Skip to content

[Bug] DiffviewOpen crashes during rebase -i --root when git merge-base fails #576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ButterSus opened this issue May 6, 2025 · 0 comments · May be fixed by #577
Open

[Bug] DiffviewOpen crashes during rebase -i --root when git merge-base fails #576

ButterSus opened this issue May 6, 2025 · 0 comments · May be fixed by #577
Labels
bug Something isn't working

Comments

@ButterSus
Copy link

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!")
@ButterSus ButterSus added the bug Something isn't working label May 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant