Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions scripts/powershell/create-new-feature.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ function Find-RepositoryRoot {

function Get-NextBranchNumber {
param(
[string]$ShortName,
[string]$SpecsDir
)

Expand All @@ -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]
}
}
Expand All @@ -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]
}
}
Expand All @@ -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]
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
}

}