test: fix mock to actually exercise orphan branch path

This commit is contained in:
2026-05-22 20:29:30 +02:00
parent 10cbe63095
commit d0e5feeaa5
@@ -48,11 +48,17 @@ def test_init_working_repository_falls_back_to_symbolic_ref() -> None:
def test_create_branch_uses_orphan_checkout_when_head_is_unborn() -> None:
verify_head = Mock(returncode=128, stderr="fatal: Needed a single revision")
checkout_orphan = Mock(returncode=0, stderr="")
call_count = 0
with patch("src.utils.git_control._run_git_command", side_effect=[verify_head, checkout_orphan]) as run_mock:
def mock_run(repo_path: str, *args: str) -> str:
nonlocal call_count
call_count += 1
if call_count == 1:
raise RuntimeError("fatal: Needed a single revision")
return ""
with patch("src.utils.git_control._run_git_command", side_effect=mock_run) as run_mock:
create_branch("/tmp/new-repo", "feature/test")
assert run_mock.call_args_list[0].args[1:] == ("rev-parse", "--verify", "HEAD")
assert run_mock.call_args_list[0].args[1:] == ("rev-parse", "--verify", "HEAD^{commit}")
assert run_mock.call_args_list[1].args[1:] == ("checkout", "--orphan", "feature/test")