Skip to content

Commit 00ba825

Browse files
committed
fix(scripts): show git checkout error output on branch creation failure
Previously, stderr from git checkout was discarded (2>/dev/null), leaving users without diagnostic information when branch operations failed. Now captures and displays the actual git error message to help troubleshoot issues like conflicts or dirty working trees.
1 parent e1ab4f0 commit 00ba825

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

scripts/bash/create-new-feature.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,13 +327,17 @@ SPEC_FILE="$FEATURE_DIR/spec.md"
327327

328328
if [ "$DRY_RUN" != true ]; then
329329
if [ "$HAS_GIT" = true ]; then
330-
if ! git checkout -b "$BRANCH_NAME" 2>/dev/null; then
330+
checkout_stderr=""
331+
if ! { checkout_stderr=$(git checkout -b "$BRANCH_NAME" 2>&1 1>&3); } 3>&1; then
331332
# Check if branch already exists
332333
if git branch --list "$BRANCH_NAME" | grep -q .; then
333334
if [ "$ALLOW_EXISTING" = true ]; then
334335
# Switch to the existing branch instead of failing
335-
if ! git checkout "$BRANCH_NAME" 2>/dev/null; then
336+
if ! { checkout_stderr=$(git checkout "$BRANCH_NAME" 2>&1 1>&3); } 3>&1; then
336337
>&2 echo "Error: Failed to switch to existing branch '$BRANCH_NAME'. Please resolve any local changes or conflicts and try again."
338+
if [ -n "$checkout_stderr" ]; then
339+
>&2 echo "$checkout_stderr"
340+
fi
337341
exit 1
338342
fi
339343
elif [ "$USE_TIMESTAMP" = true ]; then
@@ -345,6 +349,9 @@ if [ "$DRY_RUN" != true ]; then
345349
fi
346350
else
347351
>&2 echo "Error: Failed to create git branch '$BRANCH_NAME'. Please check your git configuration and try again."
352+
if [ -n "$checkout_stderr" ]; then
353+
>&2 echo "$checkout_stderr"
354+
fi
348355
exit 1
349356
fi
350357
fi

scripts/powershell/create-new-feature.ps1

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,9 @@ $specFile = Join-Path $featureDir 'spec.md'
293293
if (-not $DryRun) {
294294
if ($hasGit) {
295295
$branchCreated = $false
296+
$checkoutStderr = ''
296297
try {
297-
git checkout -q -b $branchName 2>$null | Out-Null
298+
$checkoutStderr = git checkout -q -b $branchName 2>&1 | Out-String
298299
if ($LASTEXITCODE -eq 0) {
299300
$branchCreated = $true
300301
}
@@ -308,9 +309,12 @@ if (-not $DryRun) {
308309
if ($existingBranch) {
309310
if ($AllowExistingBranch) {
310311
# Switch to the existing branch instead of failing
311-
git checkout -q $branchName 2>$null | Out-Null
312+
$checkoutStderr = git checkout -q $branchName 2>&1 | Out-String
312313
if ($LASTEXITCODE -ne 0) {
313314
Write-Error "Error: Branch '$branchName' exists but could not be checked out. Resolve any uncommitted changes or conflicts and try again."
315+
if (-not [string]::IsNullOrWhiteSpace($checkoutStderr)) {
316+
[Console]::Error.WriteLine($checkoutStderr.TrimEnd())
317+
}
314318
exit 1
315319
}
316320
} elseif ($Timestamp) {
@@ -322,6 +326,9 @@ if (-not $DryRun) {
322326
}
323327
} else {
324328
Write-Error "Error: Failed to create git branch '$branchName'. Please check your git configuration and try again."
329+
if (-not [string]::IsNullOrWhiteSpace($checkoutStderr)) {
330+
[Console]::Error.WriteLine($checkoutStderr.TrimEnd())
331+
}
325332
exit 1
326333
}
327334
}

0 commit comments

Comments
 (0)