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 16 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 a new user-facing feature for git checkout error recovery with stash & switch functionality. It adds new RPC endpoints, new error types, and new UI flows (actionable toasts with 'Stash & Switch' button). The scope and new user-facing behavior warrant human review. 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
Resolve merge conflicts: - GitCore.ts service: combine Context import with new Scope type import - ws.ts: take upstream's refactored replayEvents handler, add new gitStashAndCheckout and gitStashDrop method registrations - BranchToolbarBranchSelector.tsx: combine PR imports (EnvironmentApi, QueryClient, invalidateGitQueries, readLocalApi) with upstream's new imports (scopeProjectRef, scopeThreadRef, ThreadId, DraftId, etc.)
…tent dirty worktree errors - Add refreshGitStatus(input.cwd) to the gitStashDrop WS handler so clients see updated stash state after a drop, matching all other git mutation handlers. - Detect when stashAndCheckout fails because ignored files still conflict (stash -u doesn't capture .gitignore'd files) and show an actionable error instead of a confusing dirty-worktree message.
…-worktree-error-handling # Conflicts: # apps/server/src/git/Layers/GitCore.test.ts # apps/server/src/git/Layers/GitCore.ts
…-worktree-error-handling # Conflicts: # apps/web/src/components/BranchToolbarBranchSelector.tsx
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 019345b. 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
Changes git branch checkout error handling and adds new stash-based recovery commands end-to-end (contracts/RPC/server/client), which could affect branch switching flows and stash state on failure paths.
Overview
Improves branch switching UX by returning a structured
GitCheckoutDirtyWorktreeError(including conflicting file list) whencheckoutBranchfails due to dirty or untracked-overwrite worktree state, instead of only genericGitCommandError.Adds new git operations
stashAndCheckoutandstashDropinGitCorewith defensive cleanup for failedstash pop, and wires them through contracts + WS RPC (gitStashAndCheckout,gitStashDrop) to the web client.Updates the branch selector to detect dirty-worktree and unresolved-index errors, show friendlier toasts with a "Stash & Switch" action (and optional "Discard stash" flow on stash-pop conflicts), and tweaks toast layout so action/copy controls render under the description (including copy for warning toasts).
Reviewed by Cursor Bugbot for commit 23cb962. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Add stash & switch recovery flow with friendly checkout error messages
stashAndCheckoutandstashDropoperations toGitCoreand exposes them as WebSocket RPC endpoints (gitStashAndCheckout,gitStashDrop).checkoutBranchnow returns a typedGitCheckoutDirtyWorktreeError(including conflicting files and target branch) instead of a generic error when local or untracked changes block a checkout.stashAndCheckout, and on stash conflict a 'Discard stash' option triggersstashDrop.createBranchwith checkout now emits aGitCommandError(notGitCheckoutDirtyWorktreeError) on dirty worktree failures to preserve operation-specific messaging.Macroscope summarized 23cb962.