mirror of
https://gerrit.googlesource.com/git-repo
synced 2026-01-12 01:20:26 +00:00
project: Fix GetHead to handle detached HEADs
The switch to git rev-parse caused GetHead() to return the literal string 'HEAD' when in a detached state. This broke repo prune, which expects a commit SHA. Bug: 434077990 Change-Id: I80b7d5965749096b59e854f61e913aa74c857b99 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/494401 Reviewed-by: Scott Lee <ddoman@google.com> Commit-Queue: Gavin Mak <gavinmak@google.com> Tested-by: Gavin Mak <gavinmak@google.com>
This commit is contained in:
@@ -3835,7 +3835,11 @@ class Project:
|
|||||||
def GetHead(self):
|
def GetHead(self):
|
||||||
"""Return the ref that HEAD points to."""
|
"""Return the ref that HEAD points to."""
|
||||||
try:
|
try:
|
||||||
return self.rev_parse("--symbolic-full-name", HEAD)
|
symbolic_head = self.rev_parse("--symbolic-full-name", HEAD)
|
||||||
|
if symbolic_head == HEAD:
|
||||||
|
# Detached HEAD. Return the commit SHA instead.
|
||||||
|
return self.rev_parse(HEAD)
|
||||||
|
return symbolic_head
|
||||||
except GitError as e:
|
except GitError as e:
|
||||||
path = self.GetDotgitPath(subpath=HEAD)
|
path = self.GetDotgitPath(subpath=HEAD)
|
||||||
raise NoManifestException(path, str(e))
|
raise NoManifestException(path, str(e))
|
||||||
|
|||||||
Reference in New Issue
Block a user