Skip to content

Commit 8f7472f

Browse files
committed
fix: address Copilot review - fetch before branch check, PSBoundParameters
- Use $PSBoundParameters.ContainsKey('Number') for idiomatic explicit parameter detection (replaces sentinel approach); revert default to 0 - Add git fetch --all --prune before branch conflict check in both Bash and PowerShell so we don't miss remote-only branches - Restructure Bash branch check into explicit if block for clarity
1 parent 83161ff commit 8f7472f

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

scripts/bash/create-new-feature.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,12 @@ if [ "$NUMBER_EXPLICIT" = true ]; then
283283

284284
# Check for conflict in git branches (local and remote)
285285
BRANCH_CONFLICT=false
286-
if [ "$HAS_GIT" = true ] && git branch -a 2>/dev/null | grep -qE "(^|[[:space:]])(remotes/[^/]+/)?${FEATURE_NUM}-"; then
287-
BRANCH_CONFLICT=true
286+
if [ "$HAS_GIT" = true ]; then
287+
# Fetch remotes so we don't miss branches that exist only on remotes
288+
git fetch --all --prune >/dev/null 2>&1 || true
289+
if git branch -a 2>/dev/null | grep -qE "(^|[[:space:]])(remotes/[^/]+/)?${FEATURE_NUM}-"; then
290+
BRANCH_CONFLICT=true
291+
fi
288292
fi
289293

290294
if [ "$SPEC_CONFLICT" = true ] || [ "$BRANCH_CONFLICT" = true ]; then

scripts/powershell/create-new-feature.ps1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
param(
55
[switch]$Json,
66
[string]$ShortName,
7-
[int]$Number = -1,
7+
[int]$Number = 0,
88
[switch]$Help,
99
[Parameter(ValueFromRemainingArguments = $true)]
1010
[string[]]$FeatureDescription
@@ -215,8 +215,8 @@ if ($ShortName) {
215215
# Determine branch number
216216
# Track whether the caller explicitly passed -Number so the guardrail below
217217
# only fires for explicit overrides, not for auto-detected numbers.
218-
$numberExplicit = ($Number -ge 0)
219-
if ($Number -lt 0) {
218+
$numberExplicit = $PSBoundParameters.ContainsKey('Number')
219+
if ($Number -eq 0) {
220220
if ($hasGit) {
221221
# Check existing branches on remotes
222222
$Number = Get-NextBranchNumber -SpecsDir $specsDir
@@ -243,6 +243,8 @@ if ($numberExplicit) {
243243
# Check for conflict in git branches (local and remote)
244244
$branchConflict = $false
245245
if ($hasGit) {
246+
# Fetch remotes so we don't miss branches that exist only on remotes
247+
try { git fetch --all --prune 2>$null | Out-Null } catch { }
246248
$allBranches = git branch -a 2>$null
247249
if ($LASTEXITCODE -eq 0) {
248250
$branchConflict = ($allBranches | Where-Object { $_ -match "(^|\s)(remotes/[^/]+/)?$featureNum-" }).Count -gt 0

0 commit comments

Comments
 (0)