project: make GetHead file-read fallback reftable-aware

When both `git symbolic-ref` and `git rev-parse` fail to resolve HEAD,
GetHead falls back to reading .git/HEAD directly. With the "reftable" ref
backend, .git/HEAD is only a stub pointing at the "refs/heads/.invalid"
placeholder while the real HEAD lives in the reftable stack. Reading the
stub returned that bogus placeholder value.

Detect the placeholder and treat HEAD as unresolvable (raising
NoManifestException) instead of returning the invalid ref.

Bug: 483758905
Change-Id: Ia0a825c0d1874686b98c5ddcdea6dc26c0d46784
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/612882
Tested-by: Brian Gan <brgan@google.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Brian Gan <brgan@google.com>
This commit is contained in:
Brian Gan
2026-07-30 10:01:58 -07:00
committed by gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com
parent 0b82311632
commit 29b6630a65
+6 -2
View File
@@ -4398,8 +4398,12 @@ class Project:
except AttributeError:
pass
if line.startswith("ref: "):
return line[5:-1]
return line[:-1]
ref = line[5:-1]
else:
ref = line[:-1]
if ref == R_HEADS + ".invalid":
raise NoManifestException(path, str(e))
return ref
def SetHead(self, ref, message=None):
cmdv = []