diff options
| author | Gavin Mak <gavinmak@google.com> | 2025-08-04 12:08:13 -0700 |
|---|---|---|
| committer | LUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2025-08-04 12:17:44 -0700 |
| commit | 8c3585f367a7d09095a22565a44fa3b47f5b690c (patch) | |
| tree | ac5a9e00d2e32d7770b359ba6dbff263e99fdc5d | |
| parent | 239fad7146e04c631825c340f23d6e69947aac50 (diff) | |
| download | git-repo-8c3585f367a7d09095a22565a44fa3b47f5b690c.tar.gz | |
project: fallback to reading HEAD when rev-parse failsv2.57.3
git rev-parse fails on invalid HEAD, e.g. after incomplete sync, causing
NoManifestException. Fall back to v2.56's direct file reading when
rev-parse fails.
Bug: 435045466
Change-Id: Ia14560335110c00d80408b2a93595a84446f8a57
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/495181
Commit-Queue: Gavin Mak <gavinmak@google.com>
Reviewed-by: Scott Lee <ddoman@google.com>
Tested-by: Gavin Mak <gavinmak@google.com>
| -rw-r--r-- | project.py | 23 |
1 files changed, 22 insertions, 1 deletions
| @@ -3841,8 +3841,29 @@ class Project: | |||
| 3841 | return self.rev_parse(HEAD) | 3841 | return self.rev_parse(HEAD) |
| 3842 | return symbolic_head | 3842 | return symbolic_head |
| 3843 | except GitError as e: | 3843 | except GitError as e: |
| 3844 | logger.warning( | ||
| 3845 | "project %s: unparseable HEAD; trying to recover.\n" | ||
| 3846 | "Check that HEAD ref in .git/HEAD is valid. The error " | ||
| 3847 | "was: %s", | ||
| 3848 | self._project.RelPath(local=False), | ||
| 3849 | e, | ||
| 3850 | ) | ||
| 3851 | |||
| 3852 | # Fallback to direct file reading for compatibility with broken | ||
| 3853 | # repos, e.g. if HEAD points to an unborn branch. | ||
| 3844 | path = self.GetDotgitPath(subpath=HEAD) | 3854 | path = self.GetDotgitPath(subpath=HEAD) |
| 3845 | raise NoManifestException(path, str(e)) | 3855 | try: |
| 3856 | with open(path) as fd: | ||
| 3857 | line = fd.readline() | ||
| 3858 | except OSError: | ||
| 3859 | raise NoManifestException(path, str(e)) | ||
| 3860 | try: | ||
| 3861 | line = line.decode() | ||
| 3862 | except AttributeError: | ||
| 3863 | pass | ||
| 3864 | if line.startswith("ref: "): | ||
| 3865 | return line[5:-1] | ||
| 3866 | return line[:-1] | ||
| 3846 | 3867 | ||
| 3847 | def SetHead(self, ref, message=None): | 3868 | def SetHead(self, ref, message=None): |
| 3848 | cmdv = [] | 3869 | cmdv = [] |
