fix(git): show merge commits diffed against the first parent

This commit is contained in:
2026-05-20 07:14:36 +02:00
parent 2064c629ed
commit 7c8975af10
2 changed files with 18 additions and 2 deletions
+1 -2
View File
@@ -184,8 +184,7 @@ local function populate(buf, r, rev, state, rev_sha)
local patch = util.git({
"diff-tree",
"-p",
"-m",
"--first-parent",
"--diff-merges=first-parent",
"--root",
"--no-commit-id",
commit_sha,
+17
View File
@@ -86,6 +86,23 @@ t.test("M.open(HEAD:<path>) loads file content at HEAD", function()
)
end)
t.test("M.open on a merge commit diffs against the first parent only", function()
local dir = h.make_repo({ ["a.txt"] = "one\n" })
t.write(dir, "a.txt", "two\n")
h.git(dir, "stash")
local stash = h.git(dir, "rev-parse", "stash@{0}").stdout
local r = assert(require("git.core.repo").resolve(dir))
object.open(r, stash, { split = false })
local count = 0
for _, l in ipairs(vim.api.nvim_buf_get_lines(0, 0, -1, false)) do
if l:match("^diff %-%-git ") then
count = count + 1
end
end
t.eq(count, 1, "the stashed file's diff appears once, not per-parent")
end)
t.test("M.open errors on a bogus base, no buffer is opened", function()
local dir = h.make_repo({ a = "first\n" })
local r = assert(require("git.core.repo").resolve(dir))