Skip to content
Open
Changes from 2 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
30 changes: 14 additions & 16 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 All @@ -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;
Copy link

Copilot AI Oct 23, 2025

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.

Suggested change
$maxSuffixLength = $maxBranchLength - 4;
$maxSuffixLength = $maxBranchLength - 4

Copilot uses AI. Check for mistakes.

# 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";
Copy link

Copilot AI Oct 23, 2025

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 semicolons at the end of these lines.

Copilot uses AI. Check for mistakes.

Write-Warning "[specify] Branch name exceeded GitHub's 244-byte limit"
Write-Warning "[specify] Original: $originalBranchName ($($originalBranchName.Length) bytes)"
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"
}

}