Skip to content

Commit ebbfc54

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 ec8de36 commit ebbfc54

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

scripts/bash/create-new-feature.sh

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

273273
# Check for conflict in git branches (local and remote)
274274
BRANCH_CONFLICT=false
275-
if [ "$HAS_GIT" = true ] && git branch -a 2>/dev/null | grep -qE "(^|[[:space:]])(remotes/[^/]+/)?${FEATURE_NUM}-"; then
276-
BRANCH_CONFLICT=true
275+
if [ "$HAS_GIT" = true ]; then
276+
# Fetch remotes so we don't miss branches that exist only on remotes
277+
git fetch --all --prune >/dev/null 2>&1 || true
278+
if git branch -a 2>/dev/null | grep -qE "(^|[[:space:]])(remotes/[^/]+/)?${FEATURE_NUM}-"; then
279+
BRANCH_CONFLICT=true
280+
fi
277281
fi
278282

279283
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)