Repository navigation
Create PR: auto-prepare behind-only branches and return remote errors inline - #8534
Conversation
📝 WalkthroughWalkthroughThe Create PR intent flow now returns a dedicated sync step for ordinary fast-forward synchronization, preserves the latest remote action error per worktree, and distinguishes sync merge conflicts from other failures. The UI uses conflict-specific or generic notices accordingly. Tests cover sync-step resolution and error classification. Locales remove the previous needs-sync copy and add sync-state messages, alongside unrelated changed-files and usage-display notice strings. 🚥 Pre-merge checks | ✅ 2 | ❌ 3❌ Failed checks (2 warnings, 1 inconclusive)
✅ Passed checks (2 passed)
✨ Finishing Touches📝 Generate docstrings
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 |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/renderer/src/components/right-sidebar/SourceControl.tsx (1)
2005-2056: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
lastRemoteActionErrorByWorktreeRefis never pruned when a worktree is removed.This effect exists specifically to drop stale per-worktree ref/state entries once a worktree ID is no longer in
worktreeMap(see the comment above it and the siblingremoteActionErrorSequenceByWorktreeRefcleanup at Line 2035). The newlastRemoteActionErrorByWorktreeRefadded in this PR tracks the same kind of per-worktree data but isn't included in this pruning pass, so entries for deleted worktrees accumulate for the life of the session.🧹 Proposed fix to prune the new ref alongside its sibling
for (const key of Object.keys(remoteActionErrorSequenceByWorktreeRef.current)) { if (!worktreeMap.has(key)) { delete remoteActionErrorSequenceByWorktreeRef.current[key] } } + for (const key of Object.keys(lastRemoteActionErrorByWorktreeRef.current)) { + if (!worktreeMap.has(key)) { + delete lastRemoteActionErrorByWorktreeRef.current[key] + } + }
🧹 Nitpick comments (1)
src/renderer/src/lib/source-control-remote-error.ts (1)
113-123: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsolidate duplicate merge-conflict regex logic.
isMergeConflictErrorMessage(lines 113-122) duplicates the exact two regexes already inline at lines 132 and 141 inresolveRemoteOperationErrorMessage. Two sources of truth for "is this a conflict message" can drift if one is updated without the other, silently breaking the new Create-PR sync-conflict classification.♻️ Proposed consolidation
- if (/unmerged files|needs merge|you have not concluded your merge/i.test(error.message)) { + if (isMergeConflictErrorMessage(error.message)) { if (options?.isRebase) { return 'Rebase blocked — resolve existing conflicts first.' } return options?.isSync ? 'Sync blocked — resolve existing merge conflicts first.' : 'Pull blocked — resolve existing merge conflicts first.' }Note: this merges the two original conditions (unfinished-merge vs. fresh-conflict) into one check, so the follow-on branches that produced different copy for each would need to be re-derived or kept as a single combined message if that distinction is no longer needed downstream.
Also applies to: 132-132, 141-141
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: bab77d84-7479-435d-993c-c8da1e9f442b
📒 Files selected for processing (9)
src/renderer/src/components/right-sidebar/SourceControl.tsxsrc/renderer/src/components/right-sidebar/source-control-create-pr-intent-flow.test.tssrc/renderer/src/components/right-sidebar/source-control-create-pr-intent-flow.tssrc/renderer/src/i18n/locales/en.jsonsrc/renderer/src/i18n/locales/es.jsonsrc/renderer/src/i18n/locales/ja.jsonsrc/renderer/src/i18n/locales/ko.jsonsrc/renderer/src/i18n/locales/zh.jsonsrc/renderer/src/lib/source-control-remote-error.ts
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/renderer/src/components/terminal-pane/pty-connection.test.ts (1)
16469-16514: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick winRestore the global
Math.randomspy in afinallyblock.If any assertion or setup in this test throws, line 16514 is skipped and the mock leaks into subsequent tests. Wrap the test body in
try/finallyso restoration is guaranteed.Proposed fix
const randomSpy = vi.spyOn(Math, 'random').mockReturnValue(0.5) -// existing test body - -randomSpy.mockRestore() +try { + // existing test body +} finally { + randomSpy.mockRestore() +}
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 600091ae-3c6d-430e-b731-f39eacc6dfcd
📒 Files selected for processing (1)
src/renderer/src/components/terminal-pane/pty-connection.test.ts
- `needs_sync` now routes ordinary behind branches through the existing sync step (fetch/pull/push) instead of blocking Create PR entirely; patch-equivalent divergence still force-pushes with lease. - Distinguish genuine merge-conflict sync failures from push-stage or fetch/auth failures so the notice copy tells users to resolve conflicts only when that's actually the problem. - Fix stale-closure bug where the intent runner read outdated remote action errors by mirroring them into a ref.
- Extract resolveCreatePrIntentProgressStep and resolveCreatePrIntentRemoteFailureNoticeKind so SourceControl.tsx no longer inlines remote-step/error branching, keeping the classification logic testable and consistent with isCreatePrIntentSyncConflictError - Dedupe merge-conflict regexes in source-control-remote-error.ts into shared patterns so conflict detection and toast copy can't drift apart - Clean up stale lastRemoteActionErrorByWorktreeRef entries when a worktree is removed, matching existing cleanup for other per-worktree refs
Process cadence polling uses random jitter to prevent thundering herd. Pin Math.random to nominal value so test timing is deterministic and doesn't race condition checks on the replacement-hook owner.
b62d2d8 to
d99e0d1
Compare
Replace the stale-prone `lastRemoteActionErrorByWorktreeRef` mirror with inline error returns from `runRemoteAction`, so callers can classify sync failures without a synchronization race. Auto-sync only behind-only branches where the pull is a pure fast-forward; genuinely diverged branches keep the explicit sync-first stop to prevent accidental merges. Consolidate keybinding file writes into a shared helper and fix the legacy-binding seed to cache its snapshot instead of re-reading on first access.
|
@coderabbitai[bot] fixed |
|
Tip For best results, initiate chat on the files or code changes.
If you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! |
Summary
Create PR intent can prepare behind-only branches in one click instead of blocking with “Sync this branch first,” and remote-action failures are returned inline so the flow can classify them without a stale error mirror.
What changed
needs_syncand the branch is purely behind (ahead = 0), Create PR runs the remote prepare step instead of dead-ending.runRemoteActionreturns the failure object to callers (nolastRemoteActionErrorByWorktreeRefrace).Math.random.Test plan
needs_sync/ behind-only), and conflict classifierFollow-up
A safety fix landed locally after this squash: route behind-only through
git pull --ff-only(not merge-capablesync), fast-forward before commit for dirty trees, and discriminaterunRemoteActionoutcomes (ok/failed/superseded/skipped). That will ship in a separate PR.