🐛 --word-diff causes unpredictable behaviour
When git show or git diff is used with the --word-diff option, then piped into delta, the resulting output is often not highlighted correctly.
The issue seems to occur with any possible value of --word-diff. Oddly, it even occurs when --word-diff=plain is used, which should be equivalent to omitting the option, according to the documentation.
When the option is omitted, the output seems to always be highlighted correctly.
# in "delta" repo:
git show e3e92221 --word-diff=none | delta
# > ... produces highlighted output about 50% of the time
git show e3e92221 | delta
# > ... produces highlighted output 100% of the time
# to visually inspect multiple runs:
# while true; do git show e3e92221 | delta --paging=never; sleep 0.2; done
# while true; do git show e3e92221 --word-diff=none | delta --paging=never; sleep 0.2; done
intermittently incorrect output when --word-diff=<...> is used:
reliably correct output when --word-diff=<...> is not used:
There is obviously some sort of race condition here but unfortunately I do not have the time to investigate at the moment. Found this bug while trying to address https://github.com/jonas/tig/pull/1298#issuecomment-2454373903
I am not sure this is a delta problem. What happens if you put cat in between? For both commands:
git show e3e92221 --word-diff=none | cat | delta
git show e3e92221 | cat | delta
Is this what you want:
git show e3e92221 --word-diff=none --color=always
?
Btw, I haven't observed the unpredictable behavior you mentioned, I tested with your command:
while true; do git show e3e92221 --word-diff=none | delta --paging=never; sleep 0.2; done
And I get consistent results.
I am not sure this is a delta problem. What happens if you put cat in between?
Yes, piping to cat before delta does seem to resolve the issue.
In my opinion, there is still clearly a race condition in the pipe handling when the intermediate pipe is not in place. Regardless of whether this stems from a bug on the git side, or whether using cat in-between fixes it, the race could be handled better by delta so as to not have this behaviour.
Is this what you want:
git show e3e92221 --word-diff=none --color=always?
I'm not sure what you mean, sorry, can you clarify? Piping this to delta has the same inconsistent result.
Btw, I haven't observed the unpredictable behavior you mentioned
Thanks for testing! Since it is a race condition, I imagine this is either due to your computer being faster or slower than mine.
That being said, I'm observing this issue on delta 0.18.2 and git 2.47.0. What versions are you on?
Here's a video of the while loop on my machine:
https://github.com/user-attachments/assets/23a76533-26de-4431-ab63-786a5cb7850d