[snowpatch] [PATCH 3/8] Delete remote branch after tests are done

Russell Currey ruscur at russell.cc
Fri Jul 20 21:57:23 AEST 2018


This left a bunch of unused remote branches up, which makes everything slower
because there's a bunch of git objects, so fix that.

This led to a little cleanup of the push function.

Signed-off-by: Russell Currey <ruscur at russell.cc>
---
 src/git.rs  | 13 ++++++++++---
 src/main.rs |  5 ++++-
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/git.rs b/src/git.rs
index bc93009..d025d03 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -15,7 +15,7 @@
 //
 
 use git2::build::CheckoutBuilder;
-use git2::{Commit, Cred, Error, PushOptions, Remote, Repository};
+use git2::{Branch, Commit, Cred, Error, PushOptions, Remote, Repository};
 
 use std::path::Path;
 use std::process::{Command, Output};
@@ -33,10 +33,17 @@ pub fn get_latest_commit(repo: &Repository) -> Commit {
 
 pub fn push_to_remote(
     remote: &mut Remote,
-    branch: &str,
+    branch: &Branch,
+    delete: bool,
     mut opts: &mut PushOptions,
 ) -> Result<(), Error> {
-    let refspecs: &[&str] = &[&format!("+{}/{}", GIT_REF_BASE, branch)];
+    let action = if delete { ":" } else { "+" };
+    let refspecs: &[&str] = &[&format!(
+        "{}{}/{}",
+        action,
+        GIT_REF_BASE,
+        branch.name().unwrap().unwrap()
+    )];
     remote.push(refspecs, Some(&mut opts))
 }
 
diff --git a/src/main.rs b/src/main.rs
index 5bf6187..027ceae 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -205,7 +205,7 @@ fn test_patch(
         let output = git::apply_patch(&repo, path);
 
         if output.is_ok() {
-            git::push_to_remote(&mut remote, &tag, &mut push_opts).unwrap();
+            git::push_to_remote(&mut remote, &branch, false, &mut push_opts).unwrap();
         }
 
         git::checkout_branch(&repo, &branch_name);
@@ -270,6 +270,9 @@ fn test_patch(
             .unwrap();
         results.append(&mut test.join().unwrap());
 
+        // Delete the remote branch now it's not needed any more
+        git::push_to_remote(&mut remote, &branch, true, &mut push_opts).unwrap();
+
         if !test_all_branches {
             break;
         }
-- 
2.17.1



More information about the snowpatch mailing list