delta: 🐛 git add -p one-to-one correspondence errors

When I try to use git add -p, I get the following error:

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

I’m using delta with the following config:

$ delta --version
delta 0.4.3
$ delta --show-config
    commit-style                  = raw
    file-style                    = blue
    hunk-header-style             = syntax
    minus-style                   = syntax 52
    minus-non-emph-style          = syntax 52
    minus-emph-style              = syntax 88
    minus-empty-line-marker-style = normal 88
    zero-style                    = syntax
    plus-style                    = syntax black
    plus-non-emph-style           = syntax black
    plus-emph-style               = syntax 22
    plus-empty-line-marker-style  = normal 22
    whitespace-error-style        = reverse magenta
    24-bit-color                  = false
    file-added-label              = 'added:'
    file-modified-label           = ''
    file-removed-label            = 'removed:'
    file-renamed-label            = 'renamed:'
    hyperlinks                    = false
    inspect-raw-lines             = true
    keep-plus-minus-markers       = true
    line-numbers                  = true
    line-numbers-minus-style      = red
    line-numbers-zero-style       = brightgreen
    line-numbers-plus-style       = green
    line-numbers-left-style       = blue
    line-numbers-right-style      = blue
    line-numbers-left-format      = '{nm:^4}⋮'
    line-numbers-right-format     = '{np:^4}│'
    max-line-distance             = 0.6
    max-line-length               = 512
    navigate                      = false
    paging                        = auto
    side-by-side                  = false
    syntax-theme                  = Solarized (dark)
    width                         = 145
    tabs                          = 4
    word-diff-regex               = '\w+'

In my .gitconfig are the following relevant options:

[core]
        pager = delta
[delta]
        commit-style = raw
        file-style = blue
        hunk-header-style = syntax
        minus-style = syntax 52
        minus-emph-style = syntax 88
        zero-style = syntax normal
        plus-style = syntax black
        plus-emph-style = syntax 22
        keep-plus-minus-markers = true
        line-numbers = true
        line-numbers-minus-style = red
        line-numbers-zero-style = brightgreen
        line-numbers-plus-style = green
        whitespace-error-style = reverse magenta
        minus-empty-line-marker-style = normal 88
        plus-empty-line-marker-style = normal 22
[interactive]
        diffFilter = delta --color-only
[color]
        ui = true

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 31 (14 by maintainers)

Commits related to this issue

Most upvoted comments

I can confirm this regressed “recently”, I’ve bisected it down to e0eef7deccc7ca1c56d7c30894985c00898ef8a3

It took me a while to understand why this only happened very rarely, but looking at the commit itself it’s obvious in hindsight – that only happens when I modified some binary files in the repo…!

With that in hand, this can be reproduced as follow:

$ mkdir /tmp/test
$ cd /tmp/test
$ git init
$ cp /bin/sh a
$ echo some text > b
$ git add a b
$ git commit -m init
$ cp /bin/cp a
$ echo other test > b
$ git add -p

I’m sure there are better ways of getting git add -p’s raw output (using tee as a filter or something – EDIT: piping from git diff would apparently have worked…), but I got it from strace and it’s obvious enough from the output (it’s missing the “Binary files a… differ” line):

$ printf "\33[1mdiff --git a/a b/a\33[m\n\33[1mindex 7b65664a8972..82c76465611f 100755\33[m\nBinary files a/a and b/a differ\n\33[1mdiff --git a/b b/b\33[m\n\33[1mindex 7b57bd29ea8a..4d3b8c11a4a2 100644\33[m\n\33[1m--- a/b\33[m\n\33[1m+++ b/b\33[m\n\33[36m@@ -1 +1 @@\33[m\n\33[31m-some text\33[m\n\33[32m+\33[m\
diff --git a/a b/a3[m\n"
index 7b65664a8972..82c76465611f 100755
Binary files a/a and b/a differ
diff --git a/b b/b
index 7b57bd29ea8a..4d3b8c11a4a2 100644
--- a/b
+++ b/b
@@ -1 +1 @@
-some text
+other text
$ printf "\33[1mdiff --git a/a b/a\33[m\n\33[1mindex 7b65664a8972..82c76465611f 100755\33[m\nBinary files a/a and b/a differ\n\33[1mdiff --git a/b b/b\33[m\n\33[1mindex 7b57bd29ea8a..4d3b8c11a4a2 100644\33[m\n\33[1m--- a/b\33[m\n\33[1m+++ b/b\33[m\n\33[36m@@ -1 +1 @@\33[m\n\33[31m-some text\33[m\n\33[32m+\33[m\33[32mother text\33[m\n" | delta --color-only
diff --git a/a b/a
index 7b65664a8972..82c76465611f 100755
diff --git a/b b/b
index 7b57bd29ea8a..4d3b8c11a4a2 100644
--- a/b
+++ b/b
@@ -1 +1 @@
-some text
+other text

lunchbreak ended so I’ll leave the rest to whoever cares, I’ve downgraded for now 😃

I was using an old version of delta (0.8.2) and today upgraded to 0.15.1. I’ve been able to use git add -p just fine until now. All of a sudden I’m getting the above error. I removed the diffFilter config from [interactive] and it started working. Could this be a regression or is this still a known issue?

I looked for causes of this bug before, and

side-by-side = true
hunk-header-style = omit (only omit. I usually use this option except when git add -p)
file-style = (any option interestingly)

these options made it happened. @Minnozz 's config can work if you remove file-style one.

@imbrish just in case you want to continue your great work in this area, this bug seems like it might be in your area of expertise? But no worries at all if you don’t have time!

Seems like diff-so-fancy has managed to add support git add -p while keeping the formatting, see so-fancy/diff-so-fancy#390.

@lithammer Yes, and that is what Delta does, since 0.4.5 (Dec 2020). You can’t use side-by-side of course, since there is then no correspondence with the true git patch, but otherwise delta can be used with git add -p (% the bug that @imiric is pointing out):

[interactive]
    diffFilter = delta --color-only

@imiric Thanks, I can reproduce your bug – using box with file-style causes the one-to-one-correspondence error (unless you use that strange features workaround).

@kevinhwang91 could you confirm your delta version please?

delta --version delta 0.4.4

Thanks a lot @Kr1ss-XD and @ryuta69 for investigating here.

I think @Kr1ss-XD’s suggestion of using features to work around these issues is an excellent one for now, until we fix all the git app -p bugs.

@Kr1ss-XD I’m finding that I have to move both the file-style and hunk-header-style to a feature to make @Minnozz’s config work under git add -p.

So, to be completely explicit, here is a modification of @Minnozz’s config that I am finding works.

[delta]
    features = meta
    commit-style = raw
    # file-style = blue
    # hunk-header-style = syntax
    minus-style = syntax 52
    minus-emph-style = syntax 88
    zero-style = syntax normal
    plus-style = syntax black
    plus-emph-style = syntax 22
    keep-plus-minus-markers = true
    line-numbers = true
    line-numbers-minus-style = red
    line-numbers-zero-style = brightgreen
    line-numbers-plus-style = green
    whitespace-error-style = reverse magenta
    minus-empty-line-marker-style = normal 88
    plus-empty-line-marker-style = normal 22

[delta "meta"]
    file-style = blue
    hunk-header-style = syntax

[delta "diff-filter"]
    # Can leave empty, but optionally put diffFilter-only settings here

[interactive]
    # I've added a --features override here to be explicit that we don't want diffFilter to use the
    # features defined in the main [delta] section.
    diffFilter = delta --color-only --features=diff-filter

@Kr1ss-XD Oh! Same as hunk-header-style, and side-by-side. Moving them to features, git add -p works while usual git diff work as those options enabled!

I think

src/options/set.rs
    if config::user_supplied_option("color-only", arg_matches) {
        builtin_features.remove("side-by-side");
    }

this is the reason why side-by-side works. I look for file-style, hunk-header-style’s reasons.

I think I found something :

If I put the file-style option in a feature category, git add -p works with the @Minnozz configuration !

[delta]
    features = files
    <... other options ...>
[delta "files"]
    file-style = blue

cc @dandavison

EDIT The same applies to hunk-header-style = omit.