auth-git2

Easy authentication for [git2].

Authentication with [git2] can be quite difficult to implement correctly. This crate aims to make it easy.

Features

Creating an authenticator and enabling authentication mechanisms

You can create use [GitAuthenticator::new()] (or [default()][GitAuthenticator::default()]) to create a ready-to-use authenticator. Using one of these constructors will enable all supported authentication mechanisms. You can still add more private key files from non-default locations to try if desired.

You can also use [GitAuthenticator::new_empty()] to create an authenticator without any authentication mechanism enabled. Then you can selectively enable authentication mechanisms and add custom private key files. and selectively enable authentication methods or add private key files.

Using the authenticator

For the most flexibility, you can get a [git2::Credentials] callback using the [GitAuthenticator::credentials()] function. You can use it with any git operation that requires authentication. Doing this gives you full control to set other options and callbacks for the git operation.

If you don't need to set other options or callbacks, you can also use the convenience functions on [GitAuthenticator]. They wrap git operations with the credentials callback set:

Example: Clone a repository

```rust use auth_git2::GitAuthenticator; use std::path::Path;

let url = "https://github.com/de-vri-es/auth-git2-rs"; let into = Path::new("/tmp/dyfhxoaj/auth-git2-rs");

let auth = GitAuthenticator::default(); let mut repo = auth.clone_repo(url, into); ```

Example: Clone a repository with full control over fetch options

```rust use auth_git2::GitAuthenticator; use std::path::Path;

let auth = GitAuthenticator::default(); let gitconfig = git2::Config::opendefault()?; let mut repobuilder = git2::build::RepoBuilder::new(); let mut fetchoptions = git2::FetchOptions::new(); let mut remote_callbacks = git2::RemoteCallbacks::new();

remotecallbacks.credentials(auth.credentials(&gitconfig)); fetchoptions.remotecallbacks(remotecallbacks); repobuilder.fetchoptions(fetchoptions);

let url = "https://github.com/de-vri-es/auth-git2-rs"; let into = Path::new("/tmp/dyfhxoaj/auth-git2-rs"); let mut repo = repo_builder.clone(url, into); ```