@@ -89,6 +89,17 @@ def _write_config(project: Path, content: str) -> Path:
8989 return config_path
9090
9191
92+ def _add_sibling_worktree (project : Path , path : Path , branch : str ) -> None :
93+ """Add a sibling worktree so `git branch -a` marks it with `+`."""
94+ subprocess .run (
95+ ["git" , "worktree" , "add" , "-q" , "-b" , branch , str (path ), "HEAD" ],
96+ cwd = project ,
97+ check = True ,
98+ capture_output = True ,
99+ text = True ,
100+ )
101+
102+
92103# Git identity env vars for CI runners without global git config
93104_GIT_ENV = {
94105 "GIT_AUTHOR_NAME" : "Test User" ,
@@ -312,6 +323,40 @@ def test_increments_from_existing_specs(self, tmp_path: Path):
312323 data = json .loads (result .stdout )
313324 assert data ["FEATURE_NUM" ] == "003"
314325
326+ def test_dry_run_counts_branches_checked_out_in_worktrees (self , tmp_path : Path ):
327+ """Branches checked out in sibling worktrees still reserve their prefix."""
328+ project = _setup_project (tmp_path / "project" )
329+ _add_sibling_worktree (project , tmp_path / "sibling-worktree" , "007-worktree-feature" )
330+
331+ result = _run_bash (
332+ "create-new-feature-branch.sh" , project ,
333+ "--json" , "--dry-run" , "--short-name" , "next" , "Next feature" ,
334+ )
335+
336+ assert result .returncode == 0 , result .stderr
337+ data = json .loads (result .stdout )
338+ assert data ["BRANCH_NAME" ] == "008-next"
339+ assert data ["FEATURE_NUM" ] == "008"
340+
341+ def test_dry_run_preserves_literal_plus_branch_prefix (self , tmp_path : Path ):
342+ """A literal leading plus in a branch name is not a git worktree marker."""
343+ project = _setup_project (tmp_path )
344+ subprocess .run (
345+ ["git" , "branch" , "+007-plus-prefix" ],
346+ cwd = project ,
347+ check = True ,
348+ )
349+
350+ result = _run_bash (
351+ "create-new-feature-branch.sh" , project ,
352+ "--json" , "--dry-run" , "--short-name" , "next" , "Next feature" ,
353+ )
354+
355+ assert result .returncode == 0 , result .stderr
356+ data = json .loads (result .stdout )
357+ assert data ["BRANCH_NAME" ] == "001-next"
358+ assert data ["FEATURE_NUM" ] == "001"
359+
315360 def test_no_git_graceful_degradation (self , tmp_path : Path ):
316361 """create-new-feature-branch.sh works without git (outputs branch name, skips branch creation)."""
317362 project = _setup_project (tmp_path , git = False )
@@ -351,6 +396,21 @@ def test_creates_branch_sequential(self, tmp_path: Path):
351396 data = json .loads (result .stdout )
352397 assert data ["BRANCH_NAME" ] == "001-user-auth"
353398
399+ def test_dry_run_counts_branches_checked_out_in_worktrees (self , tmp_path : Path ):
400+ """Branches checked out in sibling worktrees still reserve their prefix."""
401+ project = _setup_project (tmp_path / "project" )
402+ _add_sibling_worktree (project , tmp_path / "sibling-worktree" , "007-worktree-feature" )
403+
404+ result = _run_pwsh (
405+ "create-new-feature-branch.ps1" , project ,
406+ "-Json" , "-DryRun" , "-ShortName" , "next" , "Next feature" ,
407+ )
408+
409+ assert result .returncode == 0 , result .stderr
410+ data = json .loads (result .stdout )
411+ assert data ["BRANCH_NAME" ] == "008-next"
412+ assert data ["FEATURE_NUM" ] == "008"
413+
354414 def test_creates_branch_timestamp (self , tmp_path : Path ):
355415 """Extension create-new-feature-branch.ps1 creates timestamp branch."""
356416 project = _setup_project (tmp_path )
0 commit comments