diff options
author | Johannes Schindelin <johannes.schindelin@gmx.de> | 2022-09-01 17:42:17 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-09-01 18:49:45 +0200 |
commit | b6633a005384a8c120d34a8a79a5a5fe9d8719d7 (patch) | |
tree | 58520b4f0da6962b6566501a3e21c1ea47f44d6b /t/t3701-add-interactive.sh | |
parent | Git 2.37.2 (diff) | |
download | git-b6633a005384a8c120d34a8a79a5a5fe9d8719d7.tar.xz git-b6633a005384a8c120d34a8a79a5a5fe9d8719d7.zip |
add -p: detect more mismatches between plain vs colored diffs
When parsing the colored version of a diff, the interactive `add`
command really relies on the colored version having the same number of
lines as the plain (uncolored) version. That is an invariant.
We already have code to verify correctly when the colored diff has less
lines than the plain diff. Modulo an off-by-one bug: If the last diff
line has no matching colored one, the code pretends to succeed, still.
To make matters worse, when we adjusted the test in 1e4ffc765db (t3701:
adjust difffilter test, 2020-01-14), we did not catch this because `add
-p` fails for a _different_ reason: it does not find any colored hunk
header that contains a parseable line range.
If we change the test case so that the line range _can_ be parsed, the
bug is exposed.
Let's address all of the above by
- fixing the off-by-one,
- adjusting the test case to allow `add -p` to parse the line range
- making the test case more stringent by verifying that the expected
error message is shown
Also adjust a misleading code comment about the now-fixed code.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t3701-add-interactive.sh')
-rwxr-xr-x | t/t3701-add-interactive.sh | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index b354fb39de..6b1137e7c9 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -761,9 +761,10 @@ test_expect_success 'detect bogus diffFilter output' ' git reset --hard && echo content >test && - test_config interactive.diffFilter "sed 1d" && + test_config interactive.diffFilter "sed 6d" && printf y >y && - force_color test_must_fail git add -p <y + force_color test_must_fail git add -p <y >output 2>&1 && + grep "mismatched output" output ' test_expect_success 'diff.algorithm is passed to `git diff-files`' ' |