Skip to content

fix: count worktree branches in git extension numbering#3054

Merged
mnriem merged 2 commits into
github:mainfrom
luohui1:fix/1066-git-worktree-branch-prefix
Jun 18, 2026
Merged

fix: count worktree branches in git extension numbering#3054
mnriem merged 2 commits into
github:mainfrom
luohui1:fix/1066-git-worktree-branch-prefix

Conversation

@luohui1

@luohui1 luohui1 commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Strip Git's + worktree marker when the bundled Git extension scans git branch -a for sequential feature prefixes.
  • Apply marker normalization in Bash and PowerShell branch-creation scripts without stripping literal leading + characters from valid branch names.
  • Add regression coverage for sibling worktree branches and Bash literal-plus branch prefixes.

Root Cause

git branch -a prefixes 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 the git branch marker 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: produced 001-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)
  • WSL Bash smoke for create-new-feature-branch.sh --json --dry-run with sibling worktree 007-worktree-feature produced {"BRANCH_NAME":"008-next","FEATURE_NUM":"008","DRY_RUN":true}
  • Review fix: 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.py
  • uvx ruff check tests/extensions/git/test_git_extension.py
  • git diff --check

Full uv run --extra test pytest -q was 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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ 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 -a output 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 is 008-*.
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.

Comment thread extensions/git/scripts/bash/create-new-feature-branch.sh Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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.

@mnriem mnriem merged commit 4eda983 into github:main Jun 18, 2026
11 checks passed
@mnriem

mnriem commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: automatic branch naming repeats numbering prefix such as 001-second-branch after 001-first-branch

3 participants