From de1326a611364d89ecd555133d609f53b1122895 Mon Sep 17 00:00:00 2001 From: Gavin Mak Date: Fri, 25 Jul 2025 18:21:50 +0000 Subject: [PATCH] project: Return commit sha if detached HEAD Change-Id: I80b7d5965749096b59e854f61e913aa74c857b99 --- project.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/project.py b/project.py index 84a5cdf6e..4c699d4b8 100644 --- a/project.py +++ b/project.py @@ -3835,7 +3835,11 @@ class Project: def GetHead(self): """Return the ref that HEAD points to.""" 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: path = self.GetDotgitPath(subpath=HEAD) raise NoManifestException(path, str(e))