From 8004eb3b02bb89ee4f4372b60c10f9d976e7e082 Mon Sep 17 00:00:00 2001 From: Hyungjoo Song Date: Tue, 16 Dec 2025 06:38:39 +0900 Subject: [PATCH] fix: validate prefix uniqueness when --number option is used 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 #1332 --- scripts/bash/create-new-feature.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/scripts/bash/create-new-feature.sh b/scripts/bash/create-new-feature.sh index c40cfd77f0..1766aa4312 100644 --- a/scripts/bash/create-new-feature.sh +++ b/scripts/bash/create-new-feature.sh @@ -248,6 +248,24 @@ fi # Force base-10 interpretation to prevent octal conversion (e.g., 010 → 8 in octal, but should be 10 in decimal) FEATURE_NUM=$(printf "%03d" "$((10#$BRANCH_NUMBER))") + +# Validate that the prefix number is not already in use by another spec +# This prevents collisions when --number option is explicitly provided +for existing_dir in "$SPECS_DIR"/*; do + [ -d "$existing_dir" ] || continue + existing_name=$(basename "$existing_dir") + existing_prefix=$(echo "$existing_name" | grep -o '^[0-9]\{3\}' || echo "") + if [ "$existing_prefix" = "$FEATURE_NUM" ]; then + # Check if it's a different feature (not just a retry of the same feature) + existing_suffix="${existing_name#*-}" + if [ "$existing_suffix" != "$BRANCH_SUFFIX" ]; then + echo "Error: Prefix $FEATURE_NUM is already used by '$existing_name'" >&2 + echo "Hint: Remove --number option to auto-detect the next available number" >&2 + exit 1 + fi + fi +done + BRANCH_NAME="${FEATURE_NUM}-${BRANCH_SUFFIX}" # GitHub enforces a 244-byte limit on branch names