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

🐛 --word-diff causes unpredictable behaviour #1957

Open
vxsl opened this issue Feb 11, 2025 · 3 comments
Open

🐛 --word-diff causes unpredictable behaviour #1957

vxsl opened this issue Feb 11, 2025 · 3 comments

Comments

@vxsl
Copy link

vxsl commented Feb 11, 2025

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:

Image

reliably correct output when --word-diff=<...> is not used:

Image

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 jonas/tig#1298 (comment)

@pablospe
Copy link
Contributor

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

?

@pablospe
Copy link
Contributor

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.

@vxsl
Copy link
Author

vxsl commented Feb 12, 2025

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:

2025-02-12.09-18-26.mp4

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

No branches or pull requests

2 participants