Skip to content

Commit 6bc2f92

Browse files
cliffhallclaude
andcommitted
test(git): assert git_checkout reports a detached HEAD (#4804)
Replace the KNOWN BUG #4804 pin in test_protocol.py: a non-branch revision now gets "HEAD is now detached at <short sha>", and the detached commit is the one the revision names. Document the detached reply in the README. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
1 parent 0cb2630 commit 6bc2f92

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

‎src/git/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Please note that mcp-server-git is currently in early development. The functiona
8383
- Inputs:
8484
- `repo_path` (string): Path to Git repository
8585
- `branch_name` (string): Name of branch to checkout
86-
- Returns: Confirmation of branch switch
86+
- Returns: Confirmation of branch switch, or `HEAD is now detached at <short sha>` when `branch_name` is not a branch (a sha, tag or other revision)
8787
11. `git_show`
8888
- Shows the contents of a commit
8989
- Inputs:

‎src/git/tests/test_protocol.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -661,26 +661,26 @@ async def test_git_checkout_branch(repo: git.Repo):
661661
assert repo.active_branch.name == "feature"
662662

663663

664-
# KNOWN BUG #4804: pins current (wrong) behavior; the fix changes this assertion.
665664
@pytest.mark.parametrize("revision", ["sha", "tag", "HEAD~1", "refs/heads/feature"])
666-
async def test_git_checkout_non_branch_detaches_head_but_claims_switch(
665+
async def test_git_checkout_non_branch_reports_detached_head(
667666
repo: git.Repo, revision: str
668667
):
669-
# Pins #4804: any revision rev_parse accepts is checked out, detaching
670-
# HEAD, and the reply still says "Switched to branch". Fixing #4804 changes
671-
# this test.
668+
# #4804: any revision rev_parse accepts is checked out, detaching HEAD, and
669+
# the reply says so with the short sha instead of claiming a branch switch.
672670
add_commits(repo, 1)
673671
repo.git.branch("feature")
674672
repo.create_tag("v1", ref="HEAD~1")
675673
name = {
676674
"sha": repo.head.commit.hexsha[:7],
677675
"tag": "v1",
678676
}.get(revision, revision)
677+
target = repo.commit(name).hexsha
679678
result = await call(
680679
None, "git_checkout", {"repo_path": str(root_of(repo)), "branch_name": name}
681680
)
682-
assert result == text_result(f"Switched to branch '{name}'")
683681
assert repo.head.is_detached
682+
assert repo.head.commit.hexsha == target
683+
assert result == text_result(f"HEAD is now detached at {target[:7]}")
684684

685685

686686
async def test_git_checkout_unknown_branch_is_error(repo: git.Repo):

0 commit comments

Comments
 (0)