Skip to content

Commit 02fdc5f

Browse files
committed
Merge remote-tracking branch 'origin/v2/fix/4995-git-branch-errors' into v2/chore/5004-wave6-git-rollup
2 parents 57a5fed + ffb7a76 commit 02fdc5f

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

‎src/git/src/mcp_server_git/server.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,9 @@ def git_create_branch(
279279

280280
# GitPython's create_head accepts a name that already points at the base
281281
# commit, so check first rather than report a branch that was not created.
282-
if branch_name in repo.heads:
282+
# Compare names: `in repo.heads` also matches IterableList attributes
283+
# such as "append".
284+
if any(head.name == branch_name for head in repo.heads):
283285
raise ValueError(
284286
f"Cannot create branch '{branch_name}': refs/heads/{branch_name} already exists"
285287
)

‎src/git/tests/test_protocol.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,17 @@ async def test_git_create_branch_existing_name_at_same_commit_is_error(
611611
)
612612

613613

614+
async def test_git_create_branch_name_matching_list_attribute(repo: git.Repo):
615+
# The existence check compares head names, so a new branch named like an
616+
# attribute of GitPython's IterableList ("append") is still created.
617+
assert await call(
618+
None,
619+
"git_create_branch",
620+
{"repo_path": str(root_of(repo)), "branch_name": "append"},
621+
) == text_result("Created branch 'append' from 'main'")
622+
assert repo.commit("refs/heads/append") == repo.heads["main"].commit
623+
624+
614625
async def test_git_create_branch_existing_name_at_other_commit_is_error(
615626
repo: git.Repo,
616627
):

0 commit comments

Comments
 (0)