Skip to content

Pass FetchOptions for cloning #11

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

Merged
merged 1 commit into from
Jul 31, 2021
Merged

Conversation

l4l
Copy link
Contributor

@l4l l4l commented Jul 30, 2021

So that it's possible to use for private registries with ssh-auth.

@l4l
Copy link
Contributor Author

l4l commented Jul 30, 2021

I've tested it manually but perhaps it would be nice to add the automatic test like this:

let fo = {
    let mut fo = git2::FetchOptions::new();
    fo.remote_callbacks({
        let mut callbacks = git2::RemoteCallbacks::new();
        callbacks.credentials(|_url, username_from_url, _allowed_types| {
            git2::Cred::ssh_key_from_memory(
                username_from_url.unwrap(),
                None,
                std::env::var("PRIVATE_KEY").unwrap(),
                None,
            )
        });
        callbacks
    });
    fo
};
Index::from_path_or_cloned_with_extra_options(
    "index",
    CloneOptions {
        repository_url: "[email protected]:private-index/goes-here.git".into(),
    },
    Some(fo),
).unwrap();

But it firstly needs to:

  • create a private repo with crates index;
  • setup key at CI as PRIVATE_KEY.

@l4l l4l force-pushed the private-registry-key branch from 3cc53dd to 9dcc6f6 Compare July 30, 2021 12:44
@Byron Byron merged commit 091ef7d into Byron:master Jul 31, 2021
Byron added a commit that referenced this pull request Jul 31, 2021
@Byron
Copy link
Owner

Byron commented Jul 31, 2021

Thanks a lot! I added the example above as doc-test which doesn't run, that way it's not entirely lost.
Given the simplicity of the change I also feel comfortable not having a test for this.

Some time in the future it should be possible to swap in gitoxide to do all git-related operations, which is when tests should be easier to manufacture tests like these.

@l4l l4l deleted the private-registry-key branch August 14, 2021 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants