Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSX Credentials Helper #39

Open
manuschillerdev opened this issue Mar 25, 2023 · 1 comment
Open

OSX Credentials Helper #39

manuschillerdev opened this issue Mar 25, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@manuschillerdev
Copy link

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)
}
@davidB
Copy link
Owner

davidB commented Mar 29, 2023

Good idea, but TBH

  • currently I don't have idea how to do it (and test it with CI if possible).
  • I don't know when I could work on it

Anyway PR is welcome.

@davidB davidB added the enhancement New feature or request label Mar 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants