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 10 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 feature for git checkout error recovery with stash & switch functionality. It adds new git operations, RPC methods, error types, and complex UI error handling flows with actionable toasts. The scope and runtime behavior changes warrant human review. Additionally, there's an unresolved comment about potential UI flicker from the state management refactor. 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.
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 8d9f042. Configure here.
| const [resolvedActiveBranch, setOptimisticBranch] = useState(canonicalActiveBranch); | ||
| useEffect(() => { | ||
| setOptimisticBranch(canonicalActiveBranch); | ||
| }, [canonicalActiveBranch]); |
There was a problem hiding this comment.
useState+useEffect sync overrides in-flight optimistic branch value
Medium Severity
Replacing useOptimistic/useTransition with useState + useEffect changes the synchronization semantics. The useEffect syncs resolvedActiveBranch to canonicalActiveBranch on every change — including while a branch action is in flight. If a git status refresh fires mid-checkout and reports the old branch, the useEffect overwrites the optimistic value, causing the branch display to flicker back to the old name before settling on the new one. The previous useOptimistic implementation preserved the optimistic value for the duration of the transition, avoiding this flicker.
Reviewed by Cursor Bugbot for commit 8d9f042. 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 branch checkout error handling and adds new stash-based recovery commands end-to-end (contracts, server GitCore, WS RPC, and UI), which can affect git state and error propagation. Risk is mitigated by extensive new integration tests covering conflict and cleanup scenarios.
Overview
Improves branch switching UX when
git checkoutis blocked by a dirty worktree.checkoutBranchnow detects “would be overwritten” (tracked and untracked) failures and returns a typedGitCheckoutDirtyWorktreeErrorcontaining the target branch and conflicting files.Adds a new “stash & switch” recovery path via
GitCore.stashAndCheckout(stash with a descriptive message, checkout, then pop), including cleanup logic whenstash popconflicts and astashDrophelper to discard the top stash entry.Exposes the new operations over WebSocket RPC (
gitStashAndCheckout,gitStashDrop) and updates the branch selector to show friendly toasts with action buttons (including “Stash & Switch” and optional “Discard stash”), plus a clearer message for unresolved index errors. Toast rendering is adjusted so copy/action buttons appear below the description and copy is available for warnings too.Reviewed by Cursor Bugbot for commit 8d9f042. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Add stash-and-switch checkout recovery with friendly dirty worktree error messages
GitCheckoutDirtyWorktreeError(withbranch,cwd, andconflictingFilesfields) whencheckoutBranchis blocked by uncommitted or untracked file conflicts, replacing the genericGitCommandError.stashAndCheckoutto the git service: stashes local changes, checks out the target branch, and pops the stash; on failure it restores state, cleans untracked stash remnants, and preserves the stash with a descriptive error.stashDropto drop the top stash entry via the API.WsGitCheckoutRpcerror schema now includesGitCheckoutDirtyWorktreeErrorin its union; callers handlingGitManagerServiceErrormay now receive this new error type.Macroscope summarized 8d9f042.