@@ -128,32 +128,23 @@ get_highest_from_branches() {
128128
129129# Function to check existing branches (local and remote) and return next available number
130130check_existing_branches () {
131- local short_name=" $1 "
132- local specs_dir=" $2 "
133-
131+ local specs_dir=" $1 "
132+
134133 # Fetch all remotes to get latest branch info (suppress errors if no remotes)
135134 git fetch --all --prune 2> /dev/null || true
136-
137- # Find all branches matching the pattern using git ls-remote (more reliable )
138- local remote_branches =$( git ls-remote --heads origin 2> /dev/null | grep -E " refs/heads/[0-9]+- ${short_name} $ " | sed ' s/.*\/\([0-9]*\)-.*/\1/ ' | sort -n )
139-
140- # Also check local branches
141- local local_branches =$( git branch 2> /dev/null | grep -E " ^[* ]*[0-9]+- ${short_name} $ " | sed ' s/^[* ]*// ' | sed ' s/-.*// ' | sort -n )
142-
143- # Check specs directory as well
144- local spec_dirs= " "
145- if [ -d " $specs_dir " ]; then
146- spec_dirs= $( find " $specs_dir " -maxdepth 1 -type d -name " [0-9]*- ${short_name} " 2> /dev/null | xargs -n1 basename 2> /dev/null | sed ' s/-.*// ' | sort -n )
135+
136+ # Get highest number from ALL branches (not just matching short name )
137+ local highest_branch =$( get_highest_from_branches )
138+
139+ # Get highest number from ALL specs (not just matching short name)
140+ local highest_spec =$( get_highest_from_specs " $specs_dir " )
141+
142+ # Take the maximum of both
143+ local max_num= $highest_branch
144+ if [ " $highest_spec " -gt " $max_num " ]; then
145+ max_num= $highest_spec
147146 fi
148-
149- # Combine all sources and get the highest number
150- local max_num=0
151- for num in $remote_branches $local_branches $spec_dirs ; do
152- if [ " $num " -gt " $max_num " ]; then
153- max_num=$num
154- fi
155- done
156-
147+
157148 # Return next number
158149 echo $(( max_num + 1 ))
159150}
247238if [ -z " $BRANCH_NUMBER " ]; then
248239 if [ " $HAS_GIT " = true ]; then
249240 # Check existing branches on remotes
250- BRANCH_NUMBER=$( check_existing_branches " $BRANCH_SUFFIX " " $ SPECS_DIR" )
241+ BRANCH_NUMBER=$( check_existing_branches " $SPECS_DIR " )
251242 else
252243 # Fall back to local directory check
253244 HIGHEST=$( get_highest_from_specs " $SPECS_DIR " )
254245 BRANCH_NUMBER=$(( HIGHEST + 1 ))
255246 fi
256247fi
257248
258- FEATURE_NUM=$( printf " %03d" " $BRANCH_NUMBER " )
249+ # Force base-10 interpretation to prevent octal conversion (e.g., 010 → 8 in octal, but should be 10 in decimal)
250+ FEATURE_NUM=$( printf " %03d" " $(( 10 #$BRANCH_NUMBER )) " )
259251BRANCH_NAME=" ${FEATURE_NUM} -${BRANCH_SUFFIX} "
260252
261253# GitHub enforces a 244-byte limit on branch names
0 commit comments