File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 )
Original file line number Diff line number Diff 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+
614625async def test_git_create_branch_existing_name_at_other_commit_is_error (
615626 repo : git .Repo ,
616627):
You can’t perform that action at this time.
0 commit comments