#git

git2_credentials

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

10 releases (5 breaking)

0.6.1 Jun 4, 2020
0.6.0 Mar 15, 2020
0.5.0 Feb 10, 2020
0.4.0 Dec 13, 2019
0.1.1 Apr 13, 2019

#29 in Authentication

Download history 84/week @ 2020-07-02 18/week @ 2020-07-09 97/week @ 2020-07-16 110/week @ 2020-07-23 99/week @ 2020-07-30 334/week @ 2020-08-06 68/week @ 2020-08-13 147/week @ 2020-08-20 77/week @ 2020-08-27 115/week @ 2020-09-03 124/week @ 2020-09-10 56/week @ 2020-09-17 85/week @ 2020-09-24 116/week @ 2020-10-01 140/week @ 2020-10-08 220/week @ 2020-10-15

467 downloads per month
Used in less than 6 crates

Apache-2.0

16KB
180 lines

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

Dependencies

~10MB
~254K SLoC