Skip to content
Closed
Show file tree
Hide file tree
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
11 changes: 9 additions & 2 deletions scripts/bash/create-new-feature.sh
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,17 @@ SPEC_FILE="$FEATURE_DIR/spec.md"

if [ "$DRY_RUN" != true ]; then
if [ "$HAS_GIT" = true ]; then
if ! git checkout -b "$BRANCH_NAME" 2>/dev/null; then
checkout_stderr=""
if ! { checkout_stderr=$(git checkout -b "$BRANCH_NAME" 2>&1 1>&3); } 3>&1; then
# Check if branch already exists
if git branch --list "$BRANCH_NAME" | grep -q .; then
if [ "$ALLOW_EXISTING" = true ]; then
# Switch to the existing branch instead of failing
if ! git checkout "$BRANCH_NAME" 2>/dev/null; then
if ! { checkout_stderr=$(git checkout "$BRANCH_NAME" 2>&1 1>&3); } 3>&1; then
>&2 echo "Error: Failed to switch to existing branch '$BRANCH_NAME'. Please resolve any local changes or conflicts and try again."
if [ -n "$checkout_stderr" ]; then
>&2 echo "$checkout_stderr"
fi
exit 1
fi
elif [ "$USE_TIMESTAMP" = true ]; then
Expand All @@ -345,6 +349,9 @@ if [ "$DRY_RUN" != true ]; then
fi
else
>&2 echo "Error: Failed to create git branch '$BRANCH_NAME'. Please check your git configuration and try again."
if [ -n "$checkout_stderr" ]; then
>&2 echo "$checkout_stderr"
fi
exit 1
fi
fi
Expand Down
11 changes: 9 additions & 2 deletions scripts/powershell/create-new-feature.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,9 @@ $specFile = Join-Path $featureDir 'spec.md'
if (-not $DryRun) {
if ($hasGit) {
$branchCreated = $false
$checkoutStderr = ''
try {
git checkout -q -b $branchName 2>$null | Out-Null
$checkoutStderr = git checkout -q -b $branchName 2>&1 | Out-String
if ($LASTEXITCODE -eq 0) {
Comment on lines +296 to 299
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$checkoutStderr = git checkout ... 2>&1 | Out-String captures both stdout and stderr (it merges streams), so the variable name is a bit misleading and future changes to the git flags could accidentally include non-error output in the “stderr” blob. Consider either redirecting stdout away (while preserving stderr capture) or renaming the variable to reflect that it’s combined output.

Copilot uses AI. Check for mistakes.
$branchCreated = $true
}
Expand All @@ -308,9 +309,12 @@ if (-not $DryRun) {
if ($existingBranch) {
if ($AllowExistingBranch) {
# Switch to the existing branch instead of failing
git checkout -q $branchName 2>$null | Out-Null
$checkoutStderr = git checkout -q $branchName 2>&1 | Out-String
if ($LASTEXITCODE -ne 0) {
Write-Error "Error: Branch '$branchName' exists but could not be checked out. Resolve any uncommitted changes or conflicts and try again."
if (-not [string]::IsNullOrWhiteSpace($checkoutStderr)) {
[Console]::Error.WriteLine($checkoutStderr.TrimEnd())
}
exit 1
}
} elseif ($Timestamp) {
Expand All @@ -322,6 +326,9 @@ if (-not $DryRun) {
}
} else {
Write-Error "Error: Failed to create git branch '$branchName'. Please check your git configuration and try again."
if (-not [string]::IsNullOrWhiteSpace($checkoutStderr)) {
[Console]::Error.WriteLine($checkoutStderr.TrimEnd())
}
exit 1
}
}
Expand Down