summaryrefslogtreecommitdiffstats
path: root/project.py
diff options
context:
space:
mode:
authorGavin Mak <gavinmak@google.com>2025-07-25 18:21:50 +0000
committerLUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2025-07-25 14:30:07 -0700
commit7f7d70efe4c490a4df8597e04aca7d7e198b8e9b (patch)
treee6c9ee51a091eae145a8e39c3dd2532db30eb307 /project.py
parent720bd1e96b4e9c36d035987578fc01a9939d753f (diff)
downloadgit-repo-7f7d70efe4c490a4df8597e04aca7d7e198b8e9b.tar.gz
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>
Diffstat (limited to 'project.py')
-rw-r--r--project.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/project.py b/project.py
index 84a5cdf6..4c699d4b 100644
--- a/project.py
+++ b/project.py
@@ -3835,7 +3835,11 @@ class Project:
3835 def GetHead(self): 3835 def GetHead(self):
3836 """Return the ref that HEAD points to.""" 3836 """Return the ref that HEAD points to."""
3837 try: 3837 try:
3838 return self.rev_parse("--symbolic-full-name", HEAD) 3838 symbolic_head = self.rev_parse("--symbolic-full-name", HEAD)
3839 if symbolic_head == HEAD:
3840 # Detached HEAD. Return the commit SHA instead.
3841 return self.rev_parse(HEAD)
3842 return symbolic_head
3839 except GitError as e: 3843 except GitError as e:
3840 path = self.GetDotgitPath(subpath=HEAD) 3844 path = self.GetDotgitPath(subpath=HEAD)
3841 raise NoManifestException(path, str(e)) 3845 raise NoManifestException(path, str(e))