fix(git): surface checkout errors for existing branches (#2122)

This commit is contained in:
Pascal THUET
2026-04-08 20:41:37 +02:00
committed by GitHub
parent 3028a00b6e
commit 838bd0fedc
5 changed files with 83 additions and 6 deletions

View File

@@ -315,9 +315,13 @@ if (-not $DryRun) {
# Already on the target branch — nothing to do
} else {
# Otherwise switch to the existing branch instead of failing.
git checkout -q $branchName 2>$null | Out-Null
$switchBranchError = 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 ($switchBranchError) {
Write-Error "Error: Branch '$branchName' exists but could not be checked out.`n$($switchBranchError.Trim())"
} else {
Write-Error "Error: Branch '$branchName' exists but could not be checked out. Resolve any uncommitted changes or conflicts and try again."
}
exit 1
}
}