]> git.ipfire.org Git - thirdparty/git.git/commitdiff
add--interactive: detect bogus diffFilter output
authorJeff King <peff@peff.net>
Sat, 3 Mar 2018 05:58:49 +0000 (00:58 -0500)
committerJunio C Hamano <gitster@pobox.com>
Mon, 5 Mar 2018 20:49:45 +0000 (12:49 -0800)
It's important that the diff-filter only filter the
individual lines, and that there remain a one-to-one mapping
between the input and output lines. Otherwise, things like
hunk-splitting will behave quite unexpectedly (e.g., you
think you are splitting at one point, but it has a different
effect in the text patch we apply).

We can't detect all problematic cases, but we can at least
catch the obvious case where we don't even have the correct
number of lines.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-add--interactive.perl
t/t3701-add-interactive.sh

index 964c3a75420db4751cf11125b68b6904112632f1..ff02008abeceada0f2e1e423393b6119c4b731af 100755 (executable)
@@ -705,6 +705,14 @@ sub parse_diff {
        }
        my (@hunk) = { TEXT => [], DISPLAY => [], TYPE => 'header' };
 
+       if (@colored && @colored != @diff) {
+               print STDERR
+                 "fatal: mismatched output from interactive.diffFilter\n",
+                 "hint: Your filter must maintain a one-to-one correspondence\n",
+                 "hint: between its input and output lines.\n";
+               exit 1;
+       }
+
        for (my $i = 0; $i < @diff; $i++) {
                if ($diff[$i] =~ /^@@ /) {
                        push @hunk, { TEXT => [], DISPLAY => [],
index 64fe56c3d57e78116e0b945d88a10fc98a483261..9bb17f91b267224244ba1fe71ca06a33bbd2e677 100755 (executable)
@@ -404,6 +404,14 @@ test_expect_success TTY 'diffFilter filters diff' '
        grep foo:.*content output
 '
 
+test_expect_success TTY 'detect bogus diffFilter output' '
+       git reset --hard &&
+
+       echo content >test &&
+       test_config interactive.diffFilter "echo too-short" &&
+       printf y | test_must_fail test_terminal git add -p
+'
+
 test_expect_success 'patch-mode via -i prompts for files' '
        git reset --hard &&