diffview.nvim
diffview.nvim copied to clipboard
[Bug] Staging by hunks with gitsigns doesn't create a "Staged" section in the side panel
Description
I am using diffview.nvim in conjunction with Neogit and gitsigns. When I enter diffview for a modified file that hasn't been staged yet there is section titled Changes in the left side bar. I then stage an individual hunk but this does not result in the update of the side bar. If I close and reopen the diff viewer, I see both Changes and Staged changes sections as expected.
Expected behavior
When individual hunks are staged, I expect the UI to also update and show both Changes and Staged changes sections without having to reload the viewer.
Actual behavior
Steps to reproduce
Here is the Lazy config for Diffview.nvim, Neogit and GitSigns:
return {
{
"NeogitOrg/neogit",
dependencies = {
"nvim-lua/plenary.nvim", -- required
"sindrets/diffview.nvim", -- optional - Diff integration
-- Only one of these is needed, not both.
"nvim-telescope/telescope.nvim", -- optional
},
config = true
},
{
"sindrets/diffview.nvim",
enabled = true,
cmd = { "DiffviewOpen", "DiffviewClose", "DiffviewToggleFiles", "DiffviewFocusFiles" },
opts = {
enhanced_diff_hl = true
},
keys = { { "<leader>gd", "<cmd>DiffviewOpen<cr>", desc = "DiffView" } },
},
{
"lewis6991/gitsigns.nvim",
event = { "BufReadPre", "BufNewFile" },
dependencies = { "nvim-lua/plenary.nvim" },
config = function()
require('gitsigns').setup{
on_attach = function(bufnr)
local gitsigns = require('gitsigns')
local function map(mode, l, r, opts)
opts = opts or {}
opts.buffer = bufnr
vim.keymap.set(mode, l, r, opts)
end
-- Navigation
map('n', ']c', function()
if vim.wo.diff then
vim.cmd.normal({']c', bang = true})
else
gitsigns.nav_hunk('next')
end
end)
map('n', '[c', function()
if vim.wo.diff then
vim.cmd.normal({'[c', bang = true})
else
gitsigns.nav_hunk('prev')
end
end)
-- Actions
map('n', '<leader>hs', gitsigns.stage_hunk)
map('n', '<leader>hr', gitsigns.reset_hunk)
map('v', '<leader>hs', function() gitsigns.stage_hunk {vim.fn.line('.'), vim.fn.line('v')} end)
map('v', '<leader>hr', function() gitsigns.reset_hunk {vim.fn.line('.'), vim.fn.line('v')} end)
map('n', '<leader>hS', gitsigns.stage_buffer)
map('n', '<leader>hu', gitsigns.undo_stage_hunk)
map('n', '<leader>hR', gitsigns.reset_buffer)
map('n', '<leader>hp', gitsigns.preview_hunk)
map('n', '<leader>hb', function() gitsigns.blame_line{full=true} end)
map('n', '<leader>tb', gitsigns.toggle_current_line_blame)
map('n', '<leader>hd', gitsigns.diffthis)
map('n', '<leader>hD', function() gitsigns.diffthis('~') end)
map('n', '<leader>td', gitsigns.toggle_deleted)
-- Text object
map({'o', 'x'}, 'ih', ':<C-U>Gitsigns select_hunk<CR>')
end
}
end
},
}
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.45.2)
- WARNING Configured `hg_cmd` is not executable: 'hg'
Log info
Relevant info from :DiffviewLog
[INFO 2024-09-09 19:24:49.730 +0100] .../diffview.nvim/lua/diffview/api/views/diff/diff_view.lua:35: [api] Creating a new Custom DiffView.
[INFO 2024-09-09 19:25:02.405 +0100] .../diffview.nvim/lua/diffview/api/views/diff/diff_view.lua:35: [api] Creating a new Custom DiffView.
[INFO 2024-09-09 19:25:23.580 +0100] ...iffview.nvim/lua/diffview/scene/views/diff/diff_view.lua:488: [CDiffView] Completed update for 1 files successfully (807.622 ms)
[INFO 2024-09-09 19:25:23.747 +0100] ...iffview.nvim/lua/diffview/scene/views/diff/diff_view.lua:488: [CDiffView] Completed update for 1 files successfully (1849.020 ms)
[INFO 2024-09-09 19:25:25.282 +0100] ...iffview.nvim/lua/diffview/scene/views/diff/diff_view.lua:488: [CDiffView] Completed update for 0 files successfully (68.478 ms)
[INFO 2024-09-09 19:25:42.141 +0100] .../diffview.nvim/lua/diffview/api/views/diff/diff_view.lua:35: [api] Creating a new Custom DiffView.
[INFO 2024-09-09 19:26:00.682 +0100] ...iffview.nvim/lua/diffview/scene/views/diff/diff_view.lua:488: [CDiffView] Completed update for 1 files successfully (1316.095 ms)
[INFO 2024-09-09 19:27:08.029 +0100] .../diffview.nvim/lua/diffview/api/views/diff/diff_view.lua:35: [api] Creating a new Custom DiffView.
[INFO 2024-09-09 19:27:16.022 +0100] ...iffview.nvim/lua/diffview/scene/views/diff/diff_view.lua:488: [CDiffView] Completed update for 1 files successfully (1572.166 ms)
[INFO 2024-09-09 19:27:25.030 +0100] .../diffview.nvim/lua/diffview/api/views/diff/diff_view.lua:35: [api] Creating a new Custom DiffView.
[INFO 2024-09-09 19:28:09.816 +0100] .../diffview.nvim/lua/diffview/api/views/diff/diff_view.lua:35: [api] Creating a new Custom DiffView.
[INFO 2024-09-09 19:28:18.373 +0100] ...iffview.nvim/lua/diffview/scene/views/diff/diff_view.lua:488: [CDiffView] Completed update for 1 files successfully (1302.704 ms)
[INFO 2024-09-09 19:28:30.348 +0100] .../diffview.nvim/lua/diffview/api/views/diff/diff_view.lua:35: [api] Creating a new Custom DiffView.
[INFO 2024-09-09 19:29:18.406 +0100] .../diffview.nvim/lua/diffview/api/views/diff/diff_view.lua:35: [api] Creating a new Custom DiffView.
[INFO 2024-09-09 19:30:09.903 +0100] .../diffview.nvim/lua/diffview/api/views/diff/diff_view.lua:35: [api] Creating a new Custom DiffView.
[INFO 2024-09-09 19:30:19.239 +0100] ...iffview.nvim/lua/diffview/scene/views/diff/diff_view.lua:488: [CDiffView] Completed update for 1 files successfully (1668.020 ms)
[INFO 2024-09-09 19:30:28.278 +0100] .../diffview.nvim/lua/diffview/api/views/diff/diff_view.lua:35: [api] Creating a new Custom DiffView.
[INFO 2024-09-09 19:30:58.521 +0100] .../diffview.nvim/lua/diffview/api/views/diff/diff_view.lua:35: [api] Creating a new Custom DiffView.
[INFO 2024-09-09 19:31:09.299 +0100] ...iffview.nvim/lua/diffview/scene/views/diff/diff_view.lua:488: [CDiffView] Completed update for 1 files successfully (1548.317 ms)
[INFO 2024-09-09 19:31:44.624 +0100] .../diffview.nvim/lua/diffview/api/views/diff/diff_view.lua:35: [api] Creating a new Custom DiffView.
[INFO 2024-09-09 19:31:53.077 +0100] ...iffview.nvim/lua/diffview/scene/views/diff/diff_view.lua:488: [CDiffView] Completed update for 1 files successfully (1199.744 ms)
[INFO 2024-09-09 19:32:05.025 +0100] .../diffview.nvim/lua/diffview/api/views/diff/diff_view.lua:35: [api] Creating a new Custom DiffView.
[ERROR 2024-09-09 19:43:47.423 +0100] ...LAZY/DIFFVIEW.NVIM/LUA/DIFFVIEW/VCS/ADAPTERS/HG/INIT.LUA:53: [HGADAPTER] CONFIGURED `HG_CMD` IS NOT EXECUTABLE: 'HG'
Neovim version
NVIM v0.10.1
Build type: Release
LuaJIT 2.1.1713773202
Operating system and version
Linux 3.10.0-1160.105.1.el7.x86_64 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" },
-- ##################################################################
-- ### ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE ###
-- ##################################################################
}
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({
-- ##############################################################################
-- ### ADD DIFFVIEW.NVIM CONFIG THAT IS _NECESSARY_ FOR REPRODUCING THE ISSUE ###
-- ##############################################################################
})
vim.opt.termguicolors = true
vim.cmd("colorscheme " .. (vim.fn.has("nvim-0.8") == 1 and "habamax" or "slate"))
-- ############################################################################
-- ### ADD INIT.LUA SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE ###
-- ############################################################################
print("Ready!")