Feature/support branch prefix#2541
Conversation
Support custom branch prefixes (e.g. feature/, bugfix/, hotfix/) in auto-generated git branches. The agent chooses the prefix based on context and passes --branch-prefix to the script. Number extraction now handles prefixed branch names correctly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ensures consistent {prefix}/{number}-{suffix} format even when the
user omits the trailing slash (e.g. --branch-prefix "feature" becomes
"feature/").
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Update command file and README to show prefixes without trailing slash and explain the auto-append behavior and final format. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Shorter flag name consistent with --short-name and --number style. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds support for custom branch name prefixes (e.g., feature/, bugfix/, hotfix/) to the core and git-extension create-new-feature scripts, ensuring sequential number detection works correctly even when branches are prefixed. This aligns Spec Kit’s auto-generated branch naming with workflows like GitFlow while keeping prefix-less behavior backward compatible.
Changes:
- Add
--prefix(Bash) /-Prefix(PowerShell) options and normalize prefixes to end with/. - Update sequential number extraction to handle
prefix/003-nameformats and adjust 244-char truncation logic for prefix length. - Document prefix selection/usage in the git extension README and
speckit.git.featurecommand instructions.
Show a summary per file
| File | Description |
|---|---|
| scripts/powershell/create-new-feature.ps1 | Adds -Prefix, normalizes it, and includes it in branch construction and truncation math. |
| scripts/bash/create-new-feature.sh | Adds --prefix, normalizes it, and includes it in branch construction and truncation math. |
| extensions/git/scripts/powershell/create-new-feature.ps1 | Mirrors core PowerShell script changes for the git extension. |
| extensions/git/scripts/bash/create-new-feature.sh | Mirrors core Bash script changes for the git extension. |
| extensions/git/README.md | Documents optional branch prefixes and the resulting naming format. |
| extensions/git/commands/speckit.git.feature.md | Instructs agents how to choose prefixes and how to pass them to scripts. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 6/6 changed files
- Comments generated: 3
The rename from --branch-prefix to --prefix missed the error-path usage messages in three scripts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
mnriem
left a comment
There was a problem hiding this comment.
Please address Copilot feedback
Separate BRANCH_NAME (git ref, may include prefix like feature/) from FEATURE_DIR_NAME (directory-safe, no prefix) so that specs/ paths and sequential-number detection remain correct when a branch prefix is used. Also adds prefix validation (reject embedded slashes, trim whitespace) and 31 new pytest tests covering --prefix behavior across bash, ps1, and extension scripts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Please address Copilot feedback. If not applicable, please explain why |
…length constant Add input validation for --prefix/-Prefix across all 4 scripts (Bash, PowerShell, extension variants): - Reject non-ASCII characters and special characters - Require prefix to start with a letter or digit (^[a-z0-9][-a-z0-9]*$) - Enforce max length of 16 characters via extracted MAX_PREFIX_LEN constant - Reject slash-only values (e.g. "/", "//") and embedded slashes - Add comprehensive test coverage for all edge cases Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Add input validation for --prefix/-Prefix across all 4 scripts (Bash,
|
…alidation Reject any '/' in --prefix outright instead of stripping trailing slash then validating — simpler logic, clearer error message. Also switch PowerShell -notmatch to -cnotmatch so uppercase prefixes are correctly rejected (case-insensitive -notmatch let [a-z] match uppercase). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Please address Copilot feedback |
8d06059 to
aaeafac
Compare
|
Please address test & lint errors |
aaeafac to
276d051
Compare
Update test assertions to expect "must not contain slashes" error message and reject trailing slashes, matching the current validation logic that disallows any slash in --prefix. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
276d051 to
c5ef6cc
Compare
| # Calculate how much we need to trim from suffix | ||
| # Account for prefix length: timestamp (15) + hyphen (1) = 16, or sequential (3) + hyphen (1) = 4 | ||
| PREFIX_LENGTH=$(( ${#FEATURE_NUM} + 1 )) | ||
| PREFIX_LENGTH=$(( ${#BRANCH_PREFIX} + ${#FEATURE_NUM} + 1 )) |
| # Calculate how much we need to trim from suffix | ||
| # Account for prefix length: timestamp (15) + hyphen (1) = 16, or sequential (3) + hyphen (1) = 4 | ||
| $prefixLength = $featureNum.Length + 1 | ||
| $prefixLength = $Prefix.Length + $featureNum.Length + 1 |
mnriem
left a comment
There was a problem hiding this comment.
Please address Copilot feedback
Support custom branch prefixes (e.g. feature/, bugfix/, hotfix/) in auto-generated git branches. The agent chooses the prefix based on context and passes --prefix to the script. Number extraction now handles prefixed branch names correctly.
Description
Add --prefix (Bash) / -Prefix (PowerShell) option to create-new-feature scripts, enabling custom branch name prefixes such as feature, bugfix, or hotfix.
Motivation: Auto-generated branch names have a fixed format like 001-user-auth, which doesn't fit workflows like GitFlow that require category prefixes. Since the prefix varies by context (feature/bugfix/hotfix), it is not suitable as a fixed
config — the agent decides the appropriate prefix based on the nature of the work.
Changes:
Backward compatible: omitting --prefix produces identical behavior to before.
Testing
AI Disclosure
Code generated by Claude Code (Opus 4.6), reviewed and verified manually.