๐Ÿ“ฆ rust-lang / git2-rs

libgit2 bindings for Rust

โ˜… 2.0k stars โ‘‚ 435 forks ๐Ÿ‘ 2.0k watching โš–๏ธ Apache License 2.0
๐Ÿ“ฅ Clone https://github.com/rust-lang/git2-rs.git
HTTPS git clone https://github.com/rust-lang/git2-rs.git
SSH git clone git@github.com:rust-lang/git2-rs.git
CLI gh repo clone rust-lang/git2-rs
Weihang Lo Weihang Lo Merge pull request #1208 from tt/expose-git-repository-set-config-function 03ec581 1 days ago ๐Ÿ“ History
๐Ÿ“‚ master View all commits โ†’
๐Ÿ“ .github
๐Ÿ“ ci
๐Ÿ“ examples
๐Ÿ“ git2-curl
๐Ÿ“ libgit2-sys
๐Ÿ“ src
๐Ÿ“ systest
๐Ÿ“ tests
๐Ÿ“„ .gitignore
๐Ÿ“„ .gitmodules
๐Ÿ“„ Cargo.lock
๐Ÿ“„ Cargo.toml
๐Ÿ“„ CHANGELOG.md
๐Ÿ“„ CONTRIBUTING.md
๐Ÿ“„ FUNDING.json
๐Ÿ“„ LICENSE-APACHE
๐Ÿ“„ LICENSE-MIT
๐Ÿ“„ README.md
๐Ÿ“„ triagebot.toml
๐Ÿ“„ README.md

git2-rs

Documentation

libgit2 bindings for Rust.

cargo add git2

Features

By default, git2 includes support for working with local repositories, but does not include network support (e.g. cloning remote repositories). If you want to use features that require network support, you may need the "https" and/or "ssh" features. If you support user-provided repository URLs, you probably want to enable both.

cargo add git2 --features https,ssh

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.9.0 (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. On the other hand, if an appropriate version of libgit2 is present, git2 will attempt to dynamically link it.

To be more precise, the vendored libgit2 is linked statically if two conditions both hold:

  • The environment variable LIBGIT2_NO_VENDOR=1 is not set
  • and either a) The Cargo feature vendored-libgit2 is set or b) an
appropriate version of libgit2 cannot be found on the system.

In particular, note that the environment variable overrides the Cargo feature.

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 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

https://www.apache.org/licenses/LICENSE-2.0) https://opensource.org/licenses/MIT)

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.