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

[PATCH 7/9] diff --whitespace=warn/error: obey blank-at-eof

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 4, 2009, 10:55 UTC
Message-ID
<1252061718-11579-8-git-send-email-gitster@pobox.com>
In-Reply-To
<1252061718-11579-1-git-send-email-gitster@pobox.com>

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>
---
 diff.c                     |   10 +++++++---
 t/t4015-diff-whitespace.sh |    4 ++--
 t/t4019-diff-wserror.sh    |    2 +-
 3 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/diff.c b/diff.c
index 1eddd59..a693d18 100644
--- a/diff.c
+++ b/diff.c
@@ -1650,10 +1650,14 @@ static void builtin_checkdiff(const char *name_a, const char *name_b,
 		ecb.priv = &data;
 		xdi_diff(&mf1, &mf2, &xpp, &xecfg, &ecb);
 
-		if ((data.ws_rule & WS_TRAILING_SPACE) &&
+		if ((data.ws_rule & WS_BLANK_AT_EOF) &&
 		    data.trailing_blanks_start) {
-			fprintf(o->file, "%s:%d: ends with blank lines.\n",
-				data.filename, data.trailing_blanks_start);
+			static char *err;
+
+			if (!err)
+				err = whitespace_error_string(WS_BLANK_AT_EOF);
+			fprintf(o->file, "%s:%d: %s\n",
+				data.filename, data.trailing_blanks_start, err);
 			data.status = 1; /* report errors */
 		}
 	}
diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh
index b1cbd36..a5d4461 100755
--- a/t/t4015-diff-whitespace.sh
+++ b/t/t4015-diff-whitespace.sh
@@ -335,10 +335,10 @@ test_expect_success 'line numbers in --check output are correct' '
 
 '
 
-test_expect_success 'checkdiff detects trailing blank lines' '
+test_expect_success 'checkdiff detects new trailing blank lines (1)' '
 	echo "foo();" >x &&
 	echo "" >>x &&
-	git diff --check | grep "ends with blank"
+	git diff --check | grep "new blank line"
 '
 
 test_expect_success 'checkdiff allows new blank lines' '
diff --git a/t/t4019-diff-wserror.sh b/t/t4019-diff-wserror.sh
index 84a1fe3..1517fff 100755
--- a/t/t4019-diff-wserror.sh
+++ b/t/t4019-diff-wserror.sh
@@ -165,7 +165,7 @@ test_expect_success 'trailing empty lines (1)' '
 
 	rm -f .gitattributes &&
 	test_must_fail git diff --check >output &&
-	grep "ends with blank lines." output &&
+	grep "new blank line at" output &&
 	grep "trailing whitespace" output
 
 '
-- 
1.6.4.2.313.g0425f
Previous: Junio C HamanoNext: Junio C Hamano
Message 10 of 14 in “War on blank-at-eof”
  1. 0/9 War on blank-at-eofJunio C Hamano, Sep 4, 2009
  2. 1/9 apply --whitespace=fix: fix handling of blank lines at the eofJunio C Hamano, Sep 4, 2009
  3. 2/9 apply --whitespace=fix: detect new blank lines at eof correctlyJunio C Hamano, Sep 4, 2009
  4. Johannes SixtSep 4, 2009
  5. Junio C HamanoSep 4, 2009
  6. 3/9 apply.c: split check_whitespace() into twoJunio C Hamano, Sep 4, 2009
  7. 4/9 apply --whitespace=warn/error: diagnose blank at EOFJunio C Hamano, Sep 4, 2009
  8. 5/9 apply --whitespace: warn blank but not necessarily empty lines at EOFJunio C Hamano, Sep 4, 2009
  9. 6/9 diff.c: the builtin_diff() deals with only two-file comparisonJunio C Hamano, Sep 4, 2009
  10. 7/9 diff --whitespace=warn/error: obey blank-at-eofJunio C Hamano, Sep 4, 2009
  11. 8/9 diff --whitespace=warn/error: fix blank-at-eof checkJunio C Hamano, Sep 4, 2009
  12. 9/9 diff --color: color blank-at-eofJunio C Hamano, Sep 4, 2009
  13. Thell FowlerSep 5, 2009
  14. Junio C HamanoSep 6, 2009

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.