1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-06-18 18:59:38 +02:00

add--interactive: detect bogus diffFilter output

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>
This commit is contained in:
Jeff King 2018-03-03 00:58:49 -05:00 committed by Junio C Hamano
parent af3570ed6c
commit 42f7d45428
2 changed files with 16 additions and 0 deletions

View File

@ -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 => [],

View File

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