Skip to content

fix: validate prefix uniqueness when --number option is used#1340

Open
ggeutzzang wants to merge 1 commit intogithub:mainfrom
ggeutzzang:fix/validate-number-option-prefix
Open

fix: validate prefix uniqueness when --number option is used#1340
ggeutzzang wants to merge 1 commit intogithub:mainfrom
ggeutzzang:fix/validate-number-option-prefix

Conversation

@ggeutzzang
Copy link

Summary

When --number is explicitly provided to create-new-feature.sh, this PR adds validation to ensure the specified prefix number is not already in use by another spec directory.

Problem

Even after PR #1237 fixed the auto-detection logic, users can still create collisions by explicitly using the --number option:

# Existing spec
specs/001-feature-a/

# User runs with explicit --number
./create-new-feature.sh --number 1 --short-name "feature-b" "Description"

# Result: COLLISION!
specs/001-feature-b/  # Same prefix as 001-feature-a!

Solution

Added validation after FEATURE_NUM is calculated:

  • Checks all existing spec directories for the same prefix
  • Allows retry of the same feature (same suffix)
  • Blocks different features from using duplicate prefixes
  • Provides helpful error message guiding users to auto-detection

Test

$ ./create-new-feature.sh --number 1 --short-name "conflict" "Test"
Error: Prefix 001 is already used by '001-existing-feature'
Hint: Remove --number option to auto-detect the next available number

Related

Related to #1332 - This addresses a remaining edge case not covered by #1237

🤖 Generated with Claude Code

When --number is explicitly provided, validate that the specified
prefix number is not already in use by another spec directory.

This prevents collisions like:
- Existing: 001-feature-a
- New with --number 1: 001-feature-b (COLLISION!)

The validation allows retrying the same feature (same suffix) but
blocks creating different features with duplicate prefixes.

Error message guides users to remove --number for auto-detection.

Related to github#1332
@ggeutzzang ggeutzzang requested a review from localden as a code owner December 15, 2025 21:39
@ggeutzzang
Copy link
Author

@copilot review

nsalvacao added a commit to nsalvacao/spec-kit that referenced this pull request Feb 19, 2026
When the user passes --number N (bash) / -Number N (PS1) explicitly,
the chosen prefix (e.g. '003') might already be used by a different
feature directory in specs/. Without this check the collision is
silently accepted and two specs share the same prefix, causing
ambiguity in branch names and spec lookups.

Added a validation loop (bash) / foreach block (PS1) immediately after
FEATURE_NUM is computed:
- Iterates existing directories in specs/
- Extracts the 3-digit prefix of each
- If a match is found AND the suffix differs, aborts with an error
  message and a hint to use auto-detection instead
- If same suffix (idempotent retry), silently continues

Upstream fix: github#1340
Closes #55

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
nsalvacao added a commit to nsalvacao/spec-kit that referenced this pull request Feb 19, 2026
Adds the PS1 parity for bash commit 5745025 (cherry-picked from upstream
github/spec-kit PR github#1340 by Hyungjoo Song).

The bash change validates prefix collisions when --number is explicitly
provided. This commit adds the equivalent logic to the PowerShell script.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

2 participants