git2_credentials

Crates.io Crates.io

Build Status

Provide credentials function to used with git2::RemoteCallbacks.credentials

Usage

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

Build

sh cargo make cf-flow

Credit

Code extracted from:

Links