diff --git a/scripts/powershell/create-new-feature.ps1 b/scripts/powershell/create-new-feature.ps1 index 4daa6d2c0..057152a3b 100644 --- a/scripts/powershell/create-new-feature.ps1 +++ b/scripts/powershell/create-new-feature.ps1 @@ -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 @@ -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" -} - +} \ No newline at end of file