diff --color-words breaks spacing
- From
Phil Hord <phil.hord@gmail.com>
- Date
- Jan 24, 2017, 17:39 UTC
- Message-ID
- <CABURp0ryBtLALEnzRdoeYeUUdrzBxiT3+yTvW6B=vpqMG3p1Rw@mail.gmail.com>
I noticed some weird spacing when comparing files with git diff --color-words. The space before a colored word disappears sometimes.
$ git --version git version 2.11.0.485.g4e59582ff
echo "FOO foo; foo = bar" > a echo "FOO foo = baz" > b git diff --color-words --no-index a b FOOfoo; foo = barbaz
There should be a space after FOO in the diff, even if git doesn't think "foo" and "foo;" are the same word.
If I remove the semicolon, it looks better, but in fact it only moves the error later. The missing space is now between the two "foo" words.
echo "FOO foo foo = bar" > a echo "FOO foo = baz" > b git diff --color-words --no-index a b FOO foofoo = barbaz
Here's the same with the color codes changed to text for purposes of this email:
echo "FOO foo; foo = bar" > a echo "FOO foo = baz" > b git diff --color-words --no-index a b | tr \\033 E FOOE[31mfoo;E[m foo = E[31mbarE[mE[32mbazE[m
echo "FOO foo foo = bar" > a echo "FOO foo = baz" > b git diff --color-words --no-index a b | tr \\033 E FOO fooE[31mfooE[m = E[31mbarE[mE[32mbazE[m