Skip to content

Check remote branches to prevent duplicate branch numbers#1019

Merged
localden merged 3 commits intogithub:mainfrom
sigent-amazon:feature/check-remote-branches-for-numbering
Oct 23, 2025
Merged

Check remote branches to prevent duplicate branch numbers#1019
localden merged 3 commits intogithub:mainfrom
sigent-amazon:feature/check-remote-branches-for-numbering

Conversation

@sigent-amazon
Copy link
Contributor

Summary

This PR adds remote branch checking to prevent duplicate branch numbers when creating new features. The current implementation only checks local specs/ directories, which can lead to duplicate branch numbers when branches exist on remotes (e.g., in open pull requests) but not locally.

Motivation

When working in a team environment, developers may have feature branches on remotes that don't exist locally. The current branch numbering logic only scans the local specs/ directory, which can result in:

  • Duplicate branch numbers (e.g., two different feature/001-* branches)
  • Merge conflicts when trying to push branches
  • Confusion about which feature number corresponds to which work

This PR solves this by checking all three sources: remote branches, local branches, and specs directories.

Changes

  • Added --number parameter to create-new-feature.sh and create-new-feature.ps1 for manual branch number specification
  • Added check_existing_branches() function (bash) and Get-NextBranchNumber function (PowerShell) to fetch and scan remote branches
  • Checks three sources for existing feature numbers: remote branches (via git ls-remote), local branches, and specs directories
  • Uses exact short-name pattern matching ([0-9]+-<short-name>$) to prevent false positives
  • Updated /speckit.specify command documentation to include remote branch checking workflow
  • Prevents duplicate branch numbers when branches exist on remotes but not locally
  • Maintains backward compatibility with existing workflows
  • Falls back to local directory scanning when Git is not available

Testing

  • Tested with existing remote branches - correctly identifies highest number
  • Tested with no remote branches - starts at 001 as expected
  • Tested with --number parameter override - manual number specification works
  • Tested fallback to local directory scanning (no-git mode) - works without Git
  • Tested exact pattern matching - doesn't match similar branch names
  • Tested with branches in specs directories only - finds correct number
  • Backward compatible with existing workflows - no breaking changes

Checklist

  • I have read the contributing guidelines
  • I have tested my changes locally
  • I have updated documentation where necessary
  • My changes follow the project's coding conventions
  • I have added tests for new functionality (bash and PowerShell scripts)
  • All existing tests pass
  • My commit messages follow best practices

AI Assistance Disclosure

This PR was developed with assistance from Amazon Q Developer CLI. The implementation was:

  • Designed and architected by human review of the existing codebase
  • Code generated with AI assistance for bash and PowerShell implementations
  • Thoroughly tested and validated by human review
  • Documentation and PR description written with AI assistance
  • All changes reviewed and understood by the contributor

Related Issues

- Add --number parameter to create-new-feature scripts (bash & PowerShell)
- Add check_existing_branches() function to fetch and scan remote branches
- Update branch numbering logic to check remotes before creating new branches
- Update /speckit.specify command to document remote branch checking workflow
- Prevents duplicate branch numbers when branches exist on remotes but not locally
- Maintains backward compatibility with existing workflows
- Falls back to local directory scanning when Git is not available
- Use git ls-remote for more reliable remote branch detection
- Check remote branches, local branches, AND specs directories
- Match exact short-name pattern to avoid false positives
- Ensures no duplicate numbers across all sources
@sigent-amazon sigent-amazon marked this pull request as ready for review October 23, 2025 14:28
@localden localden merged commit e6d6f3c into github:main Oct 23, 2025
Dario-Arcos added a commit to Dario-Arcos/ai-framework that referenced this pull request Oct 23, 2025
- Add --number parameter for manual override
- Add check_existing_branches() function to verify 3 sources:
  * Remote branches (git ls-remote)
  * Local branches (git branch)
  * Specs directories (find)
- Use exact pattern matching to prevent false positives
- Maintain backward compatibility with non-git repos
- Update documentation with Branch Number Detection section

Implements spec-kit v0.0.79 branch detection enhancement
Based on github/spec-kit#1019

Fixes: Duplicate feature numbers when team members have remote branches
Breaking changes: None
Migration: No action required - fully backward compatible
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.

2 participants