mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
project: allow CurrentBranch to return None on errors
If the repo client checkout is in an incomplete sync state, the work git repo might be in a bad way. Turn errors parsing HEAD into None since callers of CurrentBranch already need to account for it. Change-Id: Ia7682e29ef4182006b1fb5f5e57800f8ab67a9f4 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/239239 Reviewed-by: David Pursehouse <dpursehouse@collab.net> Tested-by: Mike Frysinger <vapier@google.com>
This commit is contained in:
parent
9775a3d5d2
commit
c8290ad49e
@ -866,10 +866,17 @@ class Project(object):
|
||||
@property
|
||||
def CurrentBranch(self):
|
||||
"""Obtain the name of the currently checked out branch.
|
||||
|
||||
The branch name omits the 'refs/heads/' prefix.
|
||||
None is returned if the project is on a detached HEAD.
|
||||
None is returned if the project is on a detached HEAD, or if the work_git is
|
||||
otheriwse inaccessible (e.g. an incomplete sync).
|
||||
"""
|
||||
try:
|
||||
b = self.work_git.GetHead()
|
||||
except NoManifestException:
|
||||
# If the local checkout is in a bad state, don't barf. Let the callers
|
||||
# process this like the head is unreadable.
|
||||
return None
|
||||
if b.startswith(R_HEADS):
|
||||
return b[len(R_HEADS):]
|
||||
return None
|
||||
|
Loading…
Reference in New Issue
Block a user