#git #credentials #git2 #repository #credential-handler #remote-callbacks

git2_credentials

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

24 releases (14 breaking)

0.15.0 Jan 7, 2025
0.14.0 Nov 17, 2024
0.13.0 Sep 3, 2023
0.11.0 Mar 5, 2023
0.3.0 Jul 9, 2019

#113 in Authentication

Download history 164/week @ 2024-12-23 236/week @ 2024-12-30 391/week @ 2025-01-06 203/week @ 2025-01-13 177/week @ 2025-01-20 132/week @ 2025-01-27 597/week @ 2025-02-03 569/week @ 2025-02-10 866/week @ 2025-02-17 815/week @ 2025-02-24 979/week @ 2025-03-03 1231/week @ 2025-03-10 568/week @ 2025-03-17 1432/week @ 2025-03-24 738/week @ 2025-03-31 758/week @ 2025-04-07

3,573 downloads per month
Used in 19 crates (16 directly)

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

~13–23MB
~383K SLoC