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

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

Open
HaleTom opened this issue Jul 21, 2023 · 13 comments
Open
Labels

Comments

@HaleTom
Copy link

HaleTom commented Jul 21, 2023

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
@OJFord OJFord added the bug label Jul 21, 2023
@HaleTom
Copy link
Author

HaleTom commented Jul 21, 2023

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
Copy link
Author

HaleTom commented Dec 6, 2023

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.

@felixlinker
Copy link

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

@scottchiefbaker
Copy link
Contributor

scottchiefbaker commented Dec 21, 2023

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.

@OJFord
Copy link
Member

OJFord commented Dec 21, 2023

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.

@scottchiefbaker
Copy link
Contributor

@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.

@felixlinker
Copy link

felixlinker commented Dec 21, 2023

@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.

@scottchiefbaker
Copy link
Contributor

scottchiefbaker commented Dec 21, 2023

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.

@HaleTom
Copy link
Author

HaleTom commented Dec 22, 2023

@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
Copy link
Author

HaleTom commented Feb 23, 2024

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

@scottchiefbaker
Copy link
Contributor

scottchiefbaker commented Feb 23, 2024

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
Copy link
Contributor

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.

@rcmoret
Copy link

rcmoret commented Jun 13, 2024

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.

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

No branches or pull requests

5 participants