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/git2credentials.git", dst.as_ref()).unwrap(); ```

You can run the example via

sh cargo run --example clone -- --nocapture

You can provide custom UI (to ask password, passphrase) by providing a CredentialUI. A default implementation (with dialoguer is provided.

Build

sh cargo make ci-flow

Credit

Code extracted from:

Links