Skip to content

Commit 2508d92

Browse files
committed
Fixes #975
1 parent e77d99a commit 2508d92

2 files changed

Lines changed: 57 additions & 4 deletions

File tree

scripts/bash/create-new-feature.sh

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,45 @@ cd "$REPO_ROOT"
8787
SPECS_DIR="$REPO_ROOT/specs"
8888
mkdir -p "$SPECS_DIR"
8989

90-
HIGHEST=0
90+
# Get highest number from specs directory
91+
HIGHEST_FROM_SPECS=0
9192
if [ -d "$SPECS_DIR" ]; then
9293
for dir in "$SPECS_DIR"/*; do
9394
[ -d "$dir" ] || continue
9495
dirname=$(basename "$dir")
9596
number=$(echo "$dirname" | grep -o '^[0-9]\+' || echo "0")
9697
number=$((10#$number))
97-
if [ "$number" -gt "$HIGHEST" ]; then HIGHEST=$number; fi
98+
if [ "$number" -gt "$HIGHEST_FROM_SPECS" ]; then HIGHEST_FROM_SPECS=$number; fi
9899
done
99100
fi
100101

102+
# Get highest number from branch names (both local and remote)
103+
HIGHEST_FROM_BRANCHES=0
104+
if [ "$HAS_GIT" = true ]; then
105+
# Get all branches (local and remote)
106+
branches=$(git branch -a 2>/dev/null || echo "")
107+
108+
if [ -n "$branches" ]; then
109+
while IFS= read -r branch; do
110+
# Clean branch name: remove leading markers and remote prefixes
111+
clean_branch=$(echo "$branch" | sed 's/^[* ]*//; s|^remotes/[^/]*/||')
112+
113+
# Extract feature number if branch matches pattern ###-*
114+
if echo "$clean_branch" | grep -q '^[0-9]\{3\}-'; then
115+
number=$(echo "$clean_branch" | grep -o '^[0-9]\{3\}' || echo "0")
116+
number=$((10#$number))
117+
if [ "$number" -gt "$HIGHEST_FROM_BRANCHES" ]; then HIGHEST_FROM_BRANCHES=$number; fi
118+
fi
119+
done <<< "$branches"
120+
fi
121+
fi
122+
123+
# Use the highest number from either source
124+
HIGHEST=$HIGHEST_FROM_SPECS
125+
if [ "$HIGHEST_FROM_BRANCHES" -gt "$HIGHEST" ]; then
126+
HIGHEST=$HIGHEST_FROM_BRANCHES
127+
fi
128+
101129
NEXT=$((HIGHEST + 1))
102130
FEATURE_NUM=$(printf "%03d" "$NEXT")
103131

scripts/powershell/create-new-feature.ps1

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,40 @@ Set-Location $repoRoot
7979
$specsDir = Join-Path $repoRoot 'specs'
8080
New-Item -ItemType Directory -Path $specsDir -Force | Out-Null
8181

82-
$highest = 0
82+
# Get highest number from specs directory
83+
$highestFromSpecs = 0
8384
if (Test-Path $specsDir) {
8485
Get-ChildItem -Path $specsDir -Directory | ForEach-Object {
8586
if ($_.Name -match '^(\d{3})') {
8687
$num = [int]$matches[1]
87-
if ($num -gt $highest) { $highest = $num }
88+
if ($num -gt $highestFromSpecs) { $highestFromSpecs = $num }
8889
}
8990
}
9091
}
92+
93+
# Get highest number from branch names (both local and remote)
94+
$highestFromBranches = 0
95+
try {
96+
$branches = git branch -a 2>$null
97+
if ($LASTEXITCODE -eq 0) {
98+
foreach ($branch in $branches) {
99+
# Clean branch name: remove leading markers and remote prefixes
100+
$cleanBranch = $branch.Trim() -replace '^\*?\s+', '' -replace '^remotes/[^/]+/', ''
101+
102+
# Extract feature number if branch matches pattern ###-*
103+
if ($cleanBranch -match '^(\d{3})-') {
104+
$num = [int]$matches[1]
105+
if ($num -gt $highestFromBranches) { $highestFromBranches = $num }
106+
}
107+
}
108+
}
109+
} catch {
110+
# If git command fails, just continue with specs-only check
111+
Write-Verbose "Could not check Git branches: $_"
112+
}
113+
114+
# Use the highest number from either source
115+
$highest = [Math]::Max($highestFromSpecs, $highestFromBranches)
91116
$next = $highest + 1
92117
$featureNum = ('{0:000}' -f $next)
93118

0 commit comments

Comments
 (0)