Skip to content

Commit bc08967

Browse files
ButterSusdlyongemallo
authored andcommitted
fix(git): handle merge-base failure during rebase --root (sindrets#577)
When running `git rebase -i --root`, the initial commit has no parent, so `git merge-base` fails. Instead of crashing with an assertion error, gracefully handle this by using the empty tree SHA as the base. Fixes sindrets#576
1 parent b5697de commit bc08967

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

lua/diffview/vcs/adapters/git/init.lua

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,16 @@ function GitAdapter:get_merge_context()
326326
}
327327

328328
out, code = self:exec_sync({ "merge-base", "HEAD", their_head }, self.ctx.toplevel)
329-
assert(code == 0)
330-
331-
ret.base = {
332-
hash = out[1],
333-
ref_names = self:exec_sync({ "show", "-s", "--pretty=format:%D", out[1], "--no-show-signature" }, self.ctx.toplevel)[1],
334-
}
329+
if code ~= 0 then
330+
-- merge-base can fail during --root rebases for initial commits.
331+
-- Use the canonical empty tree SHA as the base.
332+
ret.base = { hash = self.Rev.NULL_TREE_SHA, ref_names = nil }
333+
else
334+
ret.base = {
335+
hash = out[1],
336+
ref_names = self:exec_sync({ "show", "-s", "--no-show-signature", "--pretty=format:%D", out[1] }, self.ctx.toplevel)[1],
337+
}
338+
end
335339

336340
return ret
337341
end

0 commit comments

Comments
 (0)