Blame README.md

Packit ae9e2a
libgit2 - the Git linkable library
Packit ae9e2a
==================================
Packit ae9e2a
Packit ae9e2a
[![Azure Pipelines Build Status](https://dev.azure.com/libgit2/libgit2/_apis/build/status/libgit2)](https://dev.azure.com/libgit2/libgit2/_build/latest?definitionId=7)
Packit ae9e2a
[![Coverity Scan Build Status](https://scan.coverity.com/projects/639/badge.svg)](https://scan.coverity.com/projects/639)
Packit ae9e2a
Packit ae9e2a
`libgit2` is a portable, pure C implementation of the Git core methods
Packit ae9e2a
provided as a re-entrant linkable library with a solid API, allowing you to
Packit ae9e2a
write native speed custom Git applications in any language with bindings.
Packit ae9e2a
Packit ae9e2a
`libgit2` is licensed under a **very permissive license** (GPLv2 with a special
Packit ae9e2a
Linking Exception).  This basically means that you can link it (unmodified)
Packit ae9e2a
with any kind of software without having to release its source code.
Packit ae9e2a
Additionally, the example code has been released to the public domain (see the
Packit ae9e2a
[separate license](examples/COPYING) for more information).
Packit ae9e2a
Packit ae9e2a
Getting Help
Packit ae9e2a
============
Packit ae9e2a
Packit ae9e2a
**Join us on Slack**
Packit ae9e2a
Packit ae9e2a
Visit [slack.libgit2.org](http://slack.libgit2.org/) to sign up, then join
Packit ae9e2a
us in `#libgit2`.  If you prefer IRC, you can also point your client to our
Packit ae9e2a
slack channel once you've registered.
Packit ae9e2a
Packit ae9e2a
**Getting Help**
Packit ae9e2a
Packit ae9e2a
If you have questions about the library, please be sure to check out the
Packit ae9e2a
[API documentation](http://libgit2.github.com/libgit2/).  If you still have
Packit ae9e2a
questions, reach out to us on Slack or post a question on 
Packit ae9e2a
[StackOverflow](http://stackoverflow.com/questions/tagged/libgit2) (with the `libgit2` tag).
Packit ae9e2a
Packit ae9e2a
**Reporting Bugs**
Packit ae9e2a
Packit ae9e2a
Please open a [GitHub Issue](https://github.com/libgit2/libgit2/issues) and
Packit ae9e2a
include as much information as possible.  If possible, provide sample code
Packit ae9e2a
that illustrates the problem you're seeing.  If you're seeing a bug only
Packit ae9e2a
on a specific repository, please provide a link to it if possible.
Packit ae9e2a
Packit ae9e2a
We ask that you not open a GitHub Issue for help, only for bug reports.
Packit ae9e2a
Packit ae9e2a
What It Can Do
Packit ae9e2a
==============
Packit ae9e2a
Packit ae9e2a
libgit2 provides you with the ability to manage Git repositories in the
Packit ae9e2a
programming language of your choice.  It's used in production to power many
Packit ae9e2a
applications including GitHub.com, Plastic SCM and Azure DevOps.
Packit ae9e2a
Packit ae9e2a
It does not aim to replace the git tool or its user-facing commands. Some APIs
Packit ae9e2a
resemble the plumbing commands as those align closely with the concepts of the
Packit ae9e2a
Git system, but most commands a user would type are out of scope for this
Packit ae9e2a
library to implement directly.
Packit ae9e2a
Packit ae9e2a
The library provides:
Packit ae9e2a
Packit ae9e2a
* SHA conversions, formatting and shortening
Packit ae9e2a
* abstracted ODB backend system
Packit ae9e2a
* commit, tag, tree and blob parsing, editing, and write-back
Packit ae9e2a
* tree traversal
Packit ae9e2a
* revision walking
Packit ae9e2a
* index file (staging area) manipulation
Packit ae9e2a
* reference management (including packed references)
Packit ae9e2a
* config file management
Packit ae9e2a
* high level repository management
Packit ae9e2a
* thread safety and reentrancy
Packit ae9e2a
* descriptive and detailed error messages
Packit ae9e2a
* ...and more (over 175 different API calls)
Packit ae9e2a
Packit ae9e2a
As libgit2 is purely a consumer of the Git system, we have to
Packit ae9e2a
adjust to changes made upstream. This has two major consequences:
Packit ae9e2a
Packit ae9e2a
* Some changes may require us to change provided interfaces. While we try to
Packit ae9e2a
  implement functions in a generic way so that no future changes are required,
Packit ae9e2a
  we cannot promise a completely stable API.
Packit ae9e2a
* As we have to keep up with changes in behavior made upstream, we may lag
Packit ae9e2a
  behind in some areas. We usually to document these incompatibilities in our
Packit ae9e2a
  issue tracker with the label "git change".
Packit ae9e2a
Packit ae9e2a
Optional dependencies
Packit ae9e2a
=====================
Packit ae9e2a
Packit ae9e2a
While the library provides git functionality without the need for
Packit ae9e2a
dependencies, it can make use of a few libraries to add to it:
Packit ae9e2a
Packit ae9e2a
- pthreads (non-Windows) to enable threadsafe access as well as multi-threaded pack generation
Packit ae9e2a
- OpenSSL (non-Windows) to talk over HTTPS and provide the SHA-1 functions
Packit ae9e2a
- LibSSH2 to enable the SSH transport
Packit ae9e2a
- iconv (OSX) to handle the HFS+ path encoding peculiarities
Packit ae9e2a
Packit ae9e2a
Initialization
Packit ae9e2a
===============
Packit ae9e2a
Packit ae9e2a
The library needs to keep track of some global state. Call
Packit ae9e2a
Packit ae9e2a
    git_libgit2_init();
Packit ae9e2a
Packit ae9e2a
before calling any other libgit2 functions. You can call this function many times. A matching number of calls to
Packit ae9e2a
Packit ae9e2a
    git_libgit2_shutdown();
Packit ae9e2a
Packit ae9e2a
will free the resources.  Note that if you have worker threads, you should
Packit ae9e2a
call `git_libgit2_shutdown` *after* those threads have exited.  If you
Packit ae9e2a
require assistance coordinating this, simply have the worker threads call
Packit ae9e2a
`git_libgit2_init` at startup and `git_libgit2_shutdown` at shutdown.
Packit ae9e2a
Packit ae9e2a
Threading
Packit ae9e2a
=========
Packit ae9e2a
Packit ae9e2a
See [THREADING](THREADING.md) for information
Packit ae9e2a
Packit ae9e2a
Conventions
Packit ae9e2a
===========
Packit ae9e2a
Packit ae9e2a
See [CONVENTIONS](CONVENTIONS.md) for an overview of the external
Packit ae9e2a
and internal API/coding conventions we use.
Packit ae9e2a
Packit ae9e2a
Building libgit2 - Using CMake
Packit ae9e2a
==============================
Packit ae9e2a
Packit ae9e2a
`libgit2` builds cleanly on most platforms without any external dependencies.
Packit ae9e2a
Under Unix-like systems, like Linux, \*BSD and Mac OS X, libgit2 expects `pthreads` to be available;
Packit ae9e2a
they should be installed by default on all systems. Under Windows, libgit2 uses the native Windows API
Packit ae9e2a
for threading.
Packit ae9e2a
Packit ae9e2a
The `libgit2` library is built using [CMake](<https://cmake.org/>) (version 2.8 or newer) on all platforms.
Packit ae9e2a
Packit ae9e2a
On most systems you can build the library using the following commands
Packit ae9e2a
Packit ae9e2a
	$ mkdir build && cd build
Packit ae9e2a
	$ cmake ..
Packit ae9e2a
	$ cmake --build .
Packit ae9e2a
Packit ae9e2a
Alternatively you can point the CMake GUI tool to the CMakeLists.txt file and generate platform specific build project or IDE workspace.
Packit ae9e2a
Packit ae9e2a
Once built, you can run the tests from the `build` directory with the command
Packit ae9e2a
Packit ae9e2a
	$ make test
Packit ae9e2a
Packit ae9e2a
Alternatively you can run the test suite directly using,
Packit ae9e2a
Packit ae9e2a
	$ ./libgit2_clar
Packit ae9e2a
Packit ae9e2a
To install the library you can specify the install prefix by setting:
Packit ae9e2a
Packit ae9e2a
	$ cmake .. -DCMAKE_INSTALL_PREFIX=/install/prefix
Packit ae9e2a
	$ cmake --build . --target install
Packit ae9e2a
Packit ae9e2a
For more advanced use or questions about CMake please read <https://cmake.org/Wiki/CMake_FAQ>.
Packit ae9e2a
Packit ae9e2a
The following CMake variables are declared:
Packit ae9e2a
Packit ae9e2a
- `BIN_INSTALL_DIR`: Where to install binaries to.
Packit ae9e2a
- `LIB_INSTALL_DIR`: Where to install libraries to.
Packit ae9e2a
- `INCLUDE_INSTALL_DIR`: Where to install headers to.
Packit ae9e2a
- `BUILD_SHARED_LIBS`: Build libgit2 as a Shared Library (defaults to ON)
Packit ae9e2a
- `BUILD_CLAR`: Build [Clar](https://github.com/vmg/clar)-based test suite (defaults to ON)
Packit ae9e2a
- `THREADSAFE`: Build libgit2 with threading support (defaults to ON)
Packit ae9e2a
- `STDCALL`: Build libgit2 as `stdcall`. Turn off for `cdecl` (Windows; defaults to ON)
Packit ae9e2a
Packit ae9e2a
Compiler and linker options
Packit ae9e2a
---------------------------
Packit ae9e2a
Packit ae9e2a
CMake lets you specify a few variables to control the behavior of the
Packit ae9e2a
compiler and linker. These flags are rarely used but can be useful for
Packit ae9e2a
64-bit to 32-bit cross-compilation.
Packit ae9e2a
Packit ae9e2a
- `CMAKE_C_FLAGS`: Set your own compiler flags
Packit ae9e2a
- `CMAKE_FIND_ROOT_PATH`: Override the search path for libraries
Packit ae9e2a
- `ZLIB_LIBRARY`, `OPENSSL_SSL_LIBRARY` AND `OPENSSL_CRYPTO_LIBRARY`:
Packit ae9e2a
Tell CMake where to find those specific libraries
Packit ae9e2a
Packit ae9e2a
MacOS X
Packit ae9e2a
-------
Packit ae9e2a
Packit ae9e2a
If you want to build a universal binary for Mac OS X, CMake sets it
Packit ae9e2a
all up for you if you use `-DCMAKE_OSX_ARCHITECTURES="i386;x86_64"`
Packit ae9e2a
when configuring.
Packit ae9e2a
Packit ae9e2a
Windows
Packit ae9e2a
-------
Packit ae9e2a
Packit ae9e2a
You need to run the CMake commands from the Visual Studio command
Packit ae9e2a
prompt, not the regular or Windows SDK one. Select the right generator
Packit ae9e2a
for your version with the `-G "Visual Studio X" option.
Packit ae9e2a
Packit ae9e2a
See [the website](http://libgit2.github.com/docs/guides/build-and-link/)
Packit ae9e2a
for more detailed instructions.
Packit ae9e2a
Packit ae9e2a
Android
Packit ae9e2a
-------
Packit ae9e2a
Packit ae9e2a
Extract toolchain from NDK using, `make-standalone-toolchain.sh` script.
Packit ae9e2a
Optionally, crosscompile and install OpenSSL inside of it. Then create CMake
Packit ae9e2a
toolchain file that configures paths to your crosscompiler (substitute `{PATH}`
Packit ae9e2a
with full path to the toolchain):
Packit ae9e2a
Packit ae9e2a
	SET(CMAKE_SYSTEM_NAME Linux)
Packit ae9e2a
	SET(CMAKE_SYSTEM_VERSION Android)
Packit ae9e2a
Packit ae9e2a
	SET(CMAKE_C_COMPILER   {PATH}/bin/arm-linux-androideabi-gcc)
Packit ae9e2a
	SET(CMAKE_CXX_COMPILER {PATH}/bin/arm-linux-androideabi-g++)
Packit ae9e2a
	SET(CMAKE_FIND_ROOT_PATH {PATH}/sysroot/)
Packit ae9e2a
Packit ae9e2a
	SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
Packit ae9e2a
	SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
Packit ae9e2a
	SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
Packit ae9e2a
Packit ae9e2a
Add `-DCMAKE_TOOLCHAIN_FILE={pathToToolchainFile}` to cmake command
Packit ae9e2a
when configuring.
Packit ae9e2a
Packit ae9e2a
Language Bindings
Packit ae9e2a
==================================
Packit ae9e2a
Packit ae9e2a
Here are the bindings to libgit2 that are currently available:
Packit ae9e2a
Packit ae9e2a
* C++
Packit ae9e2a
    * libqgit2, Qt bindings <https://projects.kde.org/projects/playground/libs/libqgit2/repository/>
Packit ae9e2a
* Chicken Scheme
Packit ae9e2a
    * chicken-git <https://wiki.call-cc.org/egg/git>
Packit ae9e2a
* D
Packit ae9e2a
    * dlibgit <https://github.com/s-ludwig/dlibgit>
Packit ae9e2a
* Delphi
Packit ae9e2a
    * GitForDelphi <https://github.com/libgit2/GitForDelphi>
Packit ae9e2a
* Erlang
Packit ae9e2a
    * Geef <https://github.com/carlosmn/geef>
Packit ae9e2a
* Go
Packit ae9e2a
    * git2go <https://github.com/libgit2/git2go>
Packit ae9e2a
* GObject
Packit ae9e2a
    * libgit2-glib <https://wiki.gnome.org/Projects/Libgit2-glib>
Packit ae9e2a
* Haskell
Packit ae9e2a
    * hgit2 <https://github.com/jwiegley/gitlib>
Packit ae9e2a
* Java
Packit ae9e2a
    * Jagged <https://github.com/ethomson/jagged>
Packit ae9e2a
* Julia
Packit ae9e2a
    * LibGit2.jl <https://github.com/jakebolewski/LibGit2.jl>
Packit ae9e2a
* Lua
Packit ae9e2a
    * luagit2 <https://github.com/libgit2/luagit2>
Packit ae9e2a
* .NET
Packit ae9e2a
    * libgit2sharp <https://github.com/libgit2/libgit2sharp>
Packit ae9e2a
* Node.js
Packit ae9e2a
    * nodegit <https://github.com/nodegit/nodegit>
Packit ae9e2a
* Objective-C
Packit ae9e2a
    * objective-git <https://github.com/libgit2/objective-git>
Packit ae9e2a
* OCaml
Packit ae9e2a
    * ocaml-libgit2 <https://github.com/fxfactorial/ocaml-libgit2>
Packit ae9e2a
* Parrot Virtual Machine
Packit ae9e2a
    * parrot-libgit2 <https://github.com/letolabs/parrot-libgit2>
Packit ae9e2a
* Perl
Packit ae9e2a
    * Git-Raw <https://github.com/jacquesg/p5-Git-Raw>
Packit ae9e2a
* PHP
Packit ae9e2a
    * php-git <https://github.com/libgit2/php-git>
Packit ae9e2a
* PowerShell
Packit ae9e2a
    * PSGit <https://github.com/PoshCode/PSGit>
Packit ae9e2a
* Python
Packit ae9e2a
    * pygit2 <https://github.com/libgit2/pygit2>
Packit ae9e2a
* R
Packit ae9e2a
    * git2r <https://github.com/ropensci/git2r>
Packit ae9e2a
* Ruby
Packit ae9e2a
    * Rugged <https://github.com/libgit2/rugged>
Packit ae9e2a
* Rust
Packit ae9e2a
    * git2-rs <https://github.com/alexcrichton/git2-rs>
Packit ae9e2a
* Swift
Packit ae9e2a
    * SwiftGit2 <https://github.com/SwiftGit2/SwiftGit2>
Packit ae9e2a
* Vala
Packit ae9e2a
    * libgit2.vapi <https://github.com/apmasell/vapis/blob/master/libgit2.vapi>
Packit ae9e2a
Packit ae9e2a
If you start another language binding to libgit2, please let us know so
Packit ae9e2a
we can add it to the list.
Packit ae9e2a
Packit ae9e2a
How Can I Contribute?
Packit ae9e2a
==================================
Packit ae9e2a
Packit ae9e2a
We welcome new contributors!  We have a number of issues marked as
Packit ae9e2a
["up for grabs"](https://github.com/libgit2/libgit2/issues?q=is%3Aissue+is%3Aopen+label%3A%22up+for+grabs%22)
Packit ae9e2a
and
Packit ae9e2a
["easy fix"](https://github.com/libgit2/libgit2/issues?utf8=✓&q=is%3Aissue+is%3Aopen+label%3A%22easy+fix%22)
Packit ae9e2a
that are good places to jump in and get started.  There's much more detailed
Packit ae9e2a
information in our list of [outstanding projects](PROJECTS.md).
Packit ae9e2a
Packit ae9e2a
Please be sure to check the [contribution guidelines](CONTRIBUTING.md) to
Packit ae9e2a
understand our workflow, and the libgit2 [coding conventions](CONVENTIONS.md).
Packit ae9e2a
Packit ae9e2a
License
Packit ae9e2a
==================================
Packit ae9e2a
Packit ae9e2a
`libgit2` is under GPL2 **with linking exception**. This means you can link to
Packit ae9e2a
and use the library from any program, proprietary or open source; paid or
Packit ae9e2a
gratis.  However, if you modify libgit2 itself, you must distribute the
Packit ae9e2a
source to your modified version of libgit2.
Packit ae9e2a
Packit ae9e2a
See the [COPYING file](COPYING) for the full license text.