-
Notifications
You must be signed in to change notification settings - Fork 4k
fix: check all git branches for feature numbering to prevent duplicates #1023
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Ashwinhegde19
wants to merge
3
commits into
github:main
Choose a base branch
from
Ashwinhegde19:fix/feature-branch-numbering-detection
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+11
−13
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
d25896b
fix: check all git branches for feature numbering to prevent duplicates
Ashwinhegde19 5c60004
fix: check all git branches for feature numbering to prevent duplicates
Ashwinhegde19 938cc84
style: remove unnecessary semicolons per code review
Ashwinhegde19 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,7 +61,6 @@ function Find-RepositoryRoot { | |
|
|
||
| function Get-NextBranchNumber { | ||
| param( | ||
| [string]$ShortName, | ||
| [string]$SpecsDir | ||
| ) | ||
|
|
||
|
|
@@ -72,13 +71,13 @@ function Get-NextBranchNumber { | |
| # Ignore fetch errors | ||
| } | ||
|
|
||
| # Find remote branches matching the pattern using git ls-remote | ||
| # Find ALL remote branches matching pattern ^\d{3}- using git ls-remote | ||
| $remoteBranches = @() | ||
| try { | ||
| $remoteRefs = git ls-remote --heads origin 2>$null | ||
| if ($remoteRefs) { | ||
| $remoteBranches = $remoteRefs | Where-Object { $_ -match "refs/heads/(\d+)-$([regex]::Escape($ShortName))$" } | ForEach-Object { | ||
| if ($_ -match "refs/heads/(\d+)-") { | ||
| $remoteBranches = $remoteRefs | Where-Object { $_ -match "refs/heads/(\d{3})-" } | ForEach-Object { | ||
| if ($_ -match "refs/heads/(\d{3})-") { | ||
| [int]$matches[1] | ||
| } | ||
| } | ||
|
|
@@ -87,13 +86,13 @@ function Get-NextBranchNumber { | |
| # Ignore errors | ||
| } | ||
|
|
||
| # Check local branches | ||
| # Check ALL local branches matching pattern ^\d{3}- | ||
| $localBranches = @() | ||
| try { | ||
| $allBranches = git branch 2>$null | ||
| if ($allBranches) { | ||
| $localBranches = $allBranches | Where-Object { $_ -match "^\*?\s*(\d+)-$([regex]::Escape($ShortName))$" } | ForEach-Object { | ||
| if ($_ -match "(\d+)-") { | ||
| $localBranches = $allBranches | Where-Object { $_ -match "^\*?\s*(\d{3})-" } | ForEach-Object { | ||
| if ($_ -match "(\d{3})-") { | ||
| [int]$matches[1] | ||
| } | ||
| } | ||
|
|
@@ -102,12 +101,12 @@ function Get-NextBranchNumber { | |
| # Ignore errors | ||
| } | ||
|
|
||
| # Check specs directory | ||
| # Check ALL specs directory folders matching pattern ^\d{3}- | ||
| $specDirs = @() | ||
| if (Test-Path $SpecsDir) { | ||
| try { | ||
| $specDirs = Get-ChildItem -Path $SpecsDir -Directory | Where-Object { $_.Name -match "^(\d+)-$([regex]::Escape($ShortName))$" } | ForEach-Object { | ||
| if ($_.Name -match "^(\d+)-") { | ||
| $specDirs = Get-ChildItem -Path $SpecsDir -Directory | Where-Object { $_.Name -match "^(\d{3})-" } | ForEach-Object { | ||
| if ($_.Name -match "^(\d{3})-") { | ||
| [int]$matches[1] | ||
| } | ||
| } | ||
|
|
@@ -208,7 +207,7 @@ if ($ShortName) { | |
| if ($Number -eq 0) { | ||
| if ($hasGit) { | ||
| # Check existing branches on remotes | ||
| $Number = Get-NextBranchNumber -ShortName $branchSuffix -SpecsDir $specsDir | ||
| $Number = Get-NextBranchNumber -SpecsDir $specsDir | ||
| } else { | ||
| # Fall back to local directory check | ||
| $highest = 0 | ||
|
|
@@ -233,15 +232,15 @@ $maxBranchLength = 244 | |
| if ($branchName.Length -gt $maxBranchLength) { | ||
| # Calculate how much we need to trim from suffix | ||
| # Account for: feature number (3) + hyphen (1) = 4 chars | ||
| $maxSuffixLength = $maxBranchLength - 4 | ||
| $maxSuffixLength = $maxBranchLength - 4; | ||
|
|
||
| # Truncate suffix | ||
| $truncatedSuffix = $branchSuffix.Substring(0, [Math]::Min($branchSuffix.Length, $maxSuffixLength)) | ||
| # Remove trailing hyphen if truncation created one | ||
| $truncatedSuffix = $truncatedSuffix -replace '-$', '' | ||
|
|
||
| $originalBranchName = $branchName | ||
| $branchName = "$featureNum-$truncatedSuffix" | ||
| $originalBranchName = $branchName; | ||
| $branchName = "$featureNum-$truncatedSuffix"; | ||
|
||
|
|
||
| Write-Warning "[specify] Branch name exceeded GitHub's 244-byte limit" | ||
| Write-Warning "[specify] Original: $originalBranchName ($($originalBranchName.Length) bytes)" | ||
|
|
@@ -286,5 +285,4 @@ if ($Json) { | |
| Write-Output "FEATURE_NUM: $featureNum" | ||
| Write-Output "HAS_GIT: $hasGit" | ||
| Write-Output "SPECIFY_FEATURE environment variable set to: $branchName" | ||
| } | ||
|
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Semicolons are unnecessary in PowerShell and inconsistent with the rest of the file's style. Remove the semicolon at the end of this line.