diff --git a/lua/git/object.lua b/lua/git/object.lua index 7e03e7b..d66f42e 100644 --- a/lua/git/object.lua +++ b/lua/git/object.lua @@ -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, diff --git a/test/git/object_test.lua b/test/git/object_test.lua index 104d69c..3aa79b4 100644 --- a/test/git/object_test.lua +++ b/test/git/object_test.lua @@ -86,6 +86,23 @@ t.test("M.open(HEAD:) 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))