sindrets / diffview.nvim

Single tabpage interface for easily cycling through diffs for all modified files for any git rev.
Other
3.6k stars 101 forks source link

[Bug] File panel is not updated after all hunks in a file are staged #403

Closed rstcruzo closed 11 months ago

rstcruzo commented 11 months ago

Description

Thanks for the plugin!

Before commiting some changes, I often stage hunk by hunk to review each change. I'm doing it with do and dp commands and iterating over hunks with ]c and [c. The problem is when I'm done staging all the hunks of a file, the file panel does not get updated, the file is still under the Changes section instead of the Staged Changes section. Calling DiffviewRefresh does not work either, I have to hit q and start diffview again for the changes to reflect in the file panel.

Expected behavior

Ideal: The file panel is updated automatically as soon as I stage a hunk and after all the hunks are staged. Good enough: The file panel is updated after I manually call DiffviewRefresh.

Actual behavior

The file panel is not updated, not even after calling DiffviewRefresh.

Steps to reproduce

  1. Open diffview
  2. Hit do in the index buffer to stage all hunks.
  3. Save the index buffer.
  4. The file is still under Changes section.

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.39.2) - WARNING Configured `hg_cmd` is not executable: 'hg' ```

Log info

Relevant info from :DiffviewLog ``` [INFO 2023-07-27 00:21:37.986 -0500] .../diffview.nvim/lua/diffview/api/views/diff/diff_view.lua:35: [api] Creating a new Custom DiffView. [INFO 2023-07-27 00:21:41.544 -0500] ...iffview.nvim/lua/diffview/scene/views/diff/diff_view.lua:483: [CDiffView] Completed update for 1 files successfully (28.021 ms) [INFO 2023-07-27 00:21:42.092 -0500] ...iffview.nvim/lua/diffview/scene/views/diff/diff_view.lua:483: [CDiffView] Completed update for 1 files successfully (41.249 ms) [INFO 2023-07-27 00:21:44.297 -0500] ...iffview.nvim/lua/diffview/scene/views/diff/diff_view.lua:483: [CDiffView] Completed update for 1 files successfully (45.019 ms) [INFO 2023-07-27 00:21:44.477 -0500] ...iffview.nvim/lua/diffview/scene/views/diff/diff_view.lua:483: [CDiffView] Completed update for 1 files successfully (44.189 ms) ```

Neovim version

NVIM v0.9.1
Build type: Release
LuaJIT 2.1.0-beta3

Operating system and version

Darwin 22.5.0 arm64

Minimal config

-- #######################################
-- ### USAGE: nvim --clean -u mini.lua ###
-- #######################################

local root = vim.fn.stdpath("run") .. "/nvim/diffview.nvim"
vim.fn.mkdir(root, "p")

-- set stdpaths to use root
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  {
    "sindrets/diffview.nvim",
    dependencies = { "nvim-tree/nvim-web-devicons" },
    config = function()
      require("diffview").setup({
        -- ##############################################################################
        -- ### ADD DIFFVIEW.NVIM CONFIG THAT IS _NECESSARY_ FOR REPRODUCING THE ISSUE ###
        -- ##############################################################################
      })
    end,
  },
  -- ##################################################################
  -- ### ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE ###
  -- ##################################################################
}
require("lazy").setup(plugins, { root = root .. "/plugins" })
require("lazy").sync({ show = false, wait = true })

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 ###
-- ############################################################################
sindrets commented 11 months ago

The problem is that you're using Neogit's custom integration layer over diffview. When you open a diffview through their interface they take control over updating the file data and file list. This does not happen if you instantiate diffview through the normal :DiffviewOpen command. Automatic updates were implemented a long time ago.

rstcruzo commented 11 months ago

You are right. This indeed works as expected when using:DiffviewOpen directly.