@matheusbsbs / matheus-bagliano / commits / 5b5061efd8
Fork 0

diff --whitespace=warn/error: obey blank-at-eof

The "diff --check" code used to conflate trailing-space whitespace error class with this, but now we have a proper separate error class, we should check it under blank-at-eof, not trailing-space. The whitespace error is not about _having_ blank lines at end, but about adding _new_ blank lines. To keep the message consistent with what is given by "git apply", call whitespace_error_string() to generate it, instead of using a hardcoded custom message. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Sep 3, 2009 at 22:30 UTC 5b5061efd88e1d113a4484369dfab654b43364de
3 files changed +10 -6
diff.c
+7 -3
@@ -1650,10 +1650,14 @@ static void builtin_checkdiff(const char *name_a, const char *name_b,
1650 ecb.priv = &data;
1651 xdi_diff(&mf1, &mf2, &xpp, &xecfg, &ecb);
1652
1653 - if ((data.ws_rule & WS_TRAILING_SPACE) &&
1653 + if ((data.ws_rule & WS_BLANK_AT_EOF) &&
1654 data.trailing_blanks_start) {
1655 - fprintf(o->file, "%s:%d: ends with blank lines.\n",
1656 - data.filename, data.trailing_blanks_start);
1655 + static char *err;
1656 +
1657 + if (!err)
1658 + err = whitespace_error_string(WS_BLANK_AT_EOF);
1659 + fprintf(o->file, "%s:%d: %s\n",
1660 + data.filename, data.trailing_blanks_start, err);
1661 data.status = 1; /* report errors */
1662 }
1663 }
t/t4015-diff-whitespace.sh
+2 -2
@@ -335,10 +335,10 @@ test_expect_success 'line numbers in --check output are correct' '
335
336 '
337
338 -test_expect_success 'checkdiff detects trailing blank lines' '
338 +test_expect_success 'checkdiff detects new trailing blank lines (1)' '
339 echo "foo();" >x &&
340 echo "" >>x &&
341 - git diff --check | grep "ends with blank"
341 + git diff --check | grep "new blank line"
342 '
343
344 test_expect_success 'checkdiff allows new blank lines' '
t/t4019-diff-wserror.sh
+1 -1
@@ -165,7 +165,7 @@ test_expect_success 'trailing empty lines (1)' '
165
166 rm -f .gitattributes &&
167 test_must_fail git diff --check >output &&
168 - grep "ends with blank lines." output &&
168 + grep "new blank line at" output &&
169 grep "trailing whitespace" output
170
171 '