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

Improper handling of whitespace-only lines with markEmptyLines set to true #385

Open
MrMino opened this issue Oct 11, 2020 · 1 comment
Open

Comments

@MrMino
Copy link

MrMino commented Oct 11, 2020

The colors in the diff are either not showing up, or are completely wrong / misleading.

Repro steps:

git config --bool --global diff-so-fancy.markEmptyLines true

cd $(mktemp -d)
git init
git commit --allow-empty -m "Initial commit"
echo -en "----\n\n----\n" > file
git add file; git commit -m "Add file"

# Shows empty lines properly
git show

# But then shows two lines deleted here
echo -en "----\n    \n----\n" > file
git diff

git add file

# Then, after removing one space, it looks as if 3 spaces were removed from a line below a blank one
echo -en "----\n   \n----\n" > file
git diff

git add file

# Then, after removing all of the whitespace, it now looks as if a blank line was added,
# and the file now contains 2 blank lines, where in reality it contains 1
echo -en "----\n\n----\n" > file
git diff

This makes removing redundant whitespace from blank lines, common in older Python codebases, painful.

@x-yuri
Copy link

x-yuri commented Jan 28, 2022

Not sure if it's a different issue or not, but my case is:

a.sh

# rm -rf b
mkdir b
cd b
git init

# create a file with a space on a second line
echo 'a
 
b' > f
git add f
git commit -m a

# remove the space
echo 'a

b' > f
sed -Ei 's/ //' f
git diff
$ sh -eu a.sh

The way it looks like with diff-so-fancy:

Without:

markEmptyLines doesn't affect it.

I'd say it looks like a line was added, instead of a line was stripped of spaces.

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