airblade / vim-gitgutter

A Vim plugin which shows git diff markers in the sign column and stages/previews/undoes hunks and partial hunks.
MIT License
8.37k stars 297 forks source link

Remove "file unknown in base" check #871

Closed nkouevda closed 1 year ago

nkouevda commented 1 year ago

Instead of checking whether this file exists in diff_base and returning early, we let git show fail, which still creates an empty from_file for the subsequent git diff to use.

This mostly reverts 2ee95686c5944f99b42dd04fec005b30497006de, but we keep the test case.

For posterity: this was originally meant to fix #869, but #870 accomplished that.

airblade commented 1 year ago

I didn't expect this to work, given what I wrote here about the error handler being triggered, but it does indeed work – nice! It turns out the output on stderr from the failing git-show comes before the diff output on stdout, so although the error callback is triggered it doesn't matter because the success callback is triggered afterwards.

My only concern is ;. It works fine for me on macOS. But according to this Windows command shell overview on Windows the semi-colon is used differently, to separate parameters. It looks like the correct character is &. However that would (probably?) need escaping, which is a pandora's box.

So I'd really like to merge this but I can't unless I can be sure it won't break on Windows.

airblade commented 1 year ago

However that would (probably?) need escaping...

Having said that, the existing && and || and > in the command aren't escaped so maybe it's ok. Do you have any way to try it on Windows?

nkouevda commented 1 year ago

Rebased and updated with a different approach: adding another || exit 0.

So instead of:

cd ... && (git show ... && git diff ... | grep ... || exit 0)

It would now be:

cd ... && (git show ... || exit 0) && (git diff ... | grep ... || exit 0)

Do you have any way to try it on Windows?

I do not.

airblade commented 1 year ago

Thanks, this is much neater than my original solution.