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

[PATCH 5/9] apply --whitespace: warn blank but not necessarily empty lines at EOF

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

The whitespace error of adding blank lines at the end of file should trigger if you added a non-empty line at the end, if the contents of the line is full of whitespaces.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin-apply.c          |    6 ++++--
 t/t4124-apply-ws-rule.sh |   13 +++++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/builtin-apply.c b/builtin-apply.c
index 37d3bc0..6662cc4 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -1957,7 +1957,8 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
 			is_blank_context = 1;
 			break;
 		case ' ':
-			if (plen && patch[1] == '\n')
+			if (plen && (ws_rule & WS_BLANK_AT_EOF) &&
+			    ws_blank_line(patch + 1, plen, ws_rule))
 				is_blank_context = 1;
 		case '-':
 			memcpy(old, patch + 1, plen);
@@ -1985,7 +1986,8 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,
 				      (first == '+' ? 0 : LINE_COMMON));
 			new += added;
 			if (first == '+' &&
-			    added == 1 && new[-1] == '\n')
+			    (ws_rule & WS_BLANK_AT_EOF) &&
+			    ws_blank_line(patch + 1, plen, ws_rule))
 				added_blank_line = 1;
 			break;
 		case '@': case '\\':
diff --git a/t/t4124-apply-ws-rule.sh b/t/t4124-apply-ws-rule.sh
index 89b71e1..b3c3b2c 100755
--- a/t/t4124-apply-ws-rule.sh
+++ b/t/t4124-apply-ws-rule.sh
@@ -215,4 +215,17 @@ test_expect_success 'blank at EOF with --whitespace=error' '
 	grep "new blank line at EOF" error
 '
 
+test_expect_success 'blank but not empty at EOF' '
+	{ echo a; echo b; echo c; } >one &&
+	git add one &&
+	echo "   " >>one &&
+	cat one >expect &&
+	git diff -- one >patch &&
+
+	git checkout one &&
+	git apply --whitespace=warn patch 2>error &&
+	test_cmp expect one &&
+	grep "new blank line at EOF" error
+'
+
 test_done
-- 
1.6.4.2.313.g0425f
Previous: Junio C HamanoNext: Junio C Hamano
Message 8 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.