summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2019-10-01 01:07:11 -0400
committerMike Frysinger <vapier@google.com>2019-10-01 05:53:35 +0000
commitc8290ad49e441424b59b88dce3af9919247ca364 (patch)
tree9ca4ceaeacdcb215588b3f4cc3b525f8a55fbfef
parent9775a3d5d2dcba0b33fbcf6a911b924be8f9a6e7 (diff)
downloadgit-repo-c8290ad49e441424b59b88dce3af9919247ca364.tar.gz
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>
-rwxr-xr-xproject.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/project.py b/project.py
index b41a57cf..51160a94 100755
--- a/project.py
+++ b/project.py
@@ -866,10 +866,17 @@ class Project(object):
866 @property 866 @property
867 def CurrentBranch(self): 867 def CurrentBranch(self):
868 """Obtain the name of the currently checked out branch. 868 """Obtain the name of the currently checked out branch.
869 The branch name omits the 'refs/heads/' prefix. 869
870 None is returned if the project is on a detached HEAD. 870 The branch name omits the 'refs/heads/' prefix.
871 None is returned if the project is on a detached HEAD, or if the work_git is
872 otheriwse inaccessible (e.g. an incomplete sync).
871 """ 873 """
872 b = self.work_git.GetHead() 874 try:
875 b = self.work_git.GetHead()
876 except NoManifestException:
877 # If the local checkout is in a bad state, don't barf. Let the callers
878 # process this like the head is unreadable.
879 return None
873 if b.startswith(R_HEADS): 880 if b.startswith(R_HEADS):
874 return b[len(R_HEADS):] 881 return b[len(R_HEADS):]
875 return None 882 return None