Skip to content

Commit 723b128

Browse files
committed
test(git): pin non-branch checkout revisions the reply must not call a branch
Adds the parametrized case suggested in review: HEAD~1, refs/heads/feature and origin/main are the revisions a caller is most likely to send and none of them is a branch, so none may be reported as a branch switch. All three fail against the old unconditional return and pass with the fix.
1 parent d37bd1e commit 723b128

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

‎src/git/tests/test_server.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,24 @@ def test_git_checkout_sha_reports_detached_head(test_repository):
5353
assert "detached" in result
5454
assert "Switched to branch" not in result
5555

56+
@pytest.mark.parametrize("revision", ["HEAD~1", "refs/heads/feature", "origin/main"])
57+
def test_git_checkout_non_branch_revisions_report_detached_head(
58+
test_repository, tmp_path, revision
59+
):
60+
"""The revisions an agent is most likely to send: a relative ref, a full ref name, and a
61+
remote-tracking ref. None of them is a branch, so none may be reported as a branch switch."""
62+
test_repository.git.branch("feature")
63+
test_repository.index.commit("second commit")
64+
git.Repo.init(tmp_path / "remote.git", bare=True)
65+
test_repository.create_remote("origin", str(tmp_path / "remote.git"))
66+
test_repository.git.push("origin", "HEAD:refs/heads/main")
67+
68+
result = git_checkout(test_repository, revision)
69+
70+
assert test_repository.head.is_detached
71+
assert result.startswith("HEAD is now detached at ")
72+
73+
5674
def test_git_checkout_tag_reports_detached_head(test_repository):
5775
test_repository.create_tag("v1")
5876
result = git_checkout(test_repository, "v1")

0 commit comments

Comments
 (0)