From 5f51abd142a19379c2a9cf83778899d5b96279e7 Mon Sep 17 00:00:00 2001
From: Bob Lantz <rlantz@cs.stanford.edu>
Date: Tue, 14 Jan 2014 20:08:22 -0800
Subject: [PATCH] Allow -b to specify install or test branch

---
 util/vm/build.py | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/util/vm/build.py b/util/vm/build.py
index 9cd0ba24..9fb774f6 100755
--- a/util/vm/build.py
+++ b/util/vm/build.py
@@ -510,8 +510,13 @@ def walkthroughTest( vm, prompt=Prompt ):
 
 
 def checkOutBranch( vm, branch, prompt=Prompt ):
-    vm.sendline( 'cd ~/mininet; git fetch; git pull --rebase; git checkout '
-                 + branch )
+    # This is a bit subtle; it will check out an existing branch (e.g. master)
+    # if it exists; otherwise it will create a detached branch.
+    # The branch will be rebased to its parent on origin.
+    # This probably doesn't matter since we're running on a COW disk
+    # anyway.
+    vm.sendline( 'cd ~/mininet; git fetch --all; git checkout '
+                 + branch + '; git pull --rebase origin ' + branch )
     vm.expect( prompt )
     vm.sendline( 'sudo make install' )
 
@@ -531,7 +536,10 @@ def interact( vm, tests, pre='', post='', prompt=Prompt ):
                  'install-mininet-vm.sh' )
     vm.expect( prompt )
     log( '* Running VM install script' )
-    vm.sendline( 'bash install-mininet-vm.sh' )
+    installcmd = 'bash install-mininet-vm.sh'
+    if Branch:
+        cmd = cmd + ' ' + Branch
+    vm.sendline( installcmd )
     vm.expect ( 'password for mininet: ' )
     vm.sendline( 'mininet' )
     log( '* Waiting for script to complete... ' )
@@ -867,8 +875,7 @@ def parseArgs():
     parser.add_argument( '-p', '--post', metavar='cmd', default='',
                          help='specify a command line to run after tests' )
     parser.add_argument( '-b', '--branch', metavar='branch',
-                         help='For an existing VM image, check out and install'
-                         ' this branch before testing' )
+                         help='branch to install and/or check out and test' )
     parser.add_argument( 'flavor', nargs='*',
                          help='VM flavor(s) to build (e.g. raring32server)' )
     parser.add_argument( '-z', '--zip', action='store_true',
-- 
GitLab