mirror of
https://github.com/github/spec-kit.git
synced 2026-07-03 12:28:06 +08:00
fix: count worktree branches in git extension numbering (#3054)
* fix: count worktree branches in git extension numbering * fix: preserve literal plus branch prefixes
This commit is contained in:
@@ -89,6 +89,17 @@ def _write_config(project: Path, content: str) -> Path:
|
||||
return config_path
|
||||
|
||||
|
||||
def _add_sibling_worktree(project: Path, path: Path, branch: str) -> None:
|
||||
"""Add a sibling worktree so `git branch -a` marks it with `+`."""
|
||||
subprocess.run(
|
||||
["git", "worktree", "add", "-q", "-b", branch, str(path), "HEAD"],
|
||||
cwd=project,
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
|
||||
|
||||
# Git identity env vars for CI runners without global git config
|
||||
_GIT_ENV = {
|
||||
"GIT_AUTHOR_NAME": "Test User",
|
||||
@@ -312,6 +323,40 @@ class TestCreateFeatureBash:
|
||||
data = json.loads(result.stdout)
|
||||
assert data["FEATURE_NUM"] == "003"
|
||||
|
||||
def test_dry_run_counts_branches_checked_out_in_worktrees(self, tmp_path: Path):
|
||||
"""Branches checked out in sibling worktrees still reserve their prefix."""
|
||||
project = _setup_project(tmp_path / "project")
|
||||
_add_sibling_worktree(project, tmp_path / "sibling-worktree", "007-worktree-feature")
|
||||
|
||||
result = _run_bash(
|
||||
"create-new-feature-branch.sh", project,
|
||||
"--json", "--dry-run", "--short-name", "next", "Next feature",
|
||||
)
|
||||
|
||||
assert result.returncode == 0, result.stderr
|
||||
data = json.loads(result.stdout)
|
||||
assert data["BRANCH_NAME"] == "008-next"
|
||||
assert data["FEATURE_NUM"] == "008"
|
||||
|
||||
def test_dry_run_preserves_literal_plus_branch_prefix(self, tmp_path: Path):
|
||||
"""A literal leading plus in a branch name is not a git worktree marker."""
|
||||
project = _setup_project(tmp_path)
|
||||
subprocess.run(
|
||||
["git", "branch", "+007-plus-prefix"],
|
||||
cwd=project,
|
||||
check=True,
|
||||
)
|
||||
|
||||
result = _run_bash(
|
||||
"create-new-feature-branch.sh", project,
|
||||
"--json", "--dry-run", "--short-name", "next", "Next feature",
|
||||
)
|
||||
|
||||
assert result.returncode == 0, result.stderr
|
||||
data = json.loads(result.stdout)
|
||||
assert data["BRANCH_NAME"] == "001-next"
|
||||
assert data["FEATURE_NUM"] == "001"
|
||||
|
||||
def test_no_git_graceful_degradation(self, tmp_path: Path):
|
||||
"""create-new-feature-branch.sh works without git (outputs branch name, skips branch creation)."""
|
||||
project = _setup_project(tmp_path, git=False)
|
||||
@@ -351,6 +396,21 @@ class TestCreateFeaturePowerShell:
|
||||
data = json.loads(result.stdout)
|
||||
assert data["BRANCH_NAME"] == "001-user-auth"
|
||||
|
||||
def test_dry_run_counts_branches_checked_out_in_worktrees(self, tmp_path: Path):
|
||||
"""Branches checked out in sibling worktrees still reserve their prefix."""
|
||||
project = _setup_project(tmp_path / "project")
|
||||
_add_sibling_worktree(project, tmp_path / "sibling-worktree", "007-worktree-feature")
|
||||
|
||||
result = _run_pwsh(
|
||||
"create-new-feature-branch.ps1", project,
|
||||
"-Json", "-DryRun", "-ShortName", "next", "Next feature",
|
||||
)
|
||||
|
||||
assert result.returncode == 0, result.stderr
|
||||
data = json.loads(result.stdout)
|
||||
assert data["BRANCH_NAME"] == "008-next"
|
||||
assert data["FEATURE_NUM"] == "008"
|
||||
|
||||
def test_creates_branch_timestamp(self, tmp_path: Path):
|
||||
"""Extension create-new-feature-branch.ps1 creates timestamp branch."""
|
||||
project = _setup_project(tmp_path)
|
||||
|
||||
Reference in New Issue
Block a user