[snowpatch] [PATCH] git: force reset + clean the repository before applying patches
Andrew Donnellan
andrew.donnellan at au1.ibm.com
Fri Feb 3 16:21:25 AEDT 2017
From: Russell Currey <ruscur at russell.cc>
We've been seeing some strange heisenbugs where patches refuse to apply
due to a dirty index. Do a hard reset and git clean when changing branches
which may help with this.
Signed-off-by: Russell Currey <ruscur at russell.cc>
Signed-off-by: Andrew Donnellan <andrew.donnellan at au1.ibm.com>
---
already merged, for information only
---
src/git.rs | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/src/git.rs b/src/git.rs
index e67caac..8443616 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -58,10 +58,45 @@ pub fn pull(repo: &Repository) -> Result<Output, &'static str> {
}
pub fn checkout_branch(repo: &Repository, branch: &str) -> () {
+ let workdir = repo.workdir().unwrap(); // TODO: support bare repositories
+
+ // Make sure there's no junk lying around before we switch
+ Command::new("git")
+ .arg("reset")
+ .arg("--hard")
+ .current_dir(&workdir)
+ .output()
+ .unwrap();
+
+ Command::new("git")
+ .arg("clean")
+ .arg("-f") // force remove files we don't need
+ .arg("-d") // ...including directories
+ .current_dir(&workdir)
+ .output()
+ .unwrap();
+
repo.set_head(&format!("{}/{}", GIT_REF_BASE, &branch))
.unwrap_or_else(|err| panic!("Couldn't set HEAD: {}", err));
repo.checkout_head(Some(&mut CheckoutBuilder::new().force()))
.unwrap_or_else(|err| panic!("Couldn't checkout HEAD: {}", err));
+
+ // Clean up again, just to be super sure
+ Command::new("git")
+ .arg("reset")
+ .arg("--hard")
+ .current_dir(&workdir)
+ .output()
+ .unwrap();
+
+ Command::new("git")
+ .arg("clean")
+ .arg("-f") // force remove files we don't need
+ .arg("-d") // ...including directories
+ .current_dir(&workdir)
+ .output()
+ .unwrap();
+ ()
}
pub fn apply_patch(repo: &Repository, path: &Path)
--
Andrew Donnellan OzLabs, ADL Canberra
andrew.donnellan at au1.ibm.com IBM Australia Limited
More information about the snowpatch
mailing list