sindrets / diffview.nvim

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

Can't unstage hunks with Gitsigns in the 'Staged changes' view #428

Closed d4hines closed 10 months ago

d4hines commented 11 months ago

Description

I'd like to unstage a selected hunk from the 'Staged changes' view. I've enabled Git signs for staged changes implemented in this PR so I can see the signs in a normal buffer, and calling :Gitsigns stage_hunk correctly unstages a staged hunk.

But when I run the same command in the 'Staged changes' view, it has no effect.

Is this something Diffview can support? Or do I need to make a custom function that intelligently maps the selected hunk in the diffview to the correct command? If the latter, any tips on how to do that?

Expected behavior

No response

Actual behavior

:Gitsigns stage_hunk has no effect.

Steps to reproduce

  1. Stage any change
  2. :DiffviewOpen
  3. Navigate to the staged hunk
  4. Run :Gitsigns stage_hunk

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

No response

Neovim version

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

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.9.2/share/nvim"

Run :checkhealth for more info

Operating system and version

Darwin 22.3.0 arm64

Minimal config

No response

sindrets commented 11 months ago

When you're viewing diffs for staged changes you have a representation of what the file looks like in the HEAD revision on the left, and a representation of what the file looks like in the Git index on the right. Note that these are representations, not real files. Gitsigns won't work in these buffers unless that's explicitly implemented as a feature (I think they do something like that for vim-fugitive buffers).

However, in this plugin we support staging by simply editing the index buffer. This is very powerful because it let's you edit the index the same way you edit any other text. When you :w the index buffer, the Git index will be updated.

See:

sindrets commented 10 months ago

Closing due to inactivity from OP.