diff options
author | Mike Frysinger <vapier@google.com> | 2019-10-01 01:07:11 -0400 |
---|---|---|
committer | Mike Frysinger <vapier@google.com> | 2019-10-01 05:53:35 +0000 |
commit | c8290ad49e441424b59b88dce3af9919247ca364 (patch) | |
tree | 9ca4ceaeacdcb215588b3f4cc3b525f8a55fbfef /project.py | |
parent | 9775a3d5d2dcba0b33fbcf6a911b924be8f9a6e7 (diff) | |
download | git-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>
Diffstat (limited to 'project.py')
-rwxr-xr-x | project.py | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -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 |