Fixed repo checkout error message when git reports errors.

In the current version of repo checkout, we often get the error:
  error: no project has branch xyzzy

...even when the actual error was something else.  This fixes it
to only report the 'no project has branch' when that is actually true.

This fix is very similar to one made for 'repo abandon':
  https://review.source.android.com/#change,22207

The repo checkout error is filed as: <http://crosbug.com/6514>

TEST=manual

A sample creating a case where 'git checkout' will fail:

  $ repo start branch1 .
  $ repo start branch2 .
  $ touch bogusfile
  $ git add bogusfile
  $ git commit -m "create bogus file"
  [branch2 f8b6b08] create bogus file
   0 files changed, 0 insertions(+), 0 deletions(-)
   create mode 100644 bogusfile
  $ echo "More" >> bogusfile
  $ repo checkout branch1 .
  error: chromite/: cannot checkout branch1

A sample case showing that we still fail if no project has a branch:

  $ repo checkout xyzzy .
  error: no project has branch xyzzy

Change-Id: I48a8e258fa7a9c1f2800dafc683787204bbfcc63
This commit is contained in:
Doug Anderson 2011-04-07 12:51:04 -07:00 committed by Shawn O. Pearce
parent 2630dd9787
commit 3ba5f95b46
2 changed files with 23 additions and 10 deletions

View File

@ -1167,6 +1167,13 @@ class Project(object):
def CheckoutBranch(self, name): def CheckoutBranch(self, name):
"""Checkout a local topic branch. """Checkout a local topic branch.
Args:
name: The name of the branch to checkout.
Returns:
True if the checkout succeeded; False if it didn't; None if the branch
didn't exist.
""" """
rev = R_HEADS + name rev = R_HEADS + name
head = self.work_git.GetHead() head = self.work_git.GetHead()
@ -1181,7 +1188,7 @@ class Project(object):
except KeyError: except KeyError:
# Branch does not exist in this project # Branch does not exist in this project
# #
return False return None
if head.startswith(R_HEADS): if head.startswith(R_HEADS):
try: try:

View File

@ -38,21 +38,27 @@ The command is equivalent to:
nb = args[0] nb = args[0]
err = [] err = []
success = []
all = self.GetProjects(args[1:]) all = self.GetProjects(args[1:])
pm = Progress('Checkout %s' % nb, len(all)) pm = Progress('Checkout %s' % nb, len(all))
for project in all: for project in all:
pm.update() pm.update()
if not project.CheckoutBranch(nb):
status = project.CheckoutBranch(nb)
if status is not None:
if status:
success.append(project)
else:
err.append(project) err.append(project)
pm.end() pm.end()
if err: if err:
if len(err) == len(all):
print >>sys.stderr, 'error: no project has branch %s' % nb
else:
for p in err: for p in err:
print >>sys.stderr,\ print >>sys.stderr,\
"error: %s/: cannot checkout %s" \ "error: %s/: cannot checkout %s" \
% (p.relpath, nb) % (p.relpath, nb)
sys.exit(1) sys.exit(1)
elif not success:
print >>sys.stderr, 'error: no project has branch %s' % nb
sys.exit(1)