git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] diff --check: do not unconditionally complain about trailing empty lines

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 12, 2008, 05:21 UTC
Message-ID
<7vabfist94.fsf@gitster.siamese.dyndns.org>

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>
---
 diff.c                  |    3 ++-
 t/t4019-diff-wserror.sh |   21 ++++++++++++++++++++-
 2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/diff.c b/diff.c
index 8746c60..6954f99 100644
--- a/diff.c
+++ b/diff.c
@@ -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 */
diff --git a/t/t4019-diff-wserror.sh b/t/t4019-diff-wserror.sh
index 0d9cbb6..dfa11f6 100755
--- a/t/t4019-diff-wserror.sh
+++ b/t/t4019-diff-wserror.sh
@@ -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
 
 '
 
@@ -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
Message 1 of 1 in “diff --check: do not unconditionally complain about trailing empty lines”
  1. diff --check: do not unconditionally complain about trailing empty linesJunio C Hamano, Aug 12, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.