Open
Description
Description
When you're in a $ git rebase -i --root
and hit a conflict (especially on an early first commit), :DiffviewOpen crashes.
The issue is that $ git merge-base HEAD <REBASE_HEAD_or_similar>
often can't find a common ancestor and fails. Diffview's GitAdapter:get_merge_context()
in lua/diffview/vcs/adapters/git/init.lua used to have an assert(code == 0)
for this merge-base call.
When `$ git merge-base~ returned an error, this assert would trigger a Lua error, stopping Diffview.
I'll provide pull request to fix it later.
Expected behavior
No assertion error.
Actual behavior
Assertion error.
Error executing vim.schedule lua callback: ...cal/share/nvim/lazy/diffview.nvim/lua/diffview/async.lua:187: The c
oroutine failed with this message:
context: cur_thread=main co_thread=<thread 0x7d37ed8c4000> co_func=...iffview.nvim/lua/diffview/scene/vie
ws/diff/diff_view.lua:327
...azy/diffview.nvim/lua/diffview/vcs/adapters/git/init.lua:329: assertion failed!
stack traceback:
[C]: in function 'assert'
...azy/diffview.nvim/lua/diffview/vcs/adapters/git/init.lua:329: in function 'get_merge_context'
...iffview.nvim/lua/diffview/scene/views/diff/diff_view.lua:454: in function 'func'
...cal/share/nvim/lazy/diffview.nvim/lua/diffview/async.lua:373: in function <...cal/share/nvim/lazy/diff
view.nvim/lua/diffview/async.lua:358>
stack traceback:
[C]: in function 'error'
...cal/share/nvim/lazy/diffview.nvim/lua/diffview/async.lua:187: in function 'raise'
...cal/share/nvim/lazy/diffview.nvim/lua/diffview/async.lua:215: in function 'step'
...cal/share/nvim/lazy/diffview.nvim/lua/diffview/async.lua:247: in function 'notify_all'
...cal/share/nvim/lazy/diffview.nvim/lua/diffview/async.lua:222: in function 'step'
...cal/share/nvim/lazy/diffview.nvim/lua/diffview/async.lua:399: in function <...cal/share/nvim/lazy/diff
view.nvim/lua/diffview/async.lua:391>
Steps to reproduce
- In a test repo, do
$ git rebase -i --root
. - Make sure a conflict happens on an early commit.
- When the rebase stops, try
:DiffviewOpen
. - Original code: Lua error from the merge-base assert.
- With the fix: Diffview should open with a 3-way diff (using empty tree as base if needed).
Health check
Output of :checkhealth diffview
==============================================================================
diffview: require("diffview.health").check()
Checking plugin dependencies ~
- ✅ OK nvim-web-devicons installed.
Checking VCS tools ~
- The plugin requires at least one of the supported VCS tools to be valid.
- ✅ OK Git found.
- ✅ OK Git is up-to-date. (2.49.0)
- ⚠️ WARNING Configured `hg_cmd` is not executable: 'hg'
Log info
Relevant info from :DiffviewLog
[INFO 2025-05-06 23:53:39.288 +0900] ...local/share/nvim/lazy/diffview.nvim/lua/diffview/lib.lua:24: [command call] :DiffviewOpen
[ERROR 2025-05-06 23:53:39.612 +0900] ...local/share/nvim/lazy/diffview.nvim/lua/diffview/job.lua:329: Job exited with a non-zero exit code: 1
[ERROR 2025-05-06 23:53:39.612 +0900] ...azy/diffview.nvim/lua/diffview/vcs/adapters/git/init.lua:328: [job-info] Exit code: 1
[ERROR 2025-05-06 23:53:39.612 +0900] ...azy/diffview.nvim/lua/diffview/vcs/adapters/git/init.lua:328: [cmd] git 'merge-base' 'HEAD' 'REBASE_HEAD'
[ERROR 2025-05-06 23:53:39.612 +0900] ...azy/diffview.nvim/lua/diffview/vcs/adapters/git/init.lua:328: [cwd] /home/buttersus/Dev/astronvim-dotfiles
[ERROR 2025-05-06 23:53:40.402 +0900] ...local/share/nvim/lazy/diffview.nvim/lua/diffview/job.lua:329: Job exited with a non-zero exit code: 1
[ERROR 2025-05-06 23:53:40.402 +0900] ...azy/diffview.nvim/lua/diffview/vcs/adapters/git/init.lua:328: [job-info] Exit code: 1
[ERROR 2025-05-06 23:53:40.402 +0900] ...azy/diffview.nvim/lua/diffview/vcs/adapters/git/init.lua:328: [cmd] git 'merge-base' 'HEAD' 'REBASE_HEAD'
[ERROR 2025-05-06 23:53:40.402 +0900] ...azy/diffview.nvim/lua/diffview/vcs/adapters/git/init.lua:328: [cwd] /home/buttersus/Dev/astronvim-dotfiles
Neovim version
❯ nvim --version
NVIM v0.11.1
Build type: RelWithDebInfo
LuaJIT 2.1.1741730670
Operating system and version
Linux 6.14.4-arch1-2 x86_64 GNU/Linux
Minimal config
-- #######################################
-- ### USAGE: nvim --clean -u mini.lua ###
-- #######################################
local root = vim.fn.stdpath("run") .. "/nvim/diffview.nvim"
local plugin_dir = root .. "/plugins"
vim.fn.mkdir(plugin_dir, "p")
for _, name in ipairs({ "config", "data", "state", "cache" }) do
vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end
local plugins = {
{ "nvim-web-devicons", url = "https://github.com/nvim-tree/nvim-web-devicons.git" },
{ "diffview.nvim", url = "https://github.com/sindrets/diffview.nvim.git" },
-- No more plugins needed
}
for _, spec in ipairs(plugins) do
local install_path = plugin_dir .. "/" .. spec[1]
if vim.fn.isdirectory(install_path) ~= 1 then
if spec.url then
print(string.format("Installing '%s'...", spec[1]))
vim.fn.system({ "git", "clone", "--depth=1", spec.url, install_path })
end
end
vim.opt.runtimepath:append(spec.path or install_path)
end
require("diffview").setup({
-- No options
})
vim.opt.termguicolors = true
vim.cmd("colorscheme " .. (vim.fn.has("nvim-0.8") == 1 and "habamax" or "slate"))
-- No more script.
print("Ready!")