1
0
Fork 0

project: Return commit sha if detached HEAD

Change-Id: I80b7d5965749096b59e854f61e913aa74c857b99
This commit is contained in:
Gavin Mak 2025-07-25 18:21:50 +00:00
parent 720bd1e96b
commit de1326a611

View file

@ -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))