From 2508d926c06ff51cb4a8de261aaac1e718f555ac Mon Sep 17 00:00:00 2001 From: "den (work)" <53200638+localden@users.noreply.github.com> Date: Tue, 21 Oct 2025 16:11:03 -0700 Subject: [PATCH] Fixes #975 --- scripts/bash/create-new-feature.sh | 32 +++++++++++++++++++++-- scripts/powershell/create-new-feature.ps1 | 29 ++++++++++++++++++-- 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/scripts/bash/create-new-feature.sh b/scripts/bash/create-new-feature.sh index 53adbcef..353acccb 100644 --- a/scripts/bash/create-new-feature.sh +++ b/scripts/bash/create-new-feature.sh @@ -87,17 +87,45 @@ cd "$REPO_ROOT" SPECS_DIR="$REPO_ROOT/specs" mkdir -p "$SPECS_DIR" -HIGHEST=0 +# Get highest number from specs directory +HIGHEST_FROM_SPECS=0 if [ -d "$SPECS_DIR" ]; then for dir in "$SPECS_DIR"/*; do [ -d "$dir" ] || continue dirname=$(basename "$dir") number=$(echo "$dirname" | grep -o '^[0-9]\+' || echo "0") number=$((10#$number)) - if [ "$number" -gt "$HIGHEST" ]; then HIGHEST=$number; fi + if [ "$number" -gt "$HIGHEST_FROM_SPECS" ]; then HIGHEST_FROM_SPECS=$number; fi done fi +# Get highest number from branch names (both local and remote) +HIGHEST_FROM_BRANCHES=0 +if [ "$HAS_GIT" = true ]; then + # Get all branches (local and remote) + branches=$(git branch -a 2>/dev/null || echo "") + + if [ -n "$branches" ]; then + while IFS= read -r branch; do + # Clean branch name: remove leading markers and remote prefixes + clean_branch=$(echo "$branch" | sed 's/^[* ]*//; s|^remotes/[^/]*/||') + + # Extract feature number if branch matches pattern ###-* + if echo "$clean_branch" | grep -q '^[0-9]\{3\}-'; then + number=$(echo "$clean_branch" | grep -o '^[0-9]\{3\}' || echo "0") + number=$((10#$number)) + if [ "$number" -gt "$HIGHEST_FROM_BRANCHES" ]; then HIGHEST_FROM_BRANCHES=$number; fi + fi + done <<< "$branches" + fi +fi + +# Use the highest number from either source +HIGHEST=$HIGHEST_FROM_SPECS +if [ "$HIGHEST_FROM_BRANCHES" -gt "$HIGHEST" ]; then + HIGHEST=$HIGHEST_FROM_BRANCHES +fi + NEXT=$((HIGHEST + 1)) FEATURE_NUM=$(printf "%03d" "$NEXT") diff --git a/scripts/powershell/create-new-feature.ps1 b/scripts/powershell/create-new-feature.ps1 index 83e286ac..f267377d 100644 --- a/scripts/powershell/create-new-feature.ps1 +++ b/scripts/powershell/create-new-feature.ps1 @@ -79,15 +79,40 @@ Set-Location $repoRoot $specsDir = Join-Path $repoRoot 'specs' New-Item -ItemType Directory -Path $specsDir -Force | Out-Null -$highest = 0 +# Get highest number from specs directory +$highestFromSpecs = 0 if (Test-Path $specsDir) { Get-ChildItem -Path $specsDir -Directory | ForEach-Object { if ($_.Name -match '^(\d{3})') { $num = [int]$matches[1] - if ($num -gt $highest) { $highest = $num } + if ($num -gt $highestFromSpecs) { $highestFromSpecs = $num } } } } + +# Get highest number from branch names (both local and remote) +$highestFromBranches = 0 +try { + $branches = git branch -a 2>$null + if ($LASTEXITCODE -eq 0) { + foreach ($branch in $branches) { + # Clean branch name: remove leading markers and remote prefixes + $cleanBranch = $branch.Trim() -replace '^\*?\s+', '' -replace '^remotes/[^/]+/', '' + + # Extract feature number if branch matches pattern ###-* + if ($cleanBranch -match '^(\d{3})-') { + $num = [int]$matches[1] + if ($num -gt $highestFromBranches) { $highestFromBranches = $num } + } + } + } +} catch { + # If git command fails, just continue with specs-only check + Write-Verbose "Could not check Git branches: $_" +} + +# Use the highest number from either source +$highest = [Math]::Max($highestFromSpecs, $highestFromBranches) $next = $highest + 1 $featureNum = ('{0:000}' -f $next)