Skip to content

Commit

Permalink
Merge pull request #3 from iepathos/main
Browse files Browse the repository at this point in the history
Add git download to GitAuthenticator
  • Loading branch information
de-vri-es authored Mar 15, 2024
2 parents 6017b70 + 482bd23 commit e84dc09
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ They wrap git operations with the credentials callback set:
* [`GitAuthenticator::clone_repo()`]
* [`GitAuthenticator::fetch()`]
* [`GitAuthenticator::push()`]
* [`GitAuthenticator::download()`]

## Customizing user prompts

Expand Down Expand Up @@ -95,4 +96,5 @@ let mut repo = repo_builder.clone(url, into);
[`GitAuthenticator::clone_repo()`]: https://docs.rs/auth-git2/latest/auth_git2/struct.GitAuthenticator.html#method.clone_repo
[`GitAuthenticator::fetch()`]: https://docs.rs/auth-git2/latest/auth_git2/struct.GitAuthenticator.html#method.fetch
[`GitAuthenticator::push()`]: https://docs.rs/auth-git2/latest/auth_git2/struct.GitAuthenticator.html#method.push
[`GitAuthenticator::download()`]: https://docs.rs/auth-git2/latest/auth_git2/struct.GitAuthenticator.html#method.download
[`GitAuthenticator::set_prompter()`]: https://docs.rs/auth-git2/latest/auth_git2/struct.GitAuthenticator.html#method.set_prompter
16 changes: 16 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,22 @@ impl GitAuthenticator {
remote.fetch(refspecs, Some(&mut fetch_options), reflog_msg)
}


/// Download from a remote using the git authenticator.
///
/// If you need more control over the download options,
/// use [`Self::credentials()`] with a [`git2::Remote::download`].
pub fn download(&self, repo: &git2::Repository, remote: &mut git2::Remote, refspecs: &[&str]) -> Result<(), git2::Error> {
let git_config = repo.config()?;
let mut fetch_options = git2::FetchOptions::new();
let mut remote_callbacks = git2::RemoteCallbacks::new();

remote_callbacks.credentials(self.credentials(&git_config));
fetch_options.remote_callbacks(remote_callbacks);
remote.download(refspecs, Some(&mut fetch_options))
}


/// Push to a remote using the git authenticator.
///
/// If you need more control over the push options,
Expand Down

0 comments on commit e84dc09

Please sign in to comment.