fix: count worktree branches in git extension numbering#3054
Conversation
There was a problem hiding this comment.
⚠️ Not ready to approve
The Bash branch-name normalization is currently too broad and can incorrectly strip a leading + that is part of a legitimate branch name, causing mis-numbering in that edge case.
Pull request overview
Fixes sequential feature-branch numbering when existing branches are checked out in sibling git worktrees (which git branch -a marks with a leading +), preventing prefix reuse (e.g., generating 001-* again when 001-* already exists elsewhere).
Changes:
- Normalize
git branch -aoutput to strip the worktree+marker before extracting numeric prefixes (Bash + PowerShell). - Add regression tests that create a sibling worktree on a
007-*branch and assert the next generated branch is008-*.
File summaries
| File | Description |
|---|---|
tests/extensions/git/test_git_extension.py |
Adds worktree-based regression coverage for both Bash and PowerShell branch creation scripts. |
extensions/git/scripts/powershell/create-new-feature-branch.ps1 |
Strips + worktree markers (alongside *) when cleaning branch names for prefix scanning. |
extensions/git/scripts/bash/create-new-feature-branch.sh |
Strips + worktree markers when cleaning branch names for prefix scanning (needs a small tweak noted in review). |
Copilot's findings
- Files reviewed: 3/3 changed files
- Comments generated: 1
Note
Your feedback helps us improve the quality of this feature.
Please use 👍 or 👎 to tell us whether this assessment is correct.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
✅ Ready to approve
The change is narrowly scoped, fixes the stated root cause, and is backed by focused regression tests for both worktree and literal-plus edge cases.
Note: this review does not count toward required approvals for merging.
Copilot's findings
- Files reviewed: 3/3 changed files
- Comments generated: 0 new
Note
Your feedback helps us improve the quality of this feature.
Please use 👍 or 👎 to tell us whether this assessment is correct.
|
Thank you! |
Summary
+worktree marker when the bundled Git extension scansgit branch -afor sequential feature prefixes.+characters from valid branch names.Root Cause
git branch -aprefixes branches checked out in another worktree with+. The Git extension only removed*and spaces before extracting numeric prefixes, so sibling worktree branches were ignored and the next generated feature branch could reuse an existing prefix.A review also pointed out that the initial Bash normalization stripped any leading
+, including literal+characters that Git allows inside branch names. The Bash path now strips only thegit branchmarker column when it is followed by whitespace.Validation
uv run --extra test pytest tests/extensions/git/test_git_extension.py::TestCreateFeaturePowerShell::test_dry_run_counts_branches_checked_out_in_worktrees -q(red before fix: produced001-next; green after fix)uv run --extra test pytest tests/extensions/git/test_git_extension.py -q(23 passed, 27 skipped on Windows)uv run --extra test pytest tests/test_timestamp_branches.py -q(18 passed, 52 skipped on Windows)create-new-feature-branch.sh --json --dry-runwith sibling worktree007-worktree-featureproduced{"BRANCH_NAME":"008-next","FEATURE_NUM":"008","DRY_RUN":true}uv run --extra test pytest tests/extensions/git/test_git_extension.py::TestCreateFeatureBash::test_dry_run_counts_branches_checked_out_in_worktrees tests/extensions/git/test_git_extension.py::TestCreateFeatureBash::test_dry_run_preserves_literal_plus_branch_prefix tests/extensions/git/test_git_extension.py::TestCreateFeaturePowerShell::test_dry_run_counts_branches_checked_out_in_worktrees -q(1 passed, 2 skipped on Windows)uvx ruff check src/ tests/extensions/git/test_git_extension.pyuvx ruff check tests/extensions/git/test_git_extension.pygit diff --checkFull
uv run --extra test pytest -qwas attempted locally but timed out after 15 minutes before producing a pass/fail summary, so it is not claimed as passing here.AI Assistance
Prepared with AI assistance and manually reviewed before submission.
Closes #1066