Skip to content

Commit

Permalink
diff --check: do not unconditionally complain about trailing empty lines
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Aug 12, 2008
1 parent 7e4ad90 commit 04c6e9e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -1631,7 +1631,8 @@ static void builtin_checkdiff(const char *name_a, const char *name_b,
ecb.priv = &data;
xdi_diff(&mf1, &mf2, &xpp, &xecfg, &ecb);

if (data.trailing_blanks_start) {
if ((data.ws_rule & WS_TRAILING_SPACE) &&
data.trailing_blanks_start) {
fprintf(o->file, "%s:%d: ends with blank lines.\n",
data.filename, data.trailing_blanks_start);
data.status = 1; /* report errors */
Expand Down
20 changes: 19 additions & 1 deletion t/t4019-diff-wserror.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ test_expect_success setup '
echo " HT and SP indent" >>F &&
echo "With trailing SP " >>F &&
echo "Carriage ReturnQ" | tr Q "\015" >>F &&
echo "No problem" >>F
echo "No problem" >>F &&
echo >>F
'

Expand Down Expand Up @@ -160,4 +161,21 @@ test_expect_success 'with cr-at-eol (attribute)' '
'

test_expect_success 'trailing empty lines (1)' '
rm -f .gitattributes &&
test_must_fail git diff --check >output &&
grep "ends with blank lines." output &&
grep "trailing whitespace" output
'

test_expect_success 'trailing empty lines (2)' '
echo "F -whitespace" >.gitattributes &&
git diff --check >output &&
! test -s output
'

test_done

0 comments on commit 04c6e9e

Please sign in to comment.