From 717f4074206a1cade9ebc51e8604061134900eb8 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 29 May 2021 18:12:28 +0200 Subject: Add function to update a Git repository Should work like: $ git remote update From what I can tell from: https://github.com/git/git/blob/a0dda6023ed82b927fa205c474654699a5b07a82/builtin/remote.c#L1452-L1490 this translates to something like: $ git fetch --prune --multiple default --all --- src/git.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/git.rs') diff --git a/src/git.rs b/src/git.rs index 423a01f..174f19f 100644 --- a/src/git.rs +++ b/src/git.rs @@ -26,3 +26,25 @@ pub fn mirror>( Ok(()) } + +pub fn update>( + path: P, +) -> Result<(), Box> { + let repo = git2::Repository::open_bare(path)?; + + for remote_opt in &repo.remotes()? { + if let Some(remote_name) = remote_opt { + let mut remote = repo.find_remote(remote_name)?; + + let mut fetch_options = git2::FetchOptions::new(); + fetch_options + .prune(git2::FetchPrune::On) + .download_tags(git2::AutotagOption::All); + + let refspecs: [&str; 0] = []; + remote.fetch(&refspecs, Some(&mut fetch_options), None)?; + } + } + + Ok(()) +} -- cgit v1.2.3