summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGavin Mak <gavinmak@google.com>2025-07-21 13:07:37 -0700
committerLUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2025-07-21 14:50:46 -0700
commit52bab0ba277c173259664cccc78b8ffed0c89841 (patch)
treee14deed3c4dcb92cc70359c095fbc1f508a82333
parent2e6d0881d9df9a61ac7dfa533b727ae9e9b4403e (diff)
downloadgit-repo-52bab0ba277c173259664cccc78b8ffed0c89841.tar.gz
git-repo-52bab0ba277c173259664cccc78b8ffed0c89841.zip
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>
-rw-r--r--project.py14
1 files changed, 3 insertions, 11 deletions
diff --git a/project.py b/project.py
index 3def4d324..84a5cdf6e 100644
--- a/project.py
+++ b/project.py
@@ -3834,19 +3834,11 @@ class Project:
def GetHead(self):
"""Return the ref that HEAD points to."""
- path = self.GetDotgitPath(subpath=HEAD)
try:
- with open(path) as fd:
- line = fd.readline()
- except OSError as e:
+ return self.rev_parse("--symbolic-full-name", HEAD)
+ except GitError as e:
+ path = self.GetDotgitPath(subpath=HEAD)
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):
cmdv = []