فهرست منبع

Make 'repo start' restartable upon failures

If `repo start foo` fails due to uncommitted and unmergeable changes
in a single project, we have switched half of the projects over to
the new target branches, but didn't on the one that failed to move.

This change improves the situation by doing three things differently:

- We keep going when we encounter an error, so other projects
  that can successfully switch still switch.

- We ignore projects whose current branch is already on the
  requested name; they are logically already setup.

- We checkout the branch if it already exists, rather than
  trying to recreate the branch.

Bug: REPO-22
Signed-off-by: Shawn O. Pearce <sop@google.com>
Shawn O. Pearce 17 سال پیش
والد
کامیت
0a389e94de
3فایلهای تغییر یافته به همراه35 افزوده شده و 10 حذف شده
  1. 23 8
      project.py
  2. 3 1
      subcmds/init.py
  3. 9 1
      subcmds/start.py

+ 23 - 8
project.py

@@ -748,16 +748,31 @@ class Project(object):
   def StartBranch(self, name):
     """Create a new branch off the manifest's revision.
     """
-    branch = self.GetBranch(name)
-    branch.remote = self.GetRemote(self.remote.name)
-    branch.merge = self.revision
+    try:
+      self.bare_git.rev_parse(R_HEADS + name)
+      exists = True
+    except GitError:
+      exists = False;
+
+    if exists:
+      if name == self.CurrentBranch:
+        return True
+      else:
+        cmd = ['checkout', name, '--']
+        return GitCommand(self, cmd).Wait() == 0
 
-    rev = branch.LocalMerge
-    cmd = ['checkout', '-b', branch.name, rev]
-    if GitCommand(self, cmd).Wait() == 0:
-      branch.Save()
     else:
-      raise GitError('%s checkout %s ' % (self.name, rev))
+      branch = self.GetBranch(name)
+      branch.remote = self.GetRemote(self.remote.name)
+      branch.merge = self.revision
+
+      rev = branch.LocalMerge
+      cmd = ['checkout', '-b', branch.name, rev]
+      if GitCommand(self, cmd).Wait() == 0:
+        branch.Save()
+        return True
+      else:
+        return False
 
   def CheckoutBranch(self, name):
     """Checkout a local topic branch.

+ 3 - 1
subcmds/init.py

@@ -131,7 +131,9 @@ default.xml will be used.
 
     m.Sync_LocalHalf()
     if is_new or m.CurrentBranch is None:
-      m.StartBranch('default')
+      if not m.StartBranch('default'):
+        print >>sys.stderr, 'fatal: cannot create default in manifest'
+        sys.exit(1)
 
   def _LinkManifest(self, name):
     if not name:

+ 9 - 1
subcmds/start.py

@@ -47,5 +47,13 @@ the configuration data is set up properly.
       print >>sys.stderr, "error: '%s' is not a valid name" % nb
       sys.exit(1)
 
+    err = []
     for project in self.GetProjects(args[1:]):
-      project.StartBranch(nb)
+      if not project.StartBranch(nb):
+        err.append(project)
+
+    if err:
+      err.sort()
+      for p in err:
+        print >>sys.stderr, "error: cannot start in %s" % p.relpath
+      sys.exit(1)