diff options
| author | Gavin Mak <gavinmak@google.com> | 2025-07-21 13:07:37 -0700 |
|---|---|---|
| committer | LUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2025-07-21 14:50:46 -0700 |
| commit | 52bab0ba277c173259664cccc78b8ffed0c89841 (patch) | |
| tree | e14deed3c4dcb92cc70359c095fbc1f508a82333 | |
| parent | 2e6d0881d9df9a61ac7dfa533b727ae9e9b4403e (diff) | |
| download | git-repo-52bab0ba277c173259664cccc78b8ffed0c89841.tar.gz | |
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.py | 14 |
1 files changed, 3 insertions, 11 deletions
| @@ -3834,19 +3834,11 @@ class Project: | |||
| 3834 | 3834 | ||
| 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 | path = self.GetDotgitPath(subpath=HEAD) | ||
| 3838 | try: | 3837 | try: |
| 3839 | with open(path) as fd: | 3838 | return self.rev_parse("--symbolic-full-name", HEAD) |
| 3840 | line = fd.readline() | 3839 | except GitError as e: |
| 3841 | except OSError as e: | 3840 | path = self.GetDotgitPath(subpath=HEAD) |
| 3842 | raise NoManifestException(path, str(e)) | 3841 | raise NoManifestException(path, str(e)) |
| 3843 | try: | ||
| 3844 | line = line.decode() | ||
| 3845 | except AttributeError: | ||
| 3846 | pass | ||
| 3847 | if line.startswith("ref: "): | ||
| 3848 | return line[5:-1] | ||
| 3849 | return line[:-1] | ||
| 3850 | 3842 | ||
| 3851 | def SetHead(self, ref, message=None): | 3843 | def SetHead(self, ref, message=None): |
| 3852 | cmdv = [] | 3844 | cmdv = [] |
