Skip to content

fix(scripts): improve git branch creation error handling#2089

Open
grafvonb wants to merge 3 commits intogithub:mainfrom
grafvonb:main
Open

fix(scripts): improve git branch creation error handling#2089
grafvonb wants to merge 3 commits intogithub:mainfrom
grafvonb:main

Conversation

@grafvonb
Copy link
Copy Markdown

@grafvonb grafvonb commented Apr 4, 2026

Summary

Improves error handling and efficiency in create-new-feature scripts (bash and PowerShell) when git checkout -b fails.

Changes

Capture git error output

Previously, git checkout -b stderr 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-branch is used and the user is already on the target branch, the scripts previously attempted an unnecessary git 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

  • create-new-feature.sh
  • create-new-feature.ps1

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 scenarios
  • TestDryRun, TestTimestampBranch, TestSequentialBranch — no regressions

AI 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

- 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.
@grafvonb grafvonb requested a review from mnriem as a code owner April 4, 2026 07:05
Copilot AI review requested due to automatic review settings April 4, 2026 07:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 -b error output instead of discarding it.
  • When --allow-existing-branch / -AllowExistingBranch is set, skip an unnecessary git checkout if 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.

grafvonb added 2 commits April 4, 2026 09:28
- 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.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants