#git #credentials #git2 #user-name #ui #remote-callbacks #credential-handler

git2_credentials

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

22 releases (12 breaking)

0.13.0 Sep 3, 2023
0.12.0 Aug 22, 2023
0.11.0 Mar 5, 2023
0.9.1 Sep 11, 2022
0.3.0 Jul 9, 2019

#89 in Authentication

Download history 183/week @ 2024-01-01 133/week @ 2024-01-08 127/week @ 2024-01-15 107/week @ 2024-01-22 138/week @ 2024-01-29 91/week @ 2024-02-05 580/week @ 2024-02-12 268/week @ 2024-02-19 303/week @ 2024-02-26 140/week @ 2024-03-04 177/week @ 2024-03-11 199/week @ 2024-03-18 223/week @ 2024-03-25 199/week @ 2024-04-01 79/week @ 2024-04-08 226/week @ 2024-04-15

732 downloads per month
Used in 14 crates

Apache-2.0

31KB
515 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:

Dependencies

~15–26MB
~435K SLoC