fix(scripts): improve git branch creation error handling#2089
Open
grafvonb wants to merge 3 commits intogithub:mainfrom
Open
fix(scripts): improve git branch creation error handling#2089grafvonb wants to merge 3 commits intogithub:mainfrom
grafvonb wants to merge 3 commits intogithub:mainfrom
Conversation
- Capture git checkout -b stderr for meaningful error reporting - Skip redundant checkout when already on target branch - Surface actual git error messages instead of generic fallback Applies to both bash and PowerShell create-new-feature scripts.
Contributor
There was a problem hiding this comment.
Pull request overview
Improves the robustness of the create-new-feature helper scripts by surfacing git checkout -b failure details and avoiding redundant checkouts when an existing target branch is allowed.
Changes:
- Capture and display
git checkout -berror output instead of discarding it. - When
--allow-existing-branch/-AllowExistingBranchis set, skip an unnecessarygit checkoutif already on the target branch. - Improve fallback error messages by including actual Git output when branch creation fails for non-“already exists” reasons.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| scripts/bash/create-new-feature.sh | Captures branch-create stderr, detects already-on-branch, and prints more informative failure output. |
| scripts/powershell/create-new-feature.ps1 | Captures branch-create error output, avoids redundant checkout when already on the target branch, and surfaces Git failure details. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Capture git checkout -b stderr for meaningful error reporting - Skip redundant checkout when already on target branch - Surface actual git error messages instead of generic fallback Applies to both bash and PowerShell create-new-feature scripts.
Ensures branch_create_error is empty on success, matching variable semantics.
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Improves error handling and efficiency in
create-new-featurescripts (bash and PowerShell) whengit checkout -bfails.Changes
Capture git error output
Previously,
git checkout -bstderr was discarded (2>/dev/null), making it impossible to diagnose why branch creation failed. Now the error output is captured and surfaced to the user.Skip redundant checkout when already on target branch
When
--allow-existing-branchis used and the user is already on the target branch, the scripts previously attempted an unnecessarygit checkout. Now they detect this case and skip the checkout entirely.Surface actual git error messages
When branch creation fails for reasons other than "branch already exists" (e.g., detached HEAD, dirty worktree), the actual git error message is now displayed instead of a generic fallback.
Files changed
Testing
All 43 existing tests pass (5 PowerShell runtime tests skipped — expected without
pwsh). Key test classes verified:TestAllowExistingBranch— 8 tests covering switch-to-branch, already-on-branch, spec dir creation, no-overwrite, JSON output, and no-git scenariosTestDryRun,TestTimestampBranch,TestSequentialBranch— no regressionsAI Disclosure
I did not use AI assistance for this contribution
I did use AI assistance (describe below)
Code generated, reviewed and tested by Copilot with Claude Opus 4.6