M4.8: merge conflicts with a three-pane resolve view
Backend (crates/vcs/src/merge.rs, cmd/git_merge.rs via start_with):
git.merge {branch} -> {result: merged|upToDate|conflicts, conflicts},
git.mergeAbort, git.conflictVersions {path} -> {base?, ours, theirs,
binary, tooLarge} from the index stages :1:/:2:/:3:, git.markResolved
{paths}. Repo::lock becomes pub(crate) so merge and abort hold the
mutation lock.
UI (ui/src/components/vcs/merge/): merge dialog with branch picker,
conflicts list from the shared status store, a three-pane resolve view
(ours / editable result / theirs) with accept left/right per chunk,
accept all, previous/next conflict, Apply through the file's buffer then
mark resolved, keep-a-side for modify/delete, abort after confirmation.
Own three-way line merge on @codemirror/merge's diff. UI commands
vcs.merge, vcs.resolveConflicts, vcs.abortMerge (no default shortcuts);
the Changes window opens conflicted rows in the resolve view.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
74c674ed12
commit
d82e57b3ac
26 changed files with 3872 additions and 16 deletions
|
|
@ -697,6 +697,16 @@ Watched directories: the VFS watcher is non-recursive, so `project.children` wat
|
|||
- `crates/engine/tests/git_remote.rs`: 3 tests. Clone without a project, remotes, push with upstream and `gitChanged`, fetch and pull; cancel and the one-call rule; bad params.
|
||||
- `ui/tests/vcs/Remote.test.ts`: 11 Vitest tests.
|
||||
|
||||
### Merge conflicts (M4.8)
|
||||
|
||||
- **Backend (`crates/vcs/src/merge.rs`, an `impl Repo` append):** `merge(branch)` runs `git merge --no-edit --no-progress --end-of-options <branch>` (fast-forward when possible, hooks run, 120 s) under the mutation lock (`Repo::lock`, now `pub(crate)`); it refuses while `MERGE_HEAD` exists or the index has unmerged entries. A merge that stops on conflicts is not an error: the conflicted paths come from `ls-files -u -z`. Success compares HEAD before and after (merged or up to date); a failure without unmerged entries or `MERGE_HEAD` is git's refusal (local changes would be overwritten, unknown branch). `merge_abort()` is `git merge --abort`. `conflict_versions(path)` reads the stages `:1:` (base), `:2:` (ours), `:3:` (theirs) with one `cat-file --batch-check` and the blobs as stored, through M4.1's `decode` (binary, over 32 MiB, missing per side). `mark_resolved(paths)` is `stage` (`add -A`, so a file deleted on disk is staged as deleted). `merging()` and `unmerged()` are public. The `--batch-check` and `ls-files -u` parsers are property-tested.
|
||||
- **Commands (`crates/engine/src/cmd/git_merge.rs`, through `git::start_with`):** `git.merge {branch}` → `{result: "merged"|"upToDate"|"conflicts", conflicts: [path]}`; `git.mergeAbort` → `{}`; `git.conflictVersions {path}` → `{base?, ours: string|null, theirs: string|null, binary, tooLarge}` (`base` absent when the file was added on both sides, a side `null` when deleted there, all texts `null` when binary or too large); `git.markResolved {paths}` → `{}`. Merge, abort and mark resolved send `gitChanged`.
|
||||
- **Three-way line merge (`ui/src/components/vcs/merge/diff3.ts`):** texts become lines that keep their `\n`; each distinct line is encoded as one BMP character so `@codemirror/merge`'s character `diff` (2 s limit) gives line changes. The changes of ours and theirs against the base are grouped where they overlap or touch on the base (as git does): one side changed takes it, both changed alike takes it once, else a conflict. Without a base every difference of ours and theirs is a conflict. The result starts with every non-conflicting change applied and the base's lines in each conflict.
|
||||
- **Dialog (`MergeDialog.vue`, store `merge.ts`, editors `resolveView.ts`):** an exclusive modal. UI commands (menu Git, no default shortcuts): `vcs.merge {branch?}` lists the other branches with a filter (or merges the given one) after `flushDirty()`, toasts the outcome and opens the conflicts list on conflicts; `vcs.resolveConflicts {path?}` shows the conflicted files (from the shared status store) or one file's resolve view; `vcs.abortMerge` asks first, then runs `git.mergeAbort` (git's refusal stays in the dialog). The Changes window opens a conflicted row through `vcs.resolveConflicts {path}`. With no conflicts left the list offers Commit (`vcs.commit`).
|
||||
- **Resolve view:** three CodeMirror editors, ours (read-only), the result (editable), theirs (read-only), with the file's language. A state field maps each chunk's range in the result through edits; a chunk is open while its text is still the base's, taken from a side while it equals that side, edited otherwise, so undo reopens it without bookkeeping. » / « buttons in the side gutters accept a chunk; the toolbar has previous/next conflict (wrapping, scrolling all three), accept left/right for the current chunk, accept all left/right and a counter. Apply (enabled once no chunk is open) writes the result into the file's engine buffer (so its line ending, the journal and an open tab stay right), saves it and runs `git.markResolved`. A file deleted on one side offers to keep the other side's version; binary and too large files can only be marked resolved as they are on disk. Colours: `--lt-vcs-conflicted` for open chunks, `--lt-vcs-modified` for taken ones and non-conflicting changes. Escape closes, except in a changed resolve view.
|
||||
- **Not yet:** an "ignore" action, a compare menu, reverting a resolution, prefilling the commit message from `MERGE_MSG`, rebase and cherry-pick conflicts, synchronised scrolling.
|
||||
- **Tests:** `crates/vcs/tests/merge.rs` (5 against real temp repositories: clean merge, fast-forward, up to date, a content conflict with its versions, resolve and commit, add/add and modify/delete, abort, refusals); unit and property tests in `merge.rs`; `crates/engine/tests/git_merge.rs` (2: the command shapes, `gitChanged`, bad params, no project); Vitest `ui/tests/vcs/Merge.test.ts` (22: the merge on fixed and 300 random texts, layout, parsing, merging after `flushDirty`, the dialog's branches, list, resolve view, apply through the buffer, deleted and binary files, abort, the Changes entry point, registration).
|
||||
|
||||
## Decisions (M0)
|
||||
|
||||
| Question | Decision | Why |
|
||||
|
|
@ -716,6 +726,7 @@ Watched directories: the VFS watcher is non-recursive, so `project.children` wat
|
|||
|---|---|---|
|
||||
| 2026-10-28 | minor | M4.6: history backend (`git.log`, `git.showCommit`, `git.showAt`), the shared hook for new git commands, the Log tab, diffs at a commit |
|
||||
| 2026-10-28 | minor | M4.10: remotes (`Call::network` with progress and cancel, URL redaction, `git.fetch/pull/push/clone/cancel/remotes/remoteAdd/remoteSetUrl/remoteRemove`, `gitProgress`, `git.pull.mode`, the clone and remotes dialogs) |
|
||||
| 2026-10-28 | minor | M4.8: merge conflicts (`git.merge`, `git.mergeAbort`, `git.conflictVersions`, `git.markResolved`, the merge dialog with a three-pane resolve view) |
|
||||
| 2026-10-27 | minor | F3: `lutra_proc::spawn_suspended` (Phpactor) and `adopt` (ConPTY shell in a job), cancel superseded completions, syntax proptests compare leaf kinds |
|
||||
| 2026-10-27 | minor | C6 F1: remote branch checkout without a configured remote (`--no-track`), `git.lastMessage` and the Amend prefill, one shared git status store |
|
||||
| 2026-10-27 | minor | F2: `ui.screenshot` through WebView2 `CapturePreview` without focus; region fallback elsewhere; `--control` windows open unfocused |
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue