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>
This commit is contained in:
Shawn O. Pearce 2009-04-10 16:21:18 -07:00
parent 2675c3f8b5
commit 0a389e94de
3 changed files with 35 additions and 10 deletions

View File

@ -748,6 +748,20 @@ class Project(object):
def StartBranch(self, name):
"""Create a new branch off the manifest's 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
else:
branch = self.GetBranch(name)
branch.remote = self.GetRemote(self.remote.name)
branch.merge = self.revision
@ -756,8 +770,9 @@ class Project(object):
cmd = ['checkout', '-b', branch.name, rev]
if GitCommand(self, cmd).Wait() == 0:
branch.Save()
return True
else:
raise GitError('%s checkout %s ' % (self.name, rev))
return False
def CheckoutBranch(self, name):
"""Checkout a local topic branch.

View File

@ -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:

View File

@ -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)