Provide credentials function to used with git2::RemoteCallbacks.credentials
```rust use git2; use git2_credentials::CredentialHandler; use tempfile;
let mut cb = git2::RemoteCallbacks::new(); let gitconfig = git2::Config::opendefault().unwrap(); let mut ch = CredentialHandler::new(gitconfig); cb.credentials(move |url, username, allowed| ch.trynext_credential(url, username, allowed));
// clone a repository let mut fo = git2::FetchOptions::new(); fo.remotecallbacks(cb) .downloadtags(git2::AutotagOption::All) .updatefetchhead(true); let dst = tempfile::tempdir().unwrap(); std::fs::createdirall(&dst.asref()).unwrap(); git2::build::RepoBuilder::new() .branch("master") .fetchoptions(fo) .clone("git@github.com:davidB/gitcredentials.git", dst.as_ref()).unwrap(); ```
sh
cargo make cf-flow
Code extracted from:
with_authentication
)
> Cargo, a package manager for Rust.