Treat GIT_BRANCH_NAME naming the current branch as a no-op by drakeo338 · Pull Request #5006 · github/spec-kit · GitHub
Skip to content

Treat GIT_BRANCH_NAME naming the current branch as a no-op - #5006

Open
drakeo338 wants to merge 3 commits into
github:mainfrom
drakeo338:claude/5003-fix
Open

drakeo338 wants to merge 3 commits into
github:mainfrom
drakeo338:claude/5003-fix

Conversation

@drakeo338

Copy link
Copy Markdown

Fixes #5003.

Description

With GIT_BRANCH_NAME set to the branch that is already checked out, git checkout -b fails, so the feature-branch script reported "Branch already exists" and exited 1 unless --allow-existing-branch was passed. The branch is already in the requested state, so the bash, PowerShell and Python scripts now succeed without switching, as the --allow-existing-branch path does. A GIT_BRANCH_NAME naming a different existing branch still fails.

Testing

Existing and new tests in the git extension suites: 129 passed, 0 failed (the new tests fail without the fix). I did not run the other checks.

  • Tested locally with uv run specify --help
  • Ran existing tests with uv sync && uv run pytest
  • Tested with a sample project (if applicable)

AI Disclosure

  • I did not use AI assistance for this contribution
  • I did use AI assistance (fill in the disclosure below)

AI disclosure: Code and tests written by Claude Code (model: Claude Sonnet 5.5, autonomous), reviewed by two further agent passes.

Assisted-by: Claude Code (model: Claude Sonnet 5.5, autonomous)

When GIT_BRANCH_NAME names the branch that is already checked out,
`git checkout -b` fails and the script reported "Branch already exists"
and exited 1, unless --allow-existing-branch was passed. The branch is
already in the requested state, so handle it the way the
--allow-existing-branch path does and succeed without switching.

Applied to the bash, PowerShell and Python scripts. A GIT_BRANCH_NAME
naming a different existing branch still fails.

Fixes github#5003

Assisted-by: Claude Code (model: Claude Sonnet 5.5, autonomous)
Add a PowerShell twin of the bash test for GIT_BRANCH_NAME naming the
checked-out branch, use a case-sensitive comparison in the new
PowerShell clause so a differently-cased branch is not mistaken for the
current one, and document the behaviour in speckit.git.feature.md.

Assisted-by: Claude Code (model: Claude Sonnet 5.5, autonomous)
@drakeo338
drakeo338 requested a review from mnriem as a code owner October 17, 2026 14:24
@mnriem mnriem added the triage-must-have Verdict: high-value, important work for Spec Kit — do first label Oct 18, 2026
@mnriem
mnriem requested a max review from Copilot October 19, 2026 12:57

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.

🟡 Changes recommended

Required PowerShell rejection coverage and Windows PowerShell 5.1 compatibility evidence remain missing.

2 open issues
What changed in this PR

Fixes #5003 by letting the git extension accept GIT_BRANCH_NAME when it names the current branch.

Changes:

  • Align Bash, PowerShell, and Python no-op behavior.
  • Add success regressions and Bash/Python rejection coverage.
  • Document the override behavior.

AI-generated review for the requester by GitHub Copilot (model: unknown; autonomous). Tests were not run.

File Description
tests/​extensions/​git/​test_git_extension.py Adds Bash and PowerShell no-op tests.
tests/​extensions/​git/​test_git_extension_python_parity.py Tests no-op and rejection parity.
extensions/​git/​scripts/​python/​create_new_feature_branch.py Accepts the current-branch override.
extensions/​git/​scripts/​powershell/​create-new-feature-branch.ps1 Accepts the current-branch override.
extensions/​git/​scripts/​bash/​create-new-feature-branch.sh Accepts the current-branch override.
extensions/​git/​commands/​speckit.git.feature.md Documents current-branch success.

Review effort: Max

if ($AllowExistingBranch) {
# An explicit GIT_BRANCH_NAME naming the checked-out branch is
# already satisfied, so treat it like -AllowExistingBranch.
if ($AllowExistingBranch -or ($env:GIT_BRANCH_NAME -and $currentBranch -ceq $branchName)) {
Comment thread tests/extensions/git/test_git_extension.py
@mnriem

mnriem commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

Please address Copilot feedback

@mnriem mnriem added the author-awaiting Waiting on author response label Oct 19, 2026
…g branch

Mirror the Python parity negative test: without -AllowExistingBranch, a
GIT_BRANCH_NAME naming a different existing branch must exit 1, report
that the branch already exists, and leave HEAD unchanged.

Assisted-by: Claude Code (model: Claude Sonnet 5.5, autonomous)
@drakeo338

Copy link
Copy Markdown
Author

Pushed 83df0e0: the PowerShell counterpart of the different-existing-branch test (exit 1, "already exists", HEAD unchanged). With pwsh 7.6.7, tests/extensions/git passes 181/181. On Windows PowerShell 5.1: the script change is one condition built from -or, -and, -ceq and $env:, all available in 5.1; I have no 5.1 host to run it on.

@mnriem
mnriem requested a max review from Copilot October 20, 2026 13:12
@mnriem mnriem removed the author-awaiting Waiting on author response label Oct 20, 2026

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.

🟡 Changes recommended

The extension version bump and required Windows PowerShell 5.1 validation evidence are missing.

2 open issues
1 previously missed issue

In code that hasn't changed since last review

Medium severity Bump git extension version for bundled changes

extensions/​git/​scripts/​bash/​create-new-feature-branch.sh:574

This changes the bundled git extension, but extensions/git/extension.yml and its extensions/catalog.json entry still declare 1.0.1. The version guard rejects content changes without a version increase (.github/scripts/check_extension_version_bump.py:172–177). Existing installs also will not be offered the fix because updates are version-driven, as documented in extensions/EXTENSION-DEVELOPMENT-GUIDE.md:631–637.

Please bump both versions to 1.0.2 and update the pinned version assertion in tests/extensions/git/test_git_extension.py:148.

AI disclosure: GitHub Copilot (model: unknown, autonomous), acting for the requesting contributor; analysis and this comment are AI-generated.

1 resolved since last review

Review effort: Max

["git", "checkout", "-q", "-b", "feature/PROJ-42-login"],
cwd=project, check=True,
)
result = _run_pwsh(
@mnriem

mnriem commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator

This branch has not been deployed

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

Labels

triage-must-have Verdict: high-value, important work for Spec Kit — do first

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: GIT_BRANCH_NAME naming the current branch fails the mandatory before_specify hook

3 participants