@@ -533,6 +533,109 @@ def test_branch_ls_filters(git_repo: GitSync) -> None:
533533 assert any (b .branch_name == "master" for b in verbose_branches )
534534
535535
536+ class BranchCreateFixture (t .NamedTuple ):
537+ """Test fixture for GitBranchCmd.create() and GitBranchManager.create()."""
538+
539+ test_id : str
540+ checkout : bool
541+ expect_switch : bool
542+
543+
544+ BRANCH_CREATE_FIXTURES : list [BranchCreateFixture ] = [
545+ BranchCreateFixture (
546+ test_id = "create-without-checkout" ,
547+ checkout = False ,
548+ expect_switch = False ,
549+ ),
550+ BranchCreateFixture (
551+ test_id = "create-with-checkout" ,
552+ checkout = True ,
553+ expect_switch = True ,
554+ ),
555+ ]
556+
557+
558+ @pytest .mark .parametrize (
559+ list (BranchCreateFixture ._fields ),
560+ BRANCH_CREATE_FIXTURES ,
561+ ids = [test .test_id for test in BRANCH_CREATE_FIXTURES ],
562+ )
563+ def test_branch_cmd_create_checkout_parameter (
564+ git_repo : GitSync ,
565+ test_id : str ,
566+ checkout : bool ,
567+ expect_switch : bool ,
568+ ) -> None :
569+ """Test GitBranchCmd.create() checkout parameter behavior.
570+
571+ Verifies commit 4b8a0f7: create() uses 'git branch' instead of 'checkout -b',
572+ and only switches HEAD when checkout=True.
573+ """
574+ branch_name = f"test-create-{ test_id } "
575+
576+ # Record current branch before creating
577+ current_before = git_repo .cmd .symbolic_ref (name = "HEAD" , short = True )
578+
579+ # Create branch using GitBranchCmd
580+ branch_cmd = git .GitBranchCmd (path = git_repo .path , branch_name = branch_name )
581+ result = branch_cmd .create (checkout = checkout )
582+
583+ # Should succeed (empty string or no fatal error)
584+ assert "fatal" not in result .lower () or "already exists" in result .lower ()
585+
586+ # Verify branch was created
587+ branches = git_repo .cmd .branches .ls ()
588+ branch_names = [b .branch_name for b in branches ]
589+ assert branch_name in branch_names
590+
591+ # Check if HEAD switched
592+ current_after = git_repo .cmd .symbolic_ref (name = "HEAD" , short = True )
593+ if expect_switch :
594+ assert current_after == branch_name
595+ else :
596+ assert current_after == current_before
597+
598+
599+ @pytest .mark .parametrize (
600+ list (BranchCreateFixture ._fields ),
601+ BRANCH_CREATE_FIXTURES ,
602+ ids = [test .test_id for test in BRANCH_CREATE_FIXTURES ],
603+ )
604+ def test_branch_manager_create_checkout_parameter (
605+ git_repo : GitSync ,
606+ test_id : str ,
607+ checkout : bool ,
608+ expect_switch : bool ,
609+ ) -> None :
610+ """Test GitBranchManager.create() checkout parameter behavior.
611+
612+ Verifies commit 4b8a0f7: create() uses 'git branch' instead of 'checkout -b',
613+ and only switches HEAD when checkout=True.
614+ """
615+ branch_name = f"test-mgr-create-{ test_id } "
616+
617+ # Record current branch before creating
618+ current_before = git_repo .cmd .symbolic_ref (name = "HEAD" , short = True )
619+
620+ # Create branch using GitBranchManager
621+ result = git_repo .cmd .branches .create (branch = branch_name , checkout = checkout )
622+
623+ # Should succeed (empty string or no fatal error)
624+ assert "fatal" not in result .lower () or "already exists" in result .lower ()
625+
626+ # Verify branch was created
627+ branches = git_repo .cmd .branches .ls ()
628+ branch_names = [b .branch_name for b in branches ]
629+ assert branch_name in branch_names
630+
631+ # Check if HEAD switched
632+ current_after = git_repo .cmd .symbolic_ref (name = "HEAD" , short = True )
633+ if expect_switch :
634+ assert current_after == branch_name
635+ else :
636+ assert current_after == current_before
637+
638+
536639# =============================================================================
537640# GitRemoteCmd Tests
538641# =============================================================================
0 commit comments