sindrets / diffview.nvim

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

little mixup between saved and unsaved changes #300

Closed emmanueltouzery closed 1 year ago

emmanueltouzery commented 1 year ago

procedure to reproduce:

  1. make a change in a git repo
  2. save the file
  3. undo the change in memory, but DO NOT save the file
  4. run DiffviewOpen

what happens is that the file is shown as modified in diffview, but when you try to open it, there is no diff. neogit shows the changes as saved on disk and therefore is consistent saying there are changes.

I'm not sure what is better, showing what's on disk or the latest unsaved edits, but ideally the same determination would be made for both the list of files and file contents? I've been a little confused a couple of times by this current diffview behaviour.

sindrets commented 1 year ago

I think we're doing the right thing currently. The file panel lists changes the way they are seen from Git's perspective. I don't know how else you would expect it to work.

We don't know how (n)vim will diff the buffers before they are opened. And vim's diff-mode is not always in agreement with Git. It will depend on your 'diffopt'.

As far as I understand your post the other suggestion is to read in the contents from disk into a new buffer that would not be the same as the normal buffer you get when you :edit {file}. This is a bad idea because it would mean that the buffer would not be editable. (Or if we made it editable through some BufWriteCmd magic, it would be even worse, as you would then be able to have multiple, editable versions of the same file that are not in sync).

Proposed solution: just :write your buffer, or endure the fact that Git sees the file as modified when comparing the state of your working tree against its index.

emmanueltouzery commented 1 year ago

hmm. i understand you cannot show the files as they are on disk just like neogit does because it's possible to edit the buffer in diffview... i mean i understand the behavior, and you make good points... i'll close the issue then.