1515PROJECT_ROOT = Path (__file__ ).resolve ().parent .parent
1616CREATE_FEATURE = PROJECT_ROOT / "scripts" / "bash" / "create-new-feature.sh"
1717CREATE_FEATURE_PS = PROJECT_ROOT / "scripts" / "powershell" / "create-new-feature.ps1"
18+ EXT_CREATE_FEATURE = (
19+ PROJECT_ROOT / "extensions" / "git" / "scripts" / "bash" / "create-new-feature.sh"
20+ )
21+ EXT_CREATE_FEATURE_PS = (
22+ PROJECT_ROOT / "extensions" / "git" / "scripts" / "powershell" / "create-new-feature.ps1"
23+ )
1824COMMON_SH = PROJECT_ROOT / "scripts" / "bash" / "common.sh"
1925
2026
@@ -428,6 +434,43 @@ def test_allow_existing_no_git(self, no_git_dir: Path):
428434 )
429435 assert result .returncode == 0 , result .stderr
430436
437+ def test_allow_existing_surfaces_checkout_error (self , git_repo : Path ):
438+ """Checkout failures on an existing branch should include Git's stderr."""
439+ shared_file = git_repo / "shared.txt"
440+ shared_file .write_text ("base\n " )
441+ subprocess .run (
442+ ["git" , "add" , "shared.txt" ],
443+ cwd = git_repo , check = True , capture_output = True ,
444+ )
445+ subprocess .run (
446+ ["git" , "commit" , "-m" , "add shared file" , "-q" ],
447+ cwd = git_repo , check = True , capture_output = True ,
448+ )
449+ subprocess .run (
450+ ["git" , "checkout" , "-b" , "010-checkout-failure" ],
451+ cwd = git_repo , check = True , capture_output = True ,
452+ )
453+ shared_file .write_text ("branch version\n " )
454+ subprocess .run (
455+ ["git" , "commit" , "-am" , "branch change" , "-q" ],
456+ cwd = git_repo , check = True , capture_output = True ,
457+ )
458+ subprocess .run (
459+ ["git" , "checkout" , "-" ],
460+ cwd = git_repo , check = True , capture_output = True ,
461+ )
462+ shared_file .write_text ("uncommitted main change\n " )
463+
464+ result = run_script (
465+ git_repo , "--allow-existing-branch" , "--short-name" , "checkout-failure" ,
466+ "--number" , "10" , "Checkout failure" ,
467+ )
468+
469+ assert result .returncode != 0 , "checkout should fail with conflicting local changes"
470+ assert "Failed to switch to existing branch '010-checkout-failure'" in result .stderr
471+ assert "would be overwritten by checkout" in result .stderr
472+ assert "shared.txt" in result .stderr
473+
431474
432475class TestAllowExistingBranchPowerShell :
433476 def test_powershell_supports_allow_existing_branch_flag (self ):
@@ -437,6 +480,26 @@ def test_powershell_supports_allow_existing_branch_flag(self):
437480 # Ensure the flag is referenced in script logic, not just declared
438481 assert "AllowExistingBranch" in contents .replace ("-AllowExistingBranch" , "" )
439482
483+ def test_powershell_surfaces_checkout_errors (self ):
484+ """Static guard: PS script preserves checkout stderr on existing-branch failures."""
485+ contents = CREATE_FEATURE_PS .read_text (encoding = "utf-8" )
486+ assert "$switchBranchError = git checkout -q $branchName 2>&1 | Out-String" in contents
487+ assert "exists but could not be checked out.`n$($switchBranchError.Trim())" in contents
488+
489+
490+ class TestGitExtensionParity :
491+ def test_bash_extension_surfaces_checkout_errors (self ):
492+ """Static guard: git extension bash script preserves checkout stderr."""
493+ contents = EXT_CREATE_FEATURE .read_text (encoding = "utf-8" )
494+ assert 'switch_branch_error=$(git checkout -q "$BRANCH_NAME" 2>&1)' in contents
495+ assert "Failed to switch to existing branch '$BRANCH_NAME'" in contents
496+
497+ def test_powershell_extension_surfaces_checkout_errors (self ):
498+ """Static guard: git extension PowerShell script preserves checkout stderr."""
499+ contents = EXT_CREATE_FEATURE_PS .read_text (encoding = "utf-8" )
500+ assert "$switchBranchError = git checkout -q $branchName 2>&1 | Out-String" in contents
501+ assert "exists but could not be checked out.`n$($switchBranchError.Trim())" in contents
502+
440503
441504# ── Dry-Run Tests ────────────────────────────────────────────────────────────
442505
0 commit comments