Skip to content

Commit 04c6e9e

Browse files
committed
diff --check: do not unconditionally complain about trailing empty lines
Recently "git diff --check" learned to detect new trailing blank lines just like "git apply --whitespace" does. However this check should not trigger unconditionally. This patch makes it honor the whitespace settings from core.whitespace and gitattributes. Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 7e4ad90 commit 04c6e9e

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

diff.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1631,7 +1631,8 @@ static void builtin_checkdiff(const char *name_a, const char *name_b,
16311631
ecb.priv = &data;
16321632
xdi_diff(&mf1, &mf2, &xpp, &xecfg, &ecb);
16331633

1634-
if (data.trailing_blanks_start) {
1634+
if ((data.ws_rule & WS_TRAILING_SPACE) &&
1635+
data.trailing_blanks_start) {
16351636
fprintf(o->file, "%s:%d: ends with blank lines.\n",
16361637
data.filename, data.trailing_blanks_start);
16371638
data.status = 1; /* report errors */

t/t4019-diff-wserror.sh

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ test_expect_success setup '
1313
echo " HT and SP indent" >>F &&
1414
echo "With trailing SP " >>F &&
1515
echo "Carriage ReturnQ" | tr Q "\015" >>F &&
16-
echo "No problem" >>F
16+
echo "No problem" >>F &&
17+
echo >>F
1718
1819
'
1920

@@ -160,4 +161,21 @@ test_expect_success 'with cr-at-eol (attribute)' '
160161
161162
'
162163

164+
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 &&
169+
grep "trailing whitespace" output
170+
171+
'
172+
173+
test_expect_success 'trailing empty lines (2)' '
174+
175+
echo "F -whitespace" >.gitattributes &&
176+
git diff --check >output &&
177+
! test -s output
178+
179+
'
180+
163181
test_done

0 commit comments

Comments
 (0)