diff-so-fancy icon indicating copy to clipboard operation
diff-so-fancy copied to clipboard

Deleted files cause: "error: mismatched output from interactive.diffFilter"

Open HaleTom opened this issue 2 years ago • 15 comments
trafficstars

It seems that the mismatched output from interactive.diffFilter issue has struck again in an edge case.

I have a deleted, yet-to-be-staged file:

% git status --short
 D .cache/vim/.placeholder
 M .config/vim/load-plugins.vim
 M .config/vim/spell/en.utf-8.add
 M .config/vim/vimrc
%

If I try to add it, I get:

% git add --patch .cache/vim/.placeholder
error: mismatched output from interactive.diffFilter
hint: Your filter must maintain a one-to-one correspondence
hint: between its input and output lines.
%

Here's the original diff (obtained with diffFilter="cat"), and what dsf does with it:

% cat origdiff
diff --git a/.cache/vim/.placeholder b/.cache/vim/.placeholder
deleted file mode 100644
index e69de29b..00000000
% # Note 3 lines above in the original diff
% wc -l origdiff
3 origdiff
% Now for dsf's output:
% /usr/bin/diff-so-fancy --patch < origdiff


───────────────────────────────────────────────────────────────────────────────
deleted: .cache/vim/.placeholder
───────────────────────────────────────────────────────────────────────────────
% # Note 5 lines above, 2 empties are added at top
% /usr/bin/diff-so-fancy --patch < origdiff | wc -l
5
%

Note: if I git add the deleted file, a git reset --patch will cause the same error to occur.

% diff-so-fancy --version
Diff-so-fancy: https://github.com/so-fancy/diff-so-fancy
Version      : 1.4.4

HaleTom avatar Jul 21 '23 06:07 HaleTom

Workaround:

Add the following alias:

[alias]
  xdsf = !"git -c interactive.diffFilter='less --tabs=4 -RFX' \"$@\" # Don't use DSF"

Usage:

git xdsf add --patch

HaleTom avatar Jul 21 '23 12:07 HaleTom

Note that the issue here is the two blank lines being added by dsf.

The cause is likely the same as the one causing issue #473.

HaleTom avatar Dec 06 '23 04:12 HaleTom

Hi! I ran into the similar issue on a binary diff (.png file). Hope that helps!

felixlinker avatar Dec 21 '23 12:12 felixlinker

Is this still an active with v1.4.5? I am unable to recreate the issue with the steps you provided above.

bakers@basement(~/github/diff-so-fancy)
$ git rm README.md 
rm 'README.md'

bakers@basement(~/github/diff-so-fancy)
$ git status --short
D  README.md

bakers@basement(~/github/diff-so-fancy)
$ git add --patch README.md
No changes.

scottchiefbaker avatar Dec 21 '23 16:12 scottchiefbaker

I think the deletion in OP must have been unstaged (i.e. rm not git rm) @scottchiefbaker, otherwise git add -p will always skip it, won't hit dsf.

OJFord avatar Dec 21 '23 17:12 OJFord

@OJFord attempting the same thing with rm instead of git rm still "works" for me. Git handles it appropriately and passes it to d-s-f which displays the correct content.

I'm still confused how to recreate this.

scottchiefbaker avatar Dec 21 '23 17:12 scottchiefbaker

@scottchiefbaker I just reproduced on master with the following commands:

rm *.png
git add -p

Output is:

felixlinker diff-so-fancy % rm *.png
felixlinker diff-so-fancy % git add -p
error: mismatched output from interactive.diffFilter
hint: Your filter must maintain a one-to-one correspondence
hint: between its input and output lines.

felixlinker avatar Dec 21 '23 17:12 felixlinker

I suspect this has something to do with the fact that you're deleting a binary file. I don't get this error when I delete a tracked text file. Here is the raw git diff output for a text file that has been rm'd.

diff --git a/index.html b/index.html
deleted file mode 100644
index c3ef8be..0000000
--- a/index.html
+++ /dev/null

Here is the raw git diff output for a binary file that has been rm'd.

diff --git a/image001.png b/image001.png
deleted file mode 100644
index dae0097..0000000
Binary files a/image001.png and /dev/null differ

d-s-f parses removing this binary down to three lines:

─────────────────────────────────
deleted: image001.png (binary)
─────────────────────────────────

Not sure what --patch is expecting.

scottchiefbaker avatar Dec 21 '23 18:12 scottchiefbaker

@scottchiefbaker git is expecting the number of lines to always be the same.

The input is 4 lines, the transformed output is 3.

To fix: add a blank like above/below the output header to keep the transformed line count the same as the input.

It's the only easily implemented sanity check that the diff filter is not doing something obviously wrong.

HaleTom avatar Dec 22 '23 03:12 HaleTom

Related issues: #35 #305 #296 #437 #473

HaleTom avatar Feb 23 '24 05:02 HaleTom

I'm still unable to recreate this reliably so it's hard to test. If the issue really is the 4:3 line ratio I'd expect it to pop up all over d-s-f because we do that for every file change? Is this specifically related to binary files? Or does it apply to text files as well?

A "simple" fix would be adding

print "\n";

Right after line 335 which should get you the extra line you're asking for. Try that and let me know?

scottchiefbaker avatar Feb 23 '24 18:02 scottchiefbaker

Are you calling d-s-f with --patch enabled? That is supposed to fix ratios:

# `git add --patch` requires our output to match the number of lines from the
# input. So, when patch mode is active, we print out empty lines to pad our
# output to match any lines we've consumed.

If that's not working we may need to implement the above fix wrapped in a --patch filter.

scottchiefbaker avatar Feb 23 '24 18:02 scottchiefbaker

This is happening for me on longer text files. Just upgraded 1.4.3 -> 1.4.4. Also, I am passing the -p flag:

g --short
# ...
M  app/views/**/index.html.erb
D app/views/**/show.html.erb
# . ..
git add -p
fatal: mismatched output from interactive.diffFilter
hint: Your filter must maintain a one-to-one correspondence
hint: between its input and output lines.

rcmoret avatar Jun 13 '24 14:06 rcmoret