#handler #callback #git2-rs #setup #repos #following

git2_auth

A small library to provide easy to use callback handler to authenticate with git2-rs

1 unstable release

0.1.0 Mar 7, 2023

#4 in #git2-rs

23 downloads per month

MIT license

12KB
156 lines

git2_auth

An authentication handler to be used with git2_rs. An example usage can be seen below. I used the following repos:

TODO

  • User defined ssh handlers
  • User provided username trials

Example Usage

// Setup remote callbacks
let mut callback = git2::RemoteCallbacks::new();
let config = git2::Config::open_default().unwrap();
// Setup authentication handler
let mut auth_handler = AuthHandler::default_with_config(config);
callback.credentials(move |url, username, allowed| {
    auth_handler.handle_callback(url, username, allowed)
});
// Create fetch options
let mut fetch_options = git2::FetchOptions::new();
fetch_options
    .remote_callbacks(callback)
    .download_tags(git2::AutotagOption::All)
    .update_fetchhead(true);
// Clone the repo
git2::build::RepoBuilder::new()
    .branch("master")
    .fetch_options(fetch_options)
    .clone("git@github.com:kayagokalp/git2_auth.git", dir.as_ref())
    .unwrap();

License

MIT

Dependencies

~12MB
~276K SLoC