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 run any git operation that requires authentication using the [GitAuthenticator::run_operation()
] function.
```rust use git2_auth::GitAuthenticator; use std::path::Path;
let gitconfig = git2::Config::opendefault()?; let repo = GitAuthenticator::default() .runoperation(&gitconfig, |credentials| { let mut remotecallbacks = git2::RemoteCallbacks::new(); remotecallbacks.credentials(credentials); let mut fetchoptions = git2::FetchOptions::new(); fetchoptions.remotecallbacks(remotecallbacks); let mut repobuilder = git2::build::RepoBuilder::new(); repobuilder.fetchoptions(fetchoptions);
let url = "https://github.com/de-vri-es/git2-auth-rs";
let path = Path::new("/tmp/git2-auth-rs");
repo_builder.clone(url, path)
})?;
```