gitsigns.nvim icon indicating copy to clipboard operation
gitsigns.nvim copied to clipboard

Extend `gitsigns.diffthis` for diff between index and HEAD

Open dasupradyumna opened this issue 2 years ago • 7 comments

Hello Lewis! Thank you for a such a simple yet convenient plugin!

Is your feature request related to a problem? Please describe.

I often use gitsigns.diffthis to compare current working tree to the index, and in my workflow, I usually stage my changes / hunks incrementally (parts of a feature, for example) as I work on a feature, before committing. As such, I use git diff --cached HEAD <file> for this purpose (I got used to this feature while using VS Code long back).

One thing I had checked was -

  • Open the index for a file using show function.
  • Tried to execute diffthis HEAD on the index file, but there was no change / no diff was opened.

Describe the solution you'd like

I am assuming there is a check which disallows diffthis to work on index buffers, so I was wondering if it is possible to modify diffthis function to work when the active buffer is the git index of a file.

Please let me know if this feature already is doable with the current plugin (probably something I missed), otherwise I do think this is a valuable addition to an already amazing plugin.

Additional context

I am hoping for something like this ; except the right side pane should be the git index of the file and not the file from the working tree.

featreq_gitsigns_diffthis

dasupradyumna avatar Dec 25 '22 07:12 dasupradyumna

Hey @lewis6991, I hope you're not busy. May I get a response? :)

dasupradyumna avatar Mar 09 '23 05:03 dasupradyumna

This isn't possible at the moment but I plan to add diffthis support for any Gitsigns buffer.

lewis6991 avatar Mar 09 '23 08:03 lewis6991

So after you add that support, I can open the index for a file using show and run diffthis HEAD on the index buffer to get a git-diff between index and HEAD. Did I understand you correctly?

dasupradyumna avatar Mar 09 '23 08:03 dasupradyumna

I was expecting this to be already possible from reading the docs:

diffthis({base}, {opts})                                 *gitsigns.diffthis()*
                Perform a |vimdiff| on the given file with {base} if it is
                given, or with the currently set base (index by default).

                If {base} is the index, then the opened buffer is editable and
                any written changes will update the index accordingly.

                Parameters:  
                    {base}   (string|nil): Revision to diff against. Defaults
                             to index.

                Examples:  
                  " Diff against the index
                  :Gitsigns diffthis

                  " Diff against the last commit
                  :Gitsigns diffthis ~1
 

Does this mean that base can not be anything? I tried diffthis main and nothing is shown. Indeed something like that will be very convenient, without having to change the entire base

danielo515 avatar Jun 13 '23 07:06 danielo515

diffthis only (currently) works on buffers of working copies.

lewis6991 avatar Jul 04 '23 10:07 lewis6991

diffthis only (currently) works on buffers of working copies.

I don't understand what I mean. I have a working copy, and I want to compare it against its main verson

danielo515 avatar Jul 06 '23 16:07 danielo515

You can already do that: :Gitsigns diffthis main

lewis6991 avatar Jul 06 '23 17:07 lewis6991