Skip to content

OSX Credentials Helper #39

@manuschillerdev

Description

@manuschillerdev

There is one git host I need to conect to, which does not allow ssh connections.
I use https + username + access tokens instead.

My local git-cli is configured to use OSXKeychain:

git config credential.helper
> osxkeychain

when I use a regular git clone git asks me for the credentials on the very first connection, but stores the credentials in OSXKeychain for any subsequent commands (survives restarts as well).

When using git2_credentials + git2 I can clone repos, but it always asks for the credentials.

Would it be possible that git2_credentials uses OSXKeychain as well?

My code is very close to your official example :)

use std::path::PathBuf;

use git2::Repository;
use git2_credentials::CredentialHandler;

pub fn clone_with_auth(repo_url: &str, target_path: &PathBuf) -> Result<Repository, git2::Error> {
    let mut remote_callback = git2::RemoteCallbacks::new();
    let git_config = git2::Config::open_default()?;

    let mut credential_handler = CredentialHandler::new(git_config);
    remote_callback.credentials(move |url, username, allowed| {
        credential_handler.try_next_credential(url, username, allowed)
    });

    let mut fetch_options = git2::FetchOptions::new();
    fetch_options.remote_callbacks(remote_callback);

    git2::build::RepoBuilder::new()
        .fetch_options(fetch_options)
        .clone(&repo_url, &target_path)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions