#git-repository #git #git-version #memory-safe #thread-safe #libgit2 #bindings

git2

Bindings to libgit2 for interoperating with git repositories. This library is both threadsafe and memory safe and allows both reading and writing git repositories.

113 releases

0.19.0 Jun 14, 2024
0.18.3 Mar 19, 2024
0.18.2 Feb 7, 2024
0.18.1 Sep 20, 2023
0.0.1 Nov 14, 2014

#1 in Development tools

Download history 290426/week @ 2024-07-08 291582/week @ 2024-07-15 305773/week @ 2024-07-22 303121/week @ 2024-07-29 289546/week @ 2024-08-05 324161/week @ 2024-08-12 336787/week @ 2024-08-19 347412/week @ 2024-08-26 320732/week @ 2024-09-02 359886/week @ 2024-09-09 323469/week @ 2024-09-16 374097/week @ 2024-09-23 376633/week @ 2024-09-30 411391/week @ 2024-10-07 396253/week @ 2024-10-14 420021/week @ 2024-10-21

1,624,381 downloads per month
Used in 1,550 crates (978 directly)

MIT/Apache

6.5MB
165K SLoC

C 142K SLoC // 0.1% comments Rust 23K SLoC // 0.0% comments Python 157 SLoC // 0.0% comments Shell 62 SLoC // 0.1% comments

git2-rs

Documentation

libgit2 bindings for Rust.

[dependencies]
git2 = "0.19.0"

Rust version requirements

git2-rs works with stable Rust, and typically works with the most recent prior stable release as well.

Version of libgit2

Currently this library requires libgit2 1.7.2 (or newer patch versions). The source for libgit2 is included in the libgit2-sys crate so there's no need to pre-install the libgit2 library, the libgit2-sys crate will figure that and/or build that for you.

You can enable the Cargo feature vendored-libgit2 to always compile and statically link to a copy of libgit2. Sometimes the libgit2 on the system is required to be found and used even when vendored-libgit2 is activated. In this case, you shall set the environment variable LIBGIT2_NO_VENDOR=1.

Building git2-rs

$ git clone https://github.com/rust-lang/git2-rs
$ cd git2-rs
$ cargo build

Automating Testing

Running tests and handling all of the associated edge cases on every commit proves tedious very quickly. To automate tests and handle proper stashing and unstashing of unstaged changes and thus avoid nasty surprises, use the pre-commit hook found here and place it into the .git/hooks/ with the name pre-commit. You may need to add execution permissions with chmod +x.

To skip tests on a simple commit or doc-fixes, use git commit --no-verify.

Building on macOS 10.10+

If the ssh feature is enabled (and it is by default) then this library depends on libssh2 which depends on OpenSSL. To get OpenSSL working follow the openssl crate's instructions.

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in git2-rs by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~2–3.5MB
~82K SLoC