git2_credentials

Crates.iogit2_credentials
lib.rsgit2_credentials
version0.13.0
sourcesrc
created_at2019-04-13 13:32:09.623921
updated_at2023-09-03 17:21:43.933299
descriptionProvide credential function to used with git2::RemoteCallbacks.credentials
homepagehttps://github.com/davidB/git2_credentials
repositoryhttps://github.com/davidB/git2_credentials
max_upload_size
id127659
size63,314
David Bernard (davidB)

documentation

README

git2_credentials

crate license crate version

Actions Status

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

Usage

use git2;
use git2_credentials::CredentialHandler;
use tempfile;

let mut cb = git2::RemoteCallbacks::new();
let git_config = git2::Config::open_default().unwrap();
let mut ch = CredentialHandler::new(git_config);
cb.credentials(move |url, username, allowed| ch.try_next_credential(url, username, allowed));

// clone a repository
let mut fo = git2::FetchOptions::new();
fo.remote_callbacks(cb)
    .download_tags(git2::AutotagOption::All)
    .update_fetchhead(true);
let dst = tempfile::tempdir().unwrap();
std::fs::create_dir_all(&dst.as_ref()).unwrap();
git2::build::RepoBuilder::new()
    .branch("master")
    .fetch_options(fo)
    .clone("git@github.com:davidB/git2_credentials.git", dst.as_ref()).unwrap();

You can run the example via

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

cargo make ci-flow

Credit

Code extracted from:

Links

Commit count: 114

cargo fmt