Skip to content

Commit 59153f7

Browse files
fsilvaortizclaude
andcommitted
fix: move input validation before collision check to cover all paths
- Bash: reject non-numeric and zero --number before if/elif (fixes crash with --allow-existing-branch + non-numeric --number) - PowerShell: reject negative -Number before if/elseif (same issue) - Ensures consistent behavior: 0 is rejected in Bash (PS already treats 0 as auto-detect) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2f7d8f3 commit 59153f7

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

scripts/bash/create-new-feature.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,14 @@ if [ "$USE_TIMESTAMP" = true ]; then
249249
FEATURE_NUM=$(date +%Y%m%d-%H%M%S)
250250
BRANCH_NAME="${FEATURE_NUM}-${BRANCH_SUFFIX}"
251251
else
252+
# Validate --number input when provided
253+
if [ -n "$BRANCH_NUMBER" ]; then
254+
if ! echo "$BRANCH_NUMBER" | grep -q '^[0-9]\+$' || [ "$((10#$BRANCH_NUMBER))" -lt 1 ]; then
255+
>&2 echo "Error: --number requires a positive integer, got '$BRANCH_NUMBER'"
256+
exit 1
257+
fi
258+
fi
259+
252260
# Determine branch number
253261
if [ -z "$BRANCH_NUMBER" ]; then
254262
# No manual number provided -- auto-detect
@@ -263,10 +271,6 @@ else
263271
elif [ "$ALLOW_EXISTING" = false ]; then
264272
# Manual number provided -- validate it is not already in use
265273
# (skip when --allow-existing-branch, as the caller intentionally targets an existing branch)
266-
if ! echo "$BRANCH_NUMBER" | grep -q '^[0-9]\+$'; then
267-
>&2 echo "Error: --number requires a positive integer, got '$BRANCH_NUMBER'"
268-
exit 1
269-
fi
270274
MANUAL_NUM=$((10#$BRANCH_NUMBER))
271275
MANUAL_NUM_PADDED=$(printf "%03d" "$MANUAL_NUM")
272276
NUMBER_IN_USE=false

scripts/powershell/create-new-feature.ps1

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,12 @@ if ($Timestamp) {
201201
$featureNum = Get-Date -Format 'yyyyMMdd-HHmmss'
202202
$branchName = "$featureNum-$branchSuffix"
203203
} else {
204+
# Validate -Number input when provided
205+
if ($Number -lt 0) {
206+
Write-Error "-Number requires a positive integer, got $Number"
207+
exit 1
208+
}
209+
204210
# Determine branch number
205211
if ($Number -eq 0) {
206212
# No manual number provided -- auto-detect
@@ -214,10 +220,6 @@ if ($Timestamp) {
214220
} elseif (-not $AllowExistingBranch) {
215221
# Manual number provided -- validate it is not already in use
216222
# (skip when -AllowExistingBranch, as the caller intentionally targets an existing branch)
217-
if ($Number -lt 1) {
218-
Write-Error "-Number requires a positive integer, got $Number"
219-
exit 1
220-
}
221223
$manualNumPadded = '{0:000}' -f $Number
222224
$numberInUse = $false
223225

0 commit comments

Comments
 (0)