• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/H03-May-2022-223209

azure-pipelines/H03-May-2022-966798

cmake/H03-May-2022-1,124975

deps/H03-May-2022-67,51447,715

docs/H03-May-2022-3,5322,646

examples/H03-May-2022-6,5414,234

fuzzers/H03-May-2022-963704

include/H03-May-2022-21,9745,017

script/H03-May-2022-541433

src/H03-May-2022-120,83884,820

.HEADERH A D19-Aug-20201.1 KiB2524

.editorconfigH A D19-Aug-2020334 2217

.gitattributesH A D19-Aug-202012 21

.gitignoreH A D19-Aug-202055 87

.mailmapH A D19-Aug-20201.3 KiB2322

AUTHORSH A D19-Aug-20201.3 KiB7977

COPYINGH A D19-Aug-202051 KiB1,022831

README.mdH A D19-Aug-202015.5 KiB407313

SECURITY.mdH A D19-Aug-2020601 1510

api.docuriumH A D19-Aug-2020267 1413

azure-pipelines.ymlH A D19-Aug-20206.4 KiB191179

git.git-authorsH A D19-Aug-20203 KiB7877

package.jsonH A D19-Aug-2020281 87

README.md

1libgit2 - the Git linkable library
2==================================
3
4| Build Status | |
5| ------------ | - |
6| **master** branch CI builds | [![Azure Pipelines Build Status](https://dev.azure.com/libgit2/libgit2/_apis/build/status/libgit2?branchName=master)](https://dev.azure.com/libgit2/libgit2/_build/latest?definitionId=7&branchName=master)   |
7| **v1.0 branch** CI builds | [![Azure Pipelines Build Status](https://dev.azure.com/libgit2/libgit2/_apis/build/status/libgit2?branchName=maint/v1.0)](https://dev.azure.com/libgit2/libgit2/_build/latest?definitionId=7&branchName=maint/v1.0) |
8| **v0.28 branch** CI builds | [![Azure Pipelines Build Status](https://dev.azure.com/libgit2/libgit2/_apis/build/status/libgit2?branchName=maint/v0.28)](https://dev.azure.com/libgit2/libgit2/_build/latest?definitionId=7&branchName=maint/v0.28) |
9| **Nightly** builds | [![Azure Pipelines Build Status](https://libgit2.visualstudio.com/libgit2/_apis/build/status/nightly?branchName=master&label=Full+Build)](https://libgit2.visualstudio.com/libgit2/_build/latest?definitionId=9&branchName=master) [![Coverity Build Status](https://dev.azure.com/libgit2/libgit2/_apis/build/status/coverity?branchName=master&label=Coverity+Build)](https://dev.azure.com/libgit2/libgit2/_build/latest?definitionId=21?branchName=master) [![Coverity Scan Build Status](https://scan.coverity.com/projects/639/badge.svg)](https://scan.coverity.com/projects/639) |
10
11`libgit2` is a portable, pure C implementation of the Git core methods
12provided as a linkable library with a solid API, allowing to build Git
13functionality into your application.  Language bindings like
14[Rugged](https://github.com/libgit2/rugged) (Ruby),
15[LibGit2Sharp](https://github.com/libgit2/libgit2sharp) (.NET),
16[pygit2](http://www.pygit2.org/) (Python) and
17[NodeGit](http://nodegit.org) (Node) allow you to build Git tooling
18in your favorite language.
19
20`libgit2` is used to power Git GUI clients like
21[GitKraken](https://gitkraken.com/) and [gmaster](https://gmaster.io/)
22and on Git hosting providers like [GitHub](https://github.com/),
23[GitLab](https://gitlab.com/) and
24[Azure DevOps](https://azure.com/devops).
25We perform the merge every time you click "merge pull request".
26
27`libgit2` is licensed under a **very permissive license** (GPLv2 with a special
28Linking Exception).  This basically means that you can link it (unmodified)
29with any kind of software without having to release its source code.
30Additionally, the example code has been released to the public domain (see the
31[separate license](examples/COPYING) for more information).
32
33Table of Contents
34=================
35
36* [Quick Start](#quick-start)
37* [Getting Help](#getting-help)
38* [What It Can Do](#what-it-can-do)
39* [Optional dependencies](#optional-dependencies)
40* [Initialization](#initialization)
41* [Threading](#threading)
42* [Conventions](#conventions)
43* [Building libgit2 - Using CMake](#building-libgit2---using-cmake)
44    * [Building](#building)
45    * [Installation](#installation)
46    * [Advanced Usage](#advanced-usage)
47    * [Compiler and linker options](#compiler-and-linker-options)
48    * [MacOS X](#macos-x)
49    * [Android](#android)
50    * [MinGW](#mingw)
51* [Language Bindings](#language-bindings)
52* [How Can I Contribute?](#how-can-i-contribute)
53* [License](#license)
54
55Quick Start
56===========
57
58**Prerequisites** for building libgit2:
59
601. [CMake](https://cmake.org/), and is recommended to be installed into
61   your `PATH`.
622. [Python](https://www.python.org) is used by our test framework, and
63   should be installed into your `PATH`.
643. C compiler: libgit2 is C90 and should compile on most compilers.
65   * Windows: Visual Studio is recommended
66   * Mac: Xcode is recommended
67   * Unix: gcc or clang is recommended.
68
69**Build**
70
711. Create a build directory beneath the libgit2 source directory, and change
72   into it: `mkdir build && cd build`
732. Create the cmake build environment: `cmake ..`
743. Build libgit2: `cmake --build .`
75
76Trouble with these steps?  Read our [troubleshooting guide](docs/troubleshooting.md).
77More detailed build guidance is available below.
78
79Getting Help
80============
81
82**Chat with us**
83
84- via IRC: join [#libgit2](https://webchat.freenode.net/#libgit2) on Freenode
85- via Slack: visit [slack.libgit2.org](http://slack.libgit2.org/) to sign up,
86  then join us in `#libgit2`
87
88**Getting Help**
89
90If you have questions about the library, please be sure to check out the
91[API documentation](http://libgit2.github.com/libgit2/).  If you still have
92questions, reach out to us on Slack or post a question on
93[StackOverflow](http://stackoverflow.com/questions/tagged/libgit2) (with the `libgit2` tag).
94
95**Reporting Bugs**
96
97Please open a [GitHub Issue](https://github.com/libgit2/libgit2/issues) and
98include as much information as possible.  If possible, provide sample code
99that illustrates the problem you're seeing.  If you're seeing a bug only
100on a specific repository, please provide a link to it if possible.
101
102We ask that you not open a GitHub Issue for help, only for bug reports.
103
104**Reporting Security Issues**
105
106Please have a look at SECURITY.md.
107
108What It Can Do
109==============
110
111libgit2 provides you with the ability to manage Git repositories in the
112programming language of your choice.  It's used in production to power many
113applications including GitHub.com, Plastic SCM and Azure DevOps.
114
115It does not aim to replace the git tool or its user-facing commands. Some APIs
116resemble the plumbing commands as those align closely with the concepts of the
117Git system, but most commands a user would type are out of scope for this
118library to implement directly.
119
120The library provides:
121
122* SHA conversions, formatting and shortening
123* abstracted ODB backend system
124* commit, tag, tree and blob parsing, editing, and write-back
125* tree traversal
126* revision walking
127* index file (staging area) manipulation
128* reference management (including packed references)
129* config file management
130* high level repository management
131* thread safety and reentrancy
132* descriptive and detailed error messages
133* ...and more (over 175 different API calls)
134
135As libgit2 is purely a consumer of the Git system, we have to
136adjust to changes made upstream. This has two major consequences:
137
138* Some changes may require us to change provided interfaces. While we try to
139  implement functions in a generic way so that no future changes are required,
140  we cannot promise a completely stable API.
141* As we have to keep up with changes in behavior made upstream, we may lag
142  behind in some areas. We usually to document these incompatibilities in our
143  issue tracker with the label "git change".
144
145Optional dependencies
146=====================
147
148While the library provides git functionality without the need for
149dependencies, it can make use of a few libraries to add to it:
150
151- pthreads (non-Windows) to enable threadsafe access as well as multi-threaded pack generation
152- OpenSSL (non-Windows) to talk over HTTPS and provide the SHA-1 functions
153- LibSSH2 to enable the SSH transport
154- iconv (OSX) to handle the HFS+ path encoding peculiarities
155
156Initialization
157===============
158
159The library needs to keep track of some global state. Call
160
161    git_libgit2_init();
162
163before calling any other libgit2 functions. You can call this function many times. A matching number of calls to
164
165    git_libgit2_shutdown();
166
167will free the resources.  Note that if you have worker threads, you should
168call `git_libgit2_shutdown` *after* those threads have exited.  If you
169require assistance coordinating this, simply have the worker threads call
170`git_libgit2_init` at startup and `git_libgit2_shutdown` at shutdown.
171
172Threading
173=========
174
175See [threading](docs/threading.md) for information
176
177Conventions
178===========
179
180See [conventions](docs/conventions.md) for an overview of the external
181and internal API/coding conventions we use.
182
183Building libgit2 - Using CMake
184==============================
185
186Building
187--------
188
189`libgit2` builds cleanly on most platforms without any external dependencies.
190Under Unix-like systems, like Linux, \*BSD and Mac OS X, libgit2 expects `pthreads` to be available;
191they should be installed by default on all systems. Under Windows, libgit2 uses the native Windows API
192for threading.
193
194The `libgit2` library is built using [CMake](<https://cmake.org/>) (version 2.8 or newer) on all platforms.
195
196On most systems you can build the library using the following commands
197
198	$ mkdir build && cd build
199	$ cmake ..
200	$ cmake --build .
201
202Alternatively you can point the CMake GUI tool to the CMakeLists.txt file and generate platform specific build project or IDE workspace.
203
204Running Tests
205-------------
206
207Once built, you can run the tests from the `build` directory with the command
208
209	$ ctest -V
210
211Alternatively you can run the test suite directly using,
212
213	$ ./libgit2_clar
214
215Invoking the test suite directly is useful because it allows you to execute
216individual tests, or groups of tests using the `-s` flag.  For example, to
217run the index tests:
218
219    $ ./libgit2_clar -sindex
220
221To run a single test named `index::racy::diff`, which corresponds to the test
222function [`test_index_racy__diff`](https://github.com/libgit2/libgit2/blob/master/tests/index/racy.c#L23):
223
224    $ ./libgit2_clar -sindex::racy::diff
225
226The test suite will print a `.` for every passing test, and an `F` for any
227failing test.  An `S` indicates that a test was skipped because it is not
228applicable to your platform or is particularly expensive.
229
230**Note:** There should be _no_ failing tests when you build an unmodified
231source tree from a [release](https://github.com/libgit2/libgit2/releases),
232or from the [master branch](https://github.com/libgit2/libgit2/tree/master).
233Please contact us or [open an issue](https://github.com/libgit2/libgit2/issues)
234if you see test failures.
235
236Installation
237------------
238
239To install the library you can specify the install prefix by setting:
240
241	$ cmake .. -DCMAKE_INSTALL_PREFIX=/install/prefix
242	$ cmake --build . --target install
243
244Advanced Usage
245--------------
246
247For more advanced use or questions about CMake please read <https://cmake.org/Wiki/CMake_FAQ>.
248
249The following CMake variables are declared:
250
251- `CMAKE_INSTALL_BINDIR`: Where to install binaries to.
252- `CMAKE_INSTALL_LIBDIR`: Where to install libraries to.
253- `CMAKE_INSTALL_INCLUDEDIR`: Where to install headers to.
254- `BUILD_SHARED_LIBS`: Build libgit2 as a Shared Library (defaults to ON)
255- `BUILD_CLAR`: Build [Clar](https://github.com/vmg/clar)-based test suite (defaults to ON)
256- `THREADSAFE`: Build libgit2 with threading support (defaults to ON)
257
258To list all build options and their current value, you can do the
259following:
260
261	# Create and set up a build directory
262	$ mkdir build
263	$ cmake ..
264	# List all build options and their values
265	$ cmake -L
266
267Compiler and linker options
268---------------------------
269
270CMake lets you specify a few variables to control the behavior of the
271compiler and linker. These flags are rarely used but can be useful for
27264-bit to 32-bit cross-compilation.
273
274- `CMAKE_C_FLAGS`: Set your own compiler flags
275- `CMAKE_FIND_ROOT_PATH`: Override the search path for libraries
276- `ZLIB_LIBRARY`, `OPENSSL_SSL_LIBRARY` AND `OPENSSL_CRYPTO_LIBRARY`:
277Tell CMake where to find those specific libraries
278
279MacOS X
280-------
281
282If you want to build a universal binary for Mac OS X, CMake sets it
283all up for you if you use `-DCMAKE_OSX_ARCHITECTURES="i386;x86_64"`
284when configuring.
285
286Android
287-------
288
289Extract toolchain from NDK using, `make-standalone-toolchain.sh` script.
290Optionally, crosscompile and install OpenSSL inside of it. Then create CMake
291toolchain file that configures paths to your crosscompiler (substitute `{PATH}`
292with full path to the toolchain):
293
294	SET(CMAKE_SYSTEM_NAME Linux)
295	SET(CMAKE_SYSTEM_VERSION Android)
296
297	SET(CMAKE_C_COMPILER   {PATH}/bin/arm-linux-androideabi-gcc)
298	SET(CMAKE_CXX_COMPILER {PATH}/bin/arm-linux-androideabi-g++)
299	SET(CMAKE_FIND_ROOT_PATH {PATH}/sysroot/)
300
301	SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
302	SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
303	SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
304
305Add `-DCMAKE_TOOLCHAIN_FILE={pathToToolchainFile}` to cmake command
306when configuring.
307
308MinGW
309-----
310
311If you want to build the library in MinGW environment with SSH support enabled,
312you may need to pass `-DCMAKE_LIBRARY_PATH="${MINGW_PREFIX}/${MINGW_CHOST}/lib/"` flag
313to CMake when configuring. This is because CMake cannot find the Win32 libraries in
314MinGW folders by default and you might see an error message stating that CMake
315could not resolve `ws2_32` library during configuration.
316
317Another option would be to install `msys2-w32api-runtime` package before configuring.
318This package installs the Win32 libraries into `/usr/lib` folder which is by default
319recognized as the library path by CMake. Please note though that this package is meant
320for MSYS subsystem which is different from MinGW.
321
322Language Bindings
323==================================
324
325Here are the bindings to libgit2 that are currently available:
326
327* C++
328    * libqgit2, Qt bindings <https://projects.kde.org/projects/playground/libs/libqgit2/repository/>
329* Chicken Scheme
330    * chicken-git <https://wiki.call-cc.org/egg/git>
331* D
332    * dlibgit <https://github.com/s-ludwig/dlibgit>
333* Delphi
334    * GitForDelphi <https://github.com/libgit2/GitForDelphi>
335* Erlang
336    * Geef <https://github.com/carlosmn/geef>
337* Go
338    * git2go <https://github.com/libgit2/git2go>
339* GObject
340    * libgit2-glib <https://wiki.gnome.org/Projects/Libgit2-glib>
341* Guile
342	* Guile-Git <https://gitlab.com/guile-git/guile-git>
343* Haskell
344    * hgit2 <https://github.com/jwiegley/gitlib>
345* Java
346    * Jagged <https://github.com/ethomson/jagged>
347* Javascript / WebAssembly ( browser and nodejs )
348    * WASM-git <https://github.com/petersalomonsen/wasm-git>
349* Julia
350    * LibGit2.jl <https://github.com/JuliaLang/julia/tree/master/stdlib/LibGit2>
351* Lua
352    * luagit2 <https://github.com/libgit2/luagit2>
353* .NET
354    * libgit2sharp <https://github.com/libgit2/libgit2sharp>
355* Node.js
356    * nodegit <https://github.com/nodegit/nodegit>
357* Objective-C
358    * objective-git <https://github.com/libgit2/objective-git>
359* OCaml
360    * ocaml-libgit2 <https://github.com/fxfactorial/ocaml-libgit2>
361* Parrot Virtual Machine
362    * parrot-libgit2 <https://github.com/letolabs/parrot-libgit2>
363* Perl
364    * Git-Raw <https://github.com/jacquesg/p5-Git-Raw>
365* PHP
366    * php-git <https://github.com/libgit2/php-git>
367* PowerShell
368    * PSGit <https://github.com/PoshCode/PSGit>
369* Python
370    * pygit2 <https://github.com/libgit2/pygit2>
371* R
372    * git2r <https://github.com/ropensci/git2r>
373* Ruby
374    * Rugged <https://github.com/libgit2/rugged>
375* Rust
376    * git2-rs <https://github.com/rust-lang/git2-rs>
377* Swift
378    * SwiftGit2 <https://github.com/SwiftGit2/SwiftGit2>
379* Vala
380    * libgit2.vapi <https://github.com/apmasell/vapis/blob/master/libgit2.vapi>
381
382If you start another language binding to libgit2, please let us know so
383we can add it to the list.
384
385How Can I Contribute?
386==================================
387
388We welcome new contributors!  We have a number of issues marked as
389["up for grabs"](https://github.com/libgit2/libgit2/issues?q=is%3Aissue+is%3Aopen+label%3A%22up+for+grabs%22)
390and
391["easy fix"](https://github.com/libgit2/libgit2/issues?utf8=✓&q=is%3Aissue+is%3Aopen+label%3A%22easy+fix%22)
392that are good places to jump in and get started.  There's much more detailed
393information in our list of [outstanding projects](docs/projects.md).
394
395Please be sure to check the [contribution guidelines](docs/contributing.md) to
396understand our workflow, and the libgit2 [coding conventions](docs/conventions.md).
397
398License
399==================================
400
401`libgit2` is under GPL2 **with linking exception**. This means you can link to
402and use the library from any program, proprietary or open source; paid or
403gratis.  However, if you modify libgit2 itself, you must distribute the
404source to your modified version of libgit2.
405
406See the [COPYING file](COPYING) for the full license text.
407