feat(scripts): add --allow-existing-branch flag to create-new-feature#1999
feat(scripts): add --allow-existing-branch flag to create-new-feature#1999mnriem merged 2 commits intogithub:mainfrom
Conversation
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
There was a problem hiding this comment.
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.mdby 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
There was a problem hiding this comment.
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.
mnriem
left a comment
There was a problem hiding this comment.
Please address Copilot feedback. If not applicable, please explain why
|
Thank you! |
Summary
--allow-existing-branch/-AllowExistingBranchflag to both bash and PowerShellcreate-new-featurescriptsspec.mdfiles are NOT overwritten (prevents data loss on re-runs)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-runflag, independent).Changes
scripts/bash/create-new-feature.sh--allow-existing-branchflag, modify branch creation to switch on existing, protect spec.md from overwritescripts/powershell/create-new-feature.ps1-AllowExistingBranchswitch, mirror bash logictests/test_timestamp_branches.pyTestAllowExistingBranchclass with 8 test casesTest plan
--allow-existing-branch, verify switch + spec dir creationBackwards compatibility
--allow-existing-branch, behavior is identical to before (error on existing branch)🤖 Generated with Claude Code