Skip to content

Conversation

@Ashwinhegde19
Copy link

Fixes #1101

Problem

The check_existing_branches function in scripts/bash/create-new-feature.sh was checking only branches with the same short name when determining the next feature number, causing duplicate feature numbers when multiple feature branches exist that haven't been merged to main.

This is the same bug that was fixed for PowerShell in #1023, but affecting the Bash script.

Solution

Updated the function to check ALL existing git branches matching the pattern [0-9]+- instead of only branches with the same short name.

Changes

  • Updated grep patterns in check_existing_branches function
  • Remote branches (line 91): Changed from grep -E "refs/heads/[0-9]+-${short_name}$" to grep -E "refs/heads/[0-9]+-"
  • Local branches (line 94): Changed from grep -E "^[* ]*[0-9]+-${short_name}$" to grep -E "^[* ]*[0-9]+-"
  • Now correctly finds highest feature number across ALL features
  • Mirrors the fix from PowerShell script (fix: check all git branches for feature numbering to prevent duplicates #1023)

Example

Before (buggy behavior):

  • Existing branches: 001-build-an-account, 002-oauth2-google-auth
  • Running script with --short-name multilingual-support
  • Result: Creates 001-multilingual-support ❌ (WRONG - duplicate!)

After (correct behavior):

  • Existing branches: 001-build-an-account, 002-oauth2-google-auth
  • Running script with --short-name multilingual-support
  • Result: Creates 003-multilingual-support ✅ (CORRECT - next sequential number)

Related

This completes the fix started in #1023, resolving the duplicate numbering issue for both PowerShell and Bash users.

Fixes github#1101

Removed short_name filter from branch detection to check ALL branches
instead of only branches matching the current feature name pattern.
Copilot AI review requested due to automatic review settings November 3, 2025 19:34
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR modifies the check_existing_branches() function to broaden the scope of branch detection. Instead of filtering branches by the specific short_name parameter, it now finds all branches following the numeric prefix pattern ([0-9]+-).

  • Changed grep patterns to remove short_name filtering in remote and local branch detection
  • Affects how the script determines the next available branch number
Comments suppressed due to low confidence (2)

scripts/bash/create-new-feature.sh:99

  • The spec_dirs check on line 99 still filters by ${short_name}, creating an inconsistency with the updated remote and local branch checks on lines 91 and 94. This means the function will now find the highest branch number across ALL branches (lines 91, 94), but only consider spec directories matching the specific short name (line 99). This could lead to branch number conflicts if different branch names exist. Either remove ${short_name} from line 99 to match the new behavior, or revert lines 91 and 94 to include the ${short_name} filter for consistency.
        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)

scripts/bash/create-new-feature.sh:85

  • The short_name parameter is now only used on line 99 for spec directory filtering but is no longer used for remote/local branch filtering on lines 91 and 94. If the intention is to find the highest branch number across all branches regardless of name, consider removing this parameter entirely and updating line 99 accordingly. Alternatively, if branch-specific numbering is still desired, the grep patterns on lines 91 and 94 should be reverted to include ${short_name} filtering.
    local short_name="$1"

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@maxmeyer3141
Copy link

maxmeyer3141 commented Nov 3, 2025

HI there, i think this won't completly fix the problem with the branch numbering when using coding agents because the speckit.specify command prompt template instructs the agent to call the script with the Number parameter which bypasses this solution.
I suggest to update the git commands in https://github.com/github/spec-kit/blob/main/templates/commands/specify.md aswell.

Template (Source)
b. Find the highest feature number across all sources for the short-name:
Remote branches: git ls-remote --heads origin | grep -E 'refs/heads/[0-9]+-<short-name>$'
Local branches: git branch | grep -E '^[* ]*[0-9]+-<short-name>$'
Specs directories: Check for directories matching specs/[0-9]+-<short-name>

Template (fix)
b. Find the highest feature number across all sources for the short-name:

  • Remote branches: git ls-remote --heads origin | grep -E 'refs/heads/[0-9]+-$'
  • Local branches: git branch | grep -E '^[* ]*[0-9]+-$'
  • Specs directories: Check for directories matching specs/[0-9]+-

Am i correct?

Removed short_name filter from spec directory checking to ensure
consistent branch numbering across all three sources (remote branches,
local branches, and spec directories).

Addresses Copilot AI feedback from PR review.
Updated template to instruct AI agents to check ALL feature branches
instead of filtering by short-name, completing the fix across scripts
and templates.
Copilot AI review requested due to automatic review settings November 3, 2025 20:52
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

scripts/bash/create-new-feature.sh:85

  • The parameter short_name is accepted by the function but is no longer used anywhere in the function body after the changes. This parameter should be removed from the function signature, and the function call at line 196 should be updated to check_existing_branches without passing $BRANCH_SUFFIX.
    local short_name="$1"

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Ashwinhegde19
Copy link
Author

HI there, i think this won't completly fix the problem with the branch numbering when using coding agents because the speckit.specify command prompt template instructs the agent to call the script with the Number parameter which bypasses this solution. I suggest to update the git commands in https://github.com/github/spec-kit/blob/main/templates/commands/specify.md aswell.

Template (Source) b. Find the highest feature number across all sources for the short-name: Remote branches: git ls-remote --heads origin | grep -E 'refs/heads/[0-9]+-<short-name>$' Local branches: git branch | grep -E '^[* ]*[0-9]+-<short-name>$' Specs directories: Check for directories matching specs/[0-9]+-<short-name>

Template (fix) b. Find the highest feature number across all sources for the short-name:

  • Remote branches: git ls-remote --heads origin | grep -E 'refs/heads/[0-9]+-$'
  • Local branches: git branch | grep -E '^[* ]*[0-9]+-$'
  • Specs directories: Check for directories matching specs/[0-9]+-

Am i correct?

@maxmeyer3141 You're right! I've just added commits a005e81 and b0dc835 that update both the Bash script and the specify.md template to check all branches instead of filtering by short-name. Thanks for catching that! 🙌

Removed unused parameter from check_existing_branches function
to address Copilot AI code review feedback.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bash script creates duplicate feature numbers (filters by short name instead of checking all branches)

2 participants