]> xenbits.xensource.com Git - people/gdunlap/xsatool.git/commitdiff
git: Delete stackgit data when deleting or resetting branches
authorGeorge Dunlap <george.dunlap@citrix.com>
Fri, 5 May 2017 14:33:28 +0000 (15:33 +0100)
committerGeorge Dunlap <george.dunlap@citrix.com>
Fri, 16 Jun 2017 13:39:41 +0000 (14:39 +0100)
If a developer has modified a branch to be a stackgit branch as part
of development, simply deleting or resetting that branch with git
commands will "work", but will leave leftover state lying around which
may cause problems later.

Before deleting or resetting a branch, check to see if the branch is a
stackgit branch.  If so, use `stg branch --delete --force` to get rid of all
the stackgit data.

Signed-off-by: George Dunlap <george.dunlap@citrix.com>
git.go
systemtest.go

diff --git a/git.go b/git.go
index ba214a07986644cde3cfc811655a37b79b595ac1..f49c5f0d740f1da7ba0e7de43de941c2c384feb8 100644 (file)
--- a/git.go
+++ b/git.go
@@ -47,6 +47,29 @@ func (r Repo) gitCmd(args ...string) (out []byte, err error) {
        return
 }
 
+// Just for fun, stackgit doesn't have a way to set the working directory
+func (r Repo) stgCmd(args ...string) (out []byte, err error) {
+       if r.Path != "" {
+               cwd, err := os.Getwd()
+               if err != nil {
+                       return nil, err
+               }
+               defer os.Chdir(cwd)
+
+               os.Chdir(r.Path)
+       }
+       fmt.Println(args)
+       out, err = exec.Command("stg", args...).CombinedOutput()
+       fmt.Println(string(out))
+       return
+}
+
+// Will return false if stg is not installed.
+func (r Repo) IsStg(branch string) (bool) {
+       _, err := r.stgCmd("series", "-b", branch)
+       return err == nil
+}
+
 func GitClone(gpath string, origin string) (r Repo, err error) {
        if !path.IsAbs(gpath) {
                cwd, err := os.Getwd()
@@ -100,6 +123,14 @@ func (r Repo) GetPath() string {
 
 // FIXME: Option to fail if it already exists?
 func (r Repo) MakeBranch(branch string, ref string) (err error) {
+       // Can't simply reset a stackgit branch, but if we delete the
+       // old one and checkout the new one it's the same effect
+       if r.IsStg(branch) {
+               _, err = r.stgCmd("branch", "--delete", "--force", branch)
+               if err != nil {
+                       return
+               }
+       }
        _, err = r.gitCmd("checkout", "-B", branch, ref)
        if err == nil {
                _, err = r.gitCmd("clean", "-ffdx")
@@ -108,6 +139,14 @@ func (r Repo) MakeBranch(branch string, ref string) (err error) {
        return
 }
 
+// These are basically identical now; but I feel like there needs to
+// be a distinction made
+func (r Repo) ResetBranch(branch string, ref string) (err error) {
+       return r.MakeBranch(branch, ref)
+}
+
+
+
 func (r Repo) Checkout(branch string) (out []byte, err error) {
        out, err = r.gitCmd("checkout", branch)
        if err == nil {
@@ -142,13 +181,11 @@ func (r Repo) SetRef(ref string, value string) (out []byte, err error) {
 }
 
 func (r Repo) DeleteBranch(branch string) (out []byte, err error) {
-       out, err = r.gitCmd("branch", "-D", branch)
-
-       return
-}
-
-func (r Repo) ResetBranch(branch string, commit string) (out []byte, err error) {
-       out, err = r.gitCmd("checkout", "-B", branch, commit)
+       if r.IsStg(branch) {
+               out, err = r.stgCmd("branch", "--delete", "--force", branch)
+       } else {
+               out, err = r.gitCmd("branch", "-D", branch)
+       }
 
        return
 }
index ac0b686f8ef74a78adaf2d930f7f9f7f53d86c6e..906be235251e2f9dd19e86106906c006ef24677a 100644 (file)
@@ -128,7 +128,7 @@ func InitRepo(st *SystemTest) bool {
 
                        // Only update the local branch if it already exists
                        if _, tErr := r.ParseRef(branch); tErr == nil {
-                               if _, err = r.ResetBranch(branch, fullRef); err != nil {
+                               if err = r.ResetBranch(branch, fullRef); err != nil {
                                        return
                                }
                        }