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