Skip to content

Commit 672e513

Browse files
committed
ci: reject dangling cached repository default branches
Signed-off-by: Ralf W. Grosse-Kunstleve <[email protected]>
1 parent 64ddf60 commit 672e513

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎ci/tools/checkout_link_defaults.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ def _cached_default(root: Path, repository: str, remotes: dict[str, str]) -> str
9393
for name in names:
9494
target = _git(root, "symbolic-ref", "--quiet", f"refs/remotes/{name}/HEAD", optional=True)
9595
prefix = f"refs/remotes/{name}/"
96-
if target.startswith(prefix) and target != prefix + "HEAD":
96+
if (
97+
target.startswith(prefix)
98+
and target != prefix + "HEAD"
99+
and _git(root, "rev-parse", "--verify", "--quiet", target, optional=True)
100+
):
97101
branches.add(target.removeprefix(prefix))
98102
instructions = "; ".join(f"git remote set-head {name} --auto" for name in names)
99103
if not branches:

‎ci/tools/tests/test_checkout_link_defaults.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,26 @@ def checkout(tmp_path):
3030
root = tmp_path / "checkout space$#"
3131
root.mkdir()
3232
git(root, "init")
33+
git(
34+
root,
35+
"-c",
36+
"user.name=Link Test",
37+
"-c",
38+
39+
"-c",
40+
"commit.gpgsign=false",
41+
"commit",
42+
"--allow-empty",
43+
"-m",
44+
"Initial test revision",
45+
)
3346
return root
3447

3548

3649
def remote(root, alias, url, branch=None):
3750
git(root, "remote", "add", alias, url)
3851
if branch is not None:
52+
git(root, "update-ref", f"refs/remotes/{alias}/{branch}", "HEAD")
3953
git(root, "symbolic-ref", f"refs/remotes/{alias}/HEAD", f"refs/remotes/{alias}/{branch}")
4054

4155

@@ -135,6 +149,16 @@ def test_missing_cached_head_gives_matching_remote_refresh_instruction(tmp_path,
135149
links.repository_defaults(root)
136150

137151

152+
@pytest.mark.agent_authored(model="gpt-6.1-sol")
153+
def test_dangling_cached_head_requires_refresh_instead_of_using_removed_branch(tmp_path, monkeypatch):
154+
monkeypatch.delenv(links.METADATA_ENV, raising=False)
155+
root = checkout(tmp_path)
156+
remote(root, "upstream", "https://github.com/NVIDIA/cuda-python.git")
157+
git(root, "symbolic-ref", "refs/remotes/upstream/HEAD", "refs/remotes/upstream/removed")
158+
with pytest.raises(ValueError, match="git remote set-head upstream --auto"):
159+
links.repository_defaults(root)
160+
161+
138162
@pytest.mark.agent_authored(model="gpt-6.1-sol")
139163
def test_conflicting_cached_heads_fail_instead_of_choosing_arbitrarily(tmp_path, monkeypatch):
140164
monkeypatch.delenv(links.METADATA_ENV, raising=False)

0 commit comments

Comments
 (0)