{"thread":{"id":"14949","subject":"[PATCH] diff --check: do not unconditionally complain about trailing empty lines","startedAt":"2008-08-12T05:21:43Z","lastAt":"2008-08-12T05:21:43Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"86900","messageId":"7vabfist94.fsf@gitster.siamese.dyndns.org","threadId":"14949","inReplyTo":null,"subject":"[PATCH] diff --check: do not unconditionally complain about trailing empty lines","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-08-12T05:21:43Z","receivedAt":"2008-08-12T05:21:43Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Recently \"git diff --check\" learned to detect new trailing blank lines\njust like \"git apply --whitespace\" does.  However this check should not\ntrigger unconditionally.  This patch makes it honor the whitespace\nsettings from core.whitespace and gitattributes.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n diff.c                  |    3 ++-\n t/t4019-diff-wserror.sh |   21 ++++++++++++++++++++-\n 2 files changed, 22 insertions(+), 2 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 8746c60..6954f99 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -1631,7 +1631,8 @@ static void builtin_checkdiff(const char *name_a, const char *name_b,\n \t\tecb.priv = &data;\n \t\txdi_diff(&mf1, &mf2, &xpp, &xecfg, &ecb);\n \n-\t\tif (data.trailing_blanks_start) {\n+\t\tif ((data.ws_rule & WS_TRAILING_SPACE) &&\n+\t\t    data.trailing_blanks_start) {\n \t\t\tfprintf(o->file, \"%s:%d: ends with blank lines.\\n\",\n \t\t\t\tdata.filename, data.trailing_blanks_start);\n \t\t\tdata.status = 1; /* report errors */\ndiff --git a/t/t4019-diff-wserror.sh b/t/t4019-diff-wserror.sh\nindex 0d9cbb6..dfa11f6 100755\n--- a/t/t4019-diff-wserror.sh\n+++ b/t/t4019-diff-wserror.sh\n@@ -13,7 +13,8 @@ test_expect_success setup '\n \techo \" \tHT and SP indent\" >>F &&\n \techo \"With trailing SP \" >>F &&\n \techo \"Carriage ReturnQ\" | tr Q \"\\015\" >>F &&\n-\techo \"No problem\" >>F\n+\techo \"No problem\" >>F &&\n+\techo >>F\n \n '\n \n@@ -160,4 +161,21 @@ test_expect_success 'with cr-at-eol (attribute)' '\n \n '\n \n+test_expect_success 'trailing empty lines (1)' '\n+\n+\trm -f .gitattributes &&\n+\ttest_must_fail git diff --check >output &&\n+\tgrep \"ends with blank lines.\" output &&\n+\tgrep \"trailing whitespace\" output\n+\n+'\n+\n+test_expect_success 'trailing empty lines (2)' '\n+\n+\techo \"F -whitespace\" >.gitattributes &&\n+\tgit diff --check >output &&\n+\t! test -s output\n+\n+'\n+\n test_done\n"}]}