sindrets / diffview.nvim

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

[Bug] File not reloaded after using ’restore_entry‘ #407

Closed ycycyyc closed 1 year ago

ycycyyc commented 1 year ago

Description

When I use DiffViewOpen to open the panel, and then want to roll back the modification through restore_entry, the corresponding file is not reloaded.

Expected behavior

Like the vim-fugitive plugin, pressing the X key can roll back the modification of the file and take effect immediately.

Actual behavior

File modifications are not rolled back.

Steps to reproduce

  1. create a file and initialize the git repository
    
    package main

import "fmt"

func main() { fmt.Println("hello") }

2. add a new line and save:

package main

import "fmt"

func main() { // new line here fmt.Println("hello") }

3. :DiffviewOpen
4. Restore this file by pressing the "X" key
5. :DiffviewClose
6.  It's strange that the newly added line was not rolled back.
7. If I save the file directly, there is a warning message:

WARNING: The file has been changed since reading it!!! Do you really want to write to it (y/n)?

 The extra line only disappears when I press ':e<cr>'. 

### Health check

<details>
<summary>Output of <code>:checkhealth diffview</code></summary>

#######################

PUT OUTPUT HERE

#######################


</details>

### Log info

<details>
<summary>Relevant info from <code>:DiffviewLog</code></summary>

############################

PUT LOG CONTENT HERE

############################


</details>

### Neovim version

```markdown
NVIM v0.9.2-dev-112+g65fc17b34
Build type: Release
LuaJIT 2.1.0-beta3

Operating system and version

Darwin 22.5.0 arm64

Minimal config

local lazypath = vim.fn.stdpath("data") .. "/lazy/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",
                "--branch=stable", -- latest stable release
                lazypath,
        })
end

vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
        "sindrets/diffview.nvim",
        opts = {},
})
sindrets commented 1 year ago

By default nvim doesn't automatically reload files that have been changed externally. You can make it do that with a simple auto command:

vim.api.nvim_create_autocmd({ "BufEnter", "CursorHold" }, {
  -- Automatically reload file if it's been changed externally.
  command = "silent! checktime %",
})
ycycyyc commented 1 year ago

Thank you for your reply!