#git

git2_credentials

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

17 unstable releases (8 breaking)

0.9.1 Sep 11, 2022
0.8.0 Mar 12, 2022
0.7.3 Jun 11, 2021
0.7.1 Jan 1, 2021
0.3.0 Jul 9, 2019

#123 in Authentication

Download history 418/week @ 2022-06-02 94/week @ 2022-06-09 187/week @ 2022-06-16 136/week @ 2022-06-23 98/week @ 2022-06-30 120/week @ 2022-07-07 86/week @ 2022-07-14 147/week @ 2022-07-21 104/week @ 2022-07-28 161/week @ 2022-08-04 143/week @ 2022-08-11 72/week @ 2022-08-18 105/week @ 2022-08-25 117/week @ 2022-09-01 309/week @ 2022-09-08 224/week @ 2022-09-15

763 downloads per month
Used in 10 crates (9 directly)

Apache-2.0

28KB
478 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

~14MB
~350K SLoC