mirror of
https://gerrit.googlesource.com/git-repo
synced 2026-05-07 11:29:27 +00:00
project: resolve unborn HEAD robustly in reftable repos
Use `git symbolic-ref` to resolve HEAD before trying to parse .git/HEAD directly which is unreliable for reftable repos. Bug: 476209856 Change-Id: I60185d945c5b43c871945c0126cfdf52194e745d Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/550762 Commit-Queue: Gavin Mak <gavinmak@google.com> Reviewed-by: Mike Frysinger <vapier@google.com> Tested-by: Gavin Mak <gavinmak@google.com>
This commit is contained in:
@@ -19,6 +19,7 @@ import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
from typing import Optional
|
||||
import unittest
|
||||
|
||||
import utils_for_test
|
||||
@@ -45,6 +46,9 @@ class FakeProject:
|
||||
)
|
||||
self.config = git_config.GitConfig.ForRepository(gitdir=self.gitdir)
|
||||
|
||||
def RelPath(self, local: Optional[bool] = None) -> str:
|
||||
return self.name
|
||||
|
||||
|
||||
class ReviewableBranchTests(unittest.TestCase):
|
||||
"""Check ReviewableBranch behavior."""
|
||||
@@ -98,6 +102,29 @@ class ProjectTests(unittest.TestCase):
|
||||
"abcd00%21%21_%2b",
|
||||
)
|
||||
|
||||
@unittest.skipUnless(
|
||||
utils_for_test.supports_reftable(),
|
||||
"git reftable support is required for this test",
|
||||
)
|
||||
def test_get_head_unborn_reftable(self):
|
||||
with tempfile.TemporaryDirectory(prefix="repo-tests") as tempdir:
|
||||
subprocess.check_call(
|
||||
[
|
||||
"git",
|
||||
"-c",
|
||||
"init.defaultRefFormat=reftable",
|
||||
"init",
|
||||
"-q",
|
||||
tempdir,
|
||||
]
|
||||
)
|
||||
fakeproj = FakeProject(tempdir)
|
||||
expected = subprocess.check_output(
|
||||
["git", "-C", tempdir, "symbolic-ref", "-q", "HEAD"],
|
||||
encoding="utf-8",
|
||||
).strip()
|
||||
self.assertEqual(expected, fakeproj.work_git.GetHead())
|
||||
|
||||
|
||||
class CopyLinkTestCase(unittest.TestCase):
|
||||
"""TestCase for stub repo client checkouts.
|
||||
|
||||
Reference in New Issue
Block a user