spec-kit icon indicating copy to clipboard operation
spec-kit copied to clipboard

Feature/support branch prefix

Open leoxiao2012 opened this issue 6 months ago • 4 comments

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:

  • Add --prefix argument to 4 scripts (Bash × 2 + PowerShell × 2)
  • Auto-append /, producing deterministic {prefix}/{number}-{short-name} format (e.g., --prefix "feature" → feature/001-auth)
  • Fix _extract_highest_number / Get-HighestNumberFromNames to correctly extract numbers from prefixed branch names (e.g., feature/003-name), preventing duplicate numbering
  • Update branch name construction and 244-byte truncation logic to account for prefix length
  • Update speckit.git.feature.md command instructions to guide agents on prefix selection
  • Update extensions/git/README.md with --prefix usage documentation

Backward compatible: omitting --prefix produces identical behavior to before.

Testing

  • bash create-new-feature.sh --dry-run --json --prefix "feature" --short-name "auth" "test" → {"BRANCH_NAME":"feature/001-auth","FEATURE_NUM":"001","DRY_RUN":true}
  • Without prefix — backward compatible → {"BRANCH_NAME":"001-auth","FEATURE_NUM":"001","DRY_RUN":true}
  • --help output includes new option

AI Disclosure

  • [ ] I did not use AI assistance for this contribution
  • [x] I did use AI assistance (describe below)

Code generated by Claude Code (Opus 4.6), reviewed and verified manually.

leoxiao2012 avatar May 13 '26 10:05 leoxiao2012

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

mnriem avatar May 14 '26 20:05 mnriem

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

leoxiao2012 avatar May 17 '26 17:05 leoxiao2012

Please address Copilot feedback

mnriem avatar May 27 '26 15:05 mnriem

Please address test & lint errors

mnriem avatar Jun 02 '26 15:06 mnriem