diff --check: do not get confused by new blank lines in the middle
The code remembered that the last diff output it saw was an empty line, and tried to reset that state whenever it sees a context line, a non-blank new line, or a new hunk. However, this codepath asks the underlying diff engine to feed diff without any context, and the "just saw an empty line" state was not reset if you added a new blank line in the last hunk of your patch, even if it is not the last line of the file. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Aug 20, 2008 at 11:47 UTC
c35539eb10b0ab2a180e523f03ff65dc061bd47e
2 files changed
+12
diff.c
+1
@@ -1627,6 +1627,7 @@ static void builtin_checkdiff(const char *name_a, const char *name_b,
1627
xdemitcb_t ecb;
1628
1629
memset(&xecfg, 0, sizeof(xecfg));
1630
+ xecfg.ctxlen = 1; /* at least one context line */
1631
xpp.flags = XDF_NEED_MINIMAL;
1632
ecb.outf = xdiff_outf;
1633
ecb.priv = &data;
t/t4015-diff-whitespace.sh
+11
@@ -341,4 +341,15 @@ test_expect_success 'checkdiff detects trailing blank lines' '
341
git diff --check | grep "ends with blank"
342
'
343
344
+test_expect_success 'checkdiff allows new blank lines' '
345
+ git checkout x &&
346
+ mv x y &&
347
+ (
348
+ echo "/* This is new */" &&
349
+ echo "" &&
350
+ cat y
351
+ ) >x &&
352
+ git diff --check
353
+'
354
+
355
test_done