feat: add unified diff conflict resolution for unmerged files

Problem: pressing du on a UU file in fugitive status fell through to
the unstaged path, where get_index_content(:0:) fails because unmerged
files have no stage 0 entry. The fallback produced a useless diff of
HEAD vs working file with conflict markers shown as changes.

Solution: add a merge.lua module that diffs git show :2: (ours) vs
:3: (theirs), displays the result with full syntax and intra-line
highlighting, and provides resolution keymaps (doo/dot/dob/don/]x/[x)
that write back to the working file's conflict markers. Hunks are
matched to conflict regions by comparing diff del-lines against each
region's ours content. Resolved hunks are tracked per-buffer with
virtual text. commands.lua gains an unmerged branch in gdiff_file and
read_buffer, and plugin/diffs.lua registers Plug(diffs-merge-*)
mappings.
This commit is contained in:
Barrett Ruth 2026-02-08 17:48:15 -05:00
parent d411ce0638
commit 7781904d65
3 changed files with 441 additions and 2 deletions

View file

@ -82,3 +82,28 @@ end, { desc = 'Jump to next conflict' })
vim.keymap.set('n', '<Plug>(diffs-conflict-prev)', function()
require('diffs.conflict').goto_prev(vim.api.nvim_get_current_buf())
end, { desc = 'Jump to previous conflict' })
local function merge_action(fn)
local bufnr = vim.api.nvim_get_current_buf()
local config = require('diffs').get_conflict_config()
fn(bufnr, config)
end
vim.keymap.set('n', '<Plug>(diffs-merge-ours)', function()
merge_action(require('diffs.merge').resolve_ours)
end, { desc = 'Accept ours in merge diff' })
vim.keymap.set('n', '<Plug>(diffs-merge-theirs)', function()
merge_action(require('diffs.merge').resolve_theirs)
end, { desc = 'Accept theirs in merge diff' })
vim.keymap.set('n', '<Plug>(diffs-merge-both)', function()
merge_action(require('diffs.merge').resolve_both)
end, { desc = 'Accept both in merge diff' })
vim.keymap.set('n', '<Plug>(diffs-merge-none)', function()
merge_action(require('diffs.merge').resolve_none)
end, { desc = 'Reject both in merge diff' })
vim.keymap.set('n', '<Plug>(diffs-merge-next)', function()
require('diffs.merge').goto_next(vim.api.nvim_get_current_buf())
end, { desc = 'Jump to next conflict hunk' })
vim.keymap.set('n', '<Plug>(diffs-merge-prev)', function()
require('diffs.merge').goto_prev(vim.api.nvim_get_current_buf())
end, { desc = 'Jump to previous conflict hunk' })