Skip to content

Commit 5b5061e

Browse files
committed
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 <[email protected]>
1 parent b8d9c1a commit 5b5061e

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

diff.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,10 +1650,14 @@ static void builtin_checkdiff(const char *name_a, const char *name_b,
16501650
ecb.priv = &data;
16511651
xdi_diff(&mf1, &mf2, &xpp, &xecfg, &ecb);
16521652

1653-
if ((data.ws_rule & WS_TRAILING_SPACE) &&
1653+
if ((data.ws_rule & WS_BLANK_AT_EOF) &&
16541654
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);
16571661
data.status = 1; /* report errors */
16581662
}
16591663
}

t/t4015-diff-whitespace.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,10 @@ test_expect_success 'line numbers in --check output are correct' '
335335
336336
'
337337

338-
test_expect_success 'checkdiff detects trailing blank lines' '
338+
test_expect_success 'checkdiff detects new trailing blank lines (1)' '
339339
echo "foo();" >x &&
340340
echo "" >>x &&
341-
git diff --check | grep "ends with blank"
341+
git diff --check | grep "new blank line"
342342
'
343343

344344
test_expect_success 'checkdiff allows new blank lines' '

t/t4019-diff-wserror.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ test_expect_success 'trailing empty lines (1)' '
165165
166166
rm -f .gitattributes &&
167167
test_must_fail git diff --check >output &&
168-
grep "ends with blank lines." output &&
168+
grep "new blank line at" output &&
169169
grep "trailing whitespace" output
170170
171171
'

0 commit comments

Comments
 (0)