Skip to content

feat(scripts): add --allow-existing-branch flag to create-new-feature#1999

Merged
mnriem merged 2 commits intogithub:mainfrom
rhuss:002-allow-existing-branch
Mar 27, 2026
Merged

feat(scripts): add --allow-existing-branch flag to create-new-feature#1999
mnriem merged 2 commits intogithub:mainfrom
rhuss:002-allow-existing-branch

Conversation

@rhuss
Copy link
Copy Markdown
Contributor

@rhuss rhuss commented Mar 27, 2026

Summary

  • Add --allow-existing-branch / -AllowExistingBranch flag to both bash and PowerShell create-new-feature scripts
  • When the target branch already exists, switch to it instead of failing
  • Spec directory and template are still created if missing
  • Existing spec.md files are NOT overwritten (prevents data loss on re-runs)
  • Flag is opt-in: without it, behavior is 100% unchanged

This enables worktree-based workflows and CI/CD pipelines that create branches externally before running speckit.specify.

Relates to #1931. Also addresses #1680, #841, and #1921.

Companion to #1998 (--dry-run flag, independent).

Changes

File Change
scripts/bash/create-new-feature.sh Add --allow-existing-branch flag, modify branch creation to switch on existing, protect spec.md from overwrite
scripts/powershell/create-new-feature.ps1 Add -AllowExistingBranch switch, mirror bash logic
tests/test_timestamp_branches.py Add TestAllowExistingBranch class with 8 test cases

Test plan

  • All 18 existing tests pass unchanged (backwards compatibility)
  • 8 new tests cover: switch to existing branch, already on branch, spec dir creation, backwards compat error without flag, no overwrite of existing spec.md, normal creation when branch doesn't exist, JSON output, non-git repo
  • Manual smoke test: pre-create branch, run with --allow-existing-branch, verify switch + spec dir creation

Backwards compatibility

  • Without --allow-existing-branch, behavior is identical to before (error on existing branch)
  • Added spec.md overwrite protection (only copies template if spec.md doesn't exist)
  • No new dependencies

🤖 Generated with Claude Code

Add an --allow-existing-branch / -AllowExistingBranch flag to both
bash and PowerShell create-new-feature scripts. When the target branch
already exists, the script switches to it instead of failing. The spec
directory and template are still created if missing, but existing
spec.md files are not overwritten (prevents data loss on re-runs).

The flag is opt-in, so existing behavior is completely unchanged
without it. This enables worktree-based workflows and CI/CD pipelines
that create branches externally before running speckit.specify.

Relates to github#1931. Also addresses github#1680, github#841, github#1921.

Assisted-By: 🤖 Claude Code
Copilot AI review requested due to automatic review settings March 27, 2026 17:41
@rhuss rhuss requested a review from mnriem as a code owner March 27, 2026 17:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds an opt-in --allow-existing-branch / -AllowExistingBranch mode to the create-new-feature scripts so workflows that pre-create branches (e.g., CI/worktrees) can reuse them without failing, while also preventing accidental overwrites of existing spec.md.

Changes:

  • Add --allow-existing-branch (bash) and -AllowExistingBranch (PowerShell) to switch to an existing target branch instead of erroring.
  • Avoid overwriting an existing spec.md by only copying/creating it when missing.
  • Add pytest coverage for the bash allow-existing-branch behavior (8 test cases).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
scripts/bash/create-new-feature.sh Adds --allow-existing-branch handling and avoids overwriting spec.md.
scripts/powershell/create-new-feature.ps1 Mirrors allow-existing-branch behavior and avoids overwriting spec.md.
tests/test_timestamp_branches.py Adds tests validating allow-existing-branch behavior (bash) and spec overwrite protection.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Make checkout failure fatal instead of suppressing with || true (bash)
- Check $LASTEXITCODE after git checkout in PowerShell
- Use Test-Path -PathType Leaf for spec file existence check (PS)
- Add PowerShell static assertion test for -AllowExistingBranch flag

Assisted-By: 🤖 Claude Code
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Collaborator

@mnriem mnriem left a comment

Choose a reason for hiding this comment

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

Please address Copilot feedback. If not applicable, please explain why

@mnriem mnriem self-requested a review March 27, 2026 19:03
@mnriem mnriem merged commit f8da535 into github:main Mar 27, 2026
11 of 12 checks passed
@mnriem
Copy link
Copy Markdown
Collaborator

mnriem commented Mar 27, 2026

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.

3 participants