#git

git2_credentials

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

2 releases

✓ Uses Rust 2018 edition

new 0.1.1 Apr 13, 2019
0.1.0 Apr 13, 2019

#107 in Development tools

3 downloads per month

Apache-2.0

13KB
81 lines

git2_credentials

Crates.io Crates.io

Build 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/git_credentials.git", dst.as_ref()).unwrap();

Build

cargo make cf-flow

Credit

Code extracted from:

Links

Dependencies

~10MB
~224K SLoC