aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTeddy Wing2021-05-29 18:12:28 +0200
committerTeddy Wing2021-05-29 18:13:10 +0200
commit717f4074206a1cade9ebc51e8604061134900eb8 (patch)
treedbcd9fcda8718aa57087461328b97812cb567b86 /src
parent9b6ecdd494443b8db6d037f550ca2744b3b85aad (diff)
downloadreflectub-717f4074206a1cade9ebc51e8604061134900eb8.tar.bz2
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
Diffstat (limited to 'src')
-rw-r--r--src/git.rs22
-rw-r--r--src/main.rs8
2 files changed, 28 insertions, 2 deletions
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<P: AsRef<Path>>(
Ok(())
}
+
+pub fn update<P: AsRef<Path>>(
+ path: P,
+) -> Result<(), Box<dyn std::error::Error>> {
+ 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(())
+}
diff --git a/src/main.rs b/src/main.rs
index e31da8e..70489bb 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -8,8 +8,12 @@ fn main() {
//
// dbg!(&repos);
- git::mirror(
- "https://github.com/teddywing/google-calendar-rsvp.git",
+ // git::mirror(
+ // "https://github.com/teddywing/google-calendar-rsvp.git",
+ // Path::new("/tmp/grsvp"),
+ // ).unwrap();
+
+ git::update(
Path::new("/tmp/grsvp"),
).unwrap();
}