Skip to content

Commit 8167478

Browse files
author
Christopher Herasme
committed
fix(backend): resolve tag commit from full ls-remote advertisement
1 parent cee6e3b commit 8167478

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

‎box-gui/src/box_gui/core/backend_install.py‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,16 +263,19 @@ def user_site_problems(home: Path | None = None, user_site: Path | None = None)
263263

264264

265265
def resolve_tag_commit(url: str, tag: str, *, timeout: float = _LS_REMOTE_TIMEOUT_S) -> str | None:
266-
"""Resolve one tag to its commit via ``git ls-remote <url> <tag>``.
267-
268-
Runs git without a shell and prefers the peeled ``^{}`` line for
269-
annotated tags, falling back to the plain tag line. Returns the hex
270-
commit (40 or 64 chars) or None when the tag is absent, the output is
266+
"""Resolve one tag to its commit via ``git ls-remote --tags <url>``.
267+
268+
Fetches the full tag advertisement and filters locally: passing the
269+
tag as a pattern suppresses the peeled ``^{}`` line on real forges,
270+
which would make an annotated tag resolve to its tag-object hash
271+
instead of the commit. Prefers the peeled ``^{}`` line, falling back
272+
to the plain tag line for lightweight tags. Returns the hex commit
273+
(40 or 64 chars) or None when the tag is absent, the output is
271274
malformed, or git exits non-zero. Transport errors (OSError,
272275
SubprocessError) propagate for the caller to treat as fallback.
273276
"""
274277
proc = subprocess.run(
275-
["git", "ls-remote", url, tag, f"refs/tags/{tag}"],
278+
["git", "ls-remote", "--tags", url],
276279
capture_output=True,
277280
text=True,
278281
timeout=timeout,

‎box-gui/tests/core/test_backend_install.py‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -644,12 +644,17 @@ def test_resolve_tag_commit_prefers_peeled_line(monkeypatch: Any) -> None:
644644
plain = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
645645

646646
def _fake_run(command: list[str], **kwargs: Any) -> Any:
647-
assert command[:2] == ["git", "ls-remote"]
648-
assert tag in command
647+
# No tag patterns: patterns suppress the peeled ^{} line on real
648+
# forges, so the full advertisement is filtered locally instead.
649+
assert command == ["git", "ls-remote", "--tags", "https://example.invalid/repo"]
649650
return subprocess.CompletedProcess(
650651
command,
651652
0,
652-
stdout=f"{plain}\trefs/tags/{tag}\n{peeled}\trefs/tags/{tag}^{{}}\n",
653+
stdout=(
654+
f"{plain}\trefs/tags/{tag}\n"
655+
f"{peeled}\trefs/tags/{tag}^{{}}\n"
656+
"dddddddddddddddddddddddddddddddddddddddd\trefs/tags/26.9.42\n"
657+
),
653658
stderr="",
654659
)
655660

0 commit comments

Comments
 (0)