1
0
Fork 0

project: Use git rev-parse to read HEAD

Don't directly read `.git/HEAD`, git already has a command for this.

Bug: 432200791
Change-Id: Iba030650224143eb07c44da1fa56341d9deb4288
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/492941
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:
Gavin Mak 2025-07-21 13:07:37 -07:00 committed by LUCI
parent 2e6d0881d9
commit 52bab0ba27

View file

@ -3834,19 +3834,11 @@ class Project:
def GetHead(self): def GetHead(self):
"""Return the ref that HEAD points to.""" """Return the ref that HEAD points to."""
path = self.GetDotgitPath(subpath=HEAD)
try: try:
with open(path) as fd: return self.rev_parse("--symbolic-full-name", HEAD)
line = fd.readline() except GitError as e:
except OSError as e: path = self.GetDotgitPath(subpath=HEAD)
raise NoManifestException(path, str(e)) raise NoManifestException(path, str(e))
try:
line = line.decode()
except AttributeError:
pass
if line.startswith("ref: "):
return line[5:-1]
return line[:-1]
def SetHead(self, ref, message=None): def SetHead(self, ref, message=None):
cmdv = [] cmdv = []