Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend gitsigns.diffthis for diff between index and HEAD #698

Open
dasupradyumna opened this issue Dec 25, 2022 · 7 comments
Open

Extend gitsigns.diffthis for diff between index and HEAD #698

dasupradyumna opened this issue Dec 25, 2022 · 7 comments
Labels
enhancement New feature or request

Comments

@dasupradyumna
Copy link

dasupradyumna commented Dec 25, 2022

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 dasupradyumna added the enhancement New feature or request label Dec 25, 2022
@dasupradyumna
Copy link
Author

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

@lewis6991
Copy link
Owner

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

@dasupradyumna
Copy link
Author

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?

@danielo515
Copy link

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

@lewis6991
Copy link
Owner

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

@danielo515
Copy link

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

@lewis6991
Copy link
Owner

You can already do that: :Gitsigns diffthis main

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants