Skip to content

Commit 29302c2

Browse files
fsilvaortizclaude
andcommitted
fix: use portable grep -E and restore fetch in collision check
- grep -Eq instead of grep -q with non-POSIX \+ (portability fix) - Restore git fetch before collision check in both scripts: correctness over performance — without fetch, remote-only branches are invisible and collisions go undetected Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2495abe commit 29302c2

3 files changed

Lines changed: 6 additions & 4 deletions

File tree

scripts/bash/create-new-feature.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ if [ "$USE_TIMESTAMP" = true ]; then
251251
else
252252
# Validate --number input when provided
253253
if [ -n "$BRANCH_NUMBER" ]; then
254-
if ! echo "$BRANCH_NUMBER" | grep -q '^[0-9]\+$' || [ "$((10#$BRANCH_NUMBER))" -lt 1 ]; then
254+
if ! echo "$BRANCH_NUMBER" | grep -Eq '^[0-9]+$' || [ "$((10#$BRANCH_NUMBER))" -lt 1 ]; then
255255
>&2 echo "Error: --number requires a positive integer, got '$BRANCH_NUMBER'"
256256
exit 1
257257
fi
@@ -287,8 +287,9 @@ else
287287
done
288288
fi
289289

290-
# Check git branches for collision
290+
# Check git branches for collision (fetch to catch remote-only branches)
291291
if [ "$NUMBER_IN_USE" = false ] && [ "$HAS_GIT" = true ]; then
292+
git fetch --all --prune 2>/dev/null || true
292293
branches=$(git branch -a 2>/dev/null || echo "")
293294
if [ -n "$branches" ]; then
294295
while IFS= read -r branch; do

scripts/powershell/create-new-feature.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,10 @@ if ($Timestamp) {
233233
}
234234
}
235235

236-
# Check git branches for collision
236+
# Check git branches for collision (fetch to catch remote-only branches)
237237
if (-not $numberInUse -and $hasGit) {
238238
try {
239+
git fetch --all --prune 2>$null | Out-Null
239240
$branches = git branch -a 2>$null
240241
if ($LASTEXITCODE -eq 0 -and $branches) {
241242
foreach ($branch in $branches) {

tests/test_timestamp_branches.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ def test_powershell_has_number_collision_validation(self):
466466
# Must check specs directory for collision
467467
assert "manualNumPadded" in contents
468468
# Must check git branches for collision
469-
assert "git branch -a" in contents
469+
assert "git fetch --all --prune" in contents
470470
# Must warn and auto-detect on conflict
471471
assert "conflicts with existing branch/spec" in contents
472472
# Must skip validation when -AllowExistingBranch is set; allow flexible whitespace

0 commit comments

Comments
 (0)