auth-git2

Easy authentication for [git2].

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

In the simplest case, you can create a [GitAuthenticator] struct and directly use it for authentication. By default, it will enable all supported authentication mechanisms. You can get a [git2::Credentials] callback for use with any git operation that requires authentication using the [GitAuthenticator::credentials()] function. Alternatively, you can use a utility function like [GitAuthenticator::clone()], [GitAuthenticator::fetch()] or [GitAuthenticator::push()].

Features

Example: Clone a repository with authentication

```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); ```