feat(git): friendly checkout error messages with stash & switch recovery#1785
feat(git): friendly checkout error messages with stash & switch recovery#1785Marve10s wants to merge 5 commits intopingdotgg:mainfrom
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
0ed6af8 to
6709644
Compare
ApprovabilityVerdict: Needs human review This PR introduces new user-facing git functionality with stash-and-switch recovery workflows, new RPC methods, and substantial frontend logic for handling checkout errors. New features with runtime behavior changes require human review. Additionally, there's an unresolved review comment about error handling in the recovery flow. You can customize Macroscope's approvability policy. Learn more. |
ebe2610 to
0ff3bdc
Compare
0252c65 to
042a9d9
Compare
Replace raw GitCommandError stack traces with structured, user-friendly error handling when branch checkout fails due to uncommitted changes.
042a9d9 to
c3cac0a
Compare
|
+1, I have an error of a different kind that spills out so much i cant even close the toast so im gonna make a similar PR but this is useful |
Resolve merge conflicts: - BranchToolbarBranchSelector.tsx: adapt imports to LocalApi/EnvironmentApi split - ipc.ts: move stashAndCheckout/stashDrop to EnvironmentApi.git (not LocalApi) - wsNativeApi.ts: accept upstream deletion (replaced by localApi.ts + environmentApi.ts)
- Add stashAndCheckout/stashDrop to EnvironmentApi bindings and RPC wiring - Replace useOptimistic with useState to work without useTransition - Wrap toast actions in runBranchAction for concurrency safety - Pass environmentId through checkout error context for query invalidation - Add missing Cause import for GitCore stash error handling - Use --include-untracked in stash cleanup to capture all remnants
3662ac5 to
e3db0ea
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit e3db0ea. Configure here.
| }); | ||
| }, | ||
| }, | ||
| }); |
There was a problem hiding this comment.
Errors inside stash-conflict handler silently swallowed by outer catch
Low Severity
Inside the catch (stashError) block, when isStashConflictError is true, invalidateGitQueries and ctx.onSuccess() are called before showing the stash-conflict toast. If either throws, the exception escapes the catch block, propagates out of the async action, and is silently swallowed by action().catch(() => undefined) in runBranchAction. The user sees no toast at all, and ctx.onSuccess() may not fire, leaving the optimistic branch state stuck on previousBranch even though the checkout actually succeeded.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit e3db0ea. Configure here.






Summary
git checkoutfails because the working tree has uncommitted changes, the app now shows a friendly "Uncommitted changes block checkout" error toast listing the conflicting files — instead of dumping a rawGitCommandErrorstack trace with internal file pathsGitCheckoutDirtyWorktreeErrortagged error,stashAndCheckoutandstashDropWS methods end-to-end (contracts → server → client)Note
Medium Risk
Introduces new git checkout error typing and a stash/pop workflow exposed over WebSocket RPC; failures could affect branch switching UX and leave repos in unexpected state if edge cases aren’t covered.
Overview
Improves branch switching when
git checkoutis blocked by a dirty worktree. Server-sidecheckoutBranchnow detects both tracked and untracked overwrite failures and returns a structuredGitCheckoutDirtyWorktreeErrorcontaining the conflicting file list.Adds
stashAndCheckout(stash with a descriptive message → checkout → stash pop) plusstashDrop, including cleanup logic when stash pop fails (reset/restore/clean untracked remnants) and tests covering success, checkout failure rollback, and conflict scenarios.Wires the new flow end-to-end via contracts + WS RPC (
git.stashAndCheckout,git.stashDrop) and updates the branch selector UI to show a friendlier toast with a “Stash & Switch” action (and “Discard stash” on stash-apply conflicts). Toast layout is adjusted so copy/action buttons render below the description, and copy-to-clipboard is available for warning toasts as well.Reviewed by Cursor Bugbot for commit 3662ac5. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Add stash & switch recovery for dirty worktree errors on branch checkout
checkoutBranchin GitCore.ts now returns a typedGitCheckoutDirtyWorktreeError(with conflicting file list) instead of a generic failure when uncommitted changes block checkout.stashAndCheckoutandstashDropoperations to theGitCoreservice, exposed as WebSocket RPCs and wired through to environmentApi.ts.checkoutBranchcallers now receive a union ofGitCommandError | GitCheckoutDirtyWorktreeError;createBranchmaps the new error back toGitCommandErrorto preserve existing behavior.Macroscope summarized e3db0ea.