From d0e5feeaa52e61e0045dc5115e4901e05649830f Mon Sep 17 00:00:00 2001 From: marxlaml Date: Fri, 22 May 2026 20:29:30 +0200 Subject: [PATCH] test: fix mock to actually exercise orphan branch path --- .../unit/test_git_repository_working_clones.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/apps/api/tests/unit/test_git_repository_working_clones.py b/apps/api/tests/unit/test_git_repository_working_clones.py index 1fdd2cb..577e809 100644 --- a/apps/api/tests/unit/test_git_repository_working_clones.py +++ b/apps/api/tests/unit/test_git_repository_working_clones.py @@ -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")