@@ -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))
}
@@ -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;
}
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@russell.cc> --- src/git.rs | 13 ++++++++++--- src/main.rs | 5 ++++- 2 files changed, 14 insertions(+), 4 deletions(-)