]> xenbits.xensource.com Git - people/gdunlap/xsatool.git/commitdiff
systemtest: Delete all existing branches when not making from a clean state
authorGeorge Dunlap <george.dunlap@citrix.com>
Fri, 23 Jun 2017 16:38:05 +0000 (17:38 +0100)
committerGeorge Dunlap <george.dunlap@citrix.com>
Mon, 26 Jun 2017 11:22:14 +0000 (12:22 +0100)
Except `master`, of course.

Make sure to open all repos before cleaning branches.  (xsa.git will typically not be open
after `repo init` if it wasn't cloned.)

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

index dc3147eb1b529219d4aced87d8a5d373605803c0..5d9fae1728ea0bc35d6bff11bb831a5de5d66390 100644 (file)
@@ -115,6 +115,12 @@ func InitRepo(st *SystemTest) bool {
                        G.config.Tool.rootDir)
                return false
        }
+       // Most repos are open after `repo init`, but xsa.git may not
+       // be if it wasn't cloned.
+       if err := OpenRepos(); err != nil {
+               st.Errorf("Opening repos: %v\n", err)
+               return false
+       }
 
        updateBranches := func(t Tree) (err error) {
                var r *Repo
@@ -129,6 +135,32 @@ func InitRepo(st *SystemTest) bool {
                        r = &xr.Repo
                }
 
+               // Make 'master' the current (mainly so we can delete
+               // any other branches if they exist)
+               if _, err = r.Checkout("master"); err != nil {
+                       return fmt.Errorf("Checking out branch master for tree %s: %v",
+                               t, err)
+               }
+
+               // Delete all local branches except master
+               branches, err := r.Branches("")
+               if err != nil {
+                       st.Errorf("Couldn't get branches for tree %s: %v\n",
+                               t, err)
+                       return
+               }
+               for _, branch := range branches {
+                       if branch == "master" {
+                               continue
+                       }
+                       fmt.Printf("Deleting leftover branch %s\n", branch)
+                       if _, err = r.DeleteBranch(branch); err != nil {
+                               st.Errorf("Deleting branch %s: %v\n", branch, err)
+                               return
+                       }
+               }
+
+               // Reset "remote" branches to specified state for simulation
                for branch := range *its[t] {
                        shortRef := (*its[t])[branch]
                        var fullRef string