{"thread":{"id":"25365","subject":"git diff --check always shows line 1 for blank at EOF for new files","startedAt":"2010-10-06T09:27:58Z","lastAt":"2010-10-10T10:46:27Z","messageCount":4,"participants":["Christoph Mallon","Jonathan Nieder","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"152754","messageId":"4CAC411E.3010204@gmx.de","threadId":"25365","inReplyTo":null,"subject":"git diff --check always shows line 1 for blank at EOF for new files","fromName":"Christoph Mallon","fromEmail":"christoph.mallon@gmx.de","sentAt":"2010-10-06T09:27:58Z","receivedAt":"2010-10-06T09:27:58Z","isPatch":false,"sender":{"key":"christoph.mallon@gmx.de","avatar":"https://avatars.githubusercontent.com/u/20772248?v=4"},"body":"Hi,\n\nthere seems to be a glitch in git diff --check for new files: If a new \nfile has trailing empty lines, then the error message always refers to \nline 1. This happens with git 1.7.3.1.\n\nHere is a simple test case:\n   git init test\n   cd test\n   printf 'a\\nb\\nc\\n\\n' > file\n   git add -AN\n   git diff --check\n\nThe last command will show \"file:1: new blank line at EOF.\".\n\nIt works fine, if the diff is not against /dev/null, e.g.:\n   git init test\n   cd test\n   printf 'a\\nb\\nc\\n' > file\n   git add -A\n   echo >> file\n   git diff --check\n\nThis correctly shows \"file:4: new blank line at EOF.\".\n"},{"id":"152862","messageId":"20101007093258.GA10941@burratino","threadId":"25365","inReplyTo":"4CAC411E.3010204@gmx.de","subject":"Re: git diff --check always shows line 1 for blank at EOF for new files","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2010-10-07T09:32:58Z","receivedAt":"2010-10-07T09:32:58Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi Christoph,\n\nChristoph Mallon wrote:\n\n>   git init test\n>   cd test\n>   printf 'a\\nb\\nc\\n\\n' > file\n>   git add -AN\n>   git diff --check\n> \n> The last command will show \"file:1: new blank line at EOF.\".\n> \n> It works fine, if the diff is not against /dev/null, e.g.:\n>   git init test\n>   cd test\n>   printf 'a\\nb\\nc\\n' > file\n>   git add -A\n>   echo >> file\n>   git diff --check\n> \n> This correctly shows \"file:4: new blank line at EOF.\".\n\nTry this:\n\n    git init test\n    cd test\n    printf 'a\\nb\\nc\\n' > file\n    git add -A\n    echo hello >> file\n    echo >> file\n    git diff --check\n\nAs you can see, it still returns line 4, which is the beginning of the\nhunk that adds the blank line.\n\nA change to make it print the line number of the blank line itself\ndoes not sound so bad, though.\n"},{"id":"152871","messageId":"4CADBE01.4000901@gmx.de","threadId":"25365","inReplyTo":"20101007093258.GA10941@burratino","subject":"Re: git diff --check always shows line 1 for blank at EOF for new files","fromName":"Christoph Mallon","fromEmail":"christoph.mallon@gmx.de","sentAt":"2010-10-07T12:33:05Z","receivedAt":"2010-10-07T12:33:05Z","isPatch":false,"sender":{"key":"christoph.mallon@gmx.de","avatar":"https://avatars.githubusercontent.com/u/20772248?v=4"},"body":"On 07.10.2010 11:32, Jonathan Nieder wrote:\n> Try this:\n>\n>      git init test\n>      cd test\n>      printf 'a\\nb\\nc\\n'>  file\n>      git add -A\n>      echo hello>>  file\n>      echo>>  file\n>      git diff --check\n>\n> As you can see, it still returns line 4, which is the beginning of the\n> hunk that adds the blank line.\n>\n> A change to make it print the line number of the blank line itself\n> does not sound so bad, though.\n\nYou're right. I think, the attached patch corrects the issue.\n\n\n>From 45eaa882dae35f2976e77cf0b6b06be78283c13f Mon Sep 17 00:00:00 2001\nFrom: Christoph Mallon <christoph.mallon@gmx.de>\nDate: Thu, 7 Oct 2010 14:22:02 +0200\nSubject: [PATCH] When git diff --check detects a blank line at EOF, show the line number of the empty line, not the line number of the beginning of the hunk.\n\n---\n diff.c |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex 71efa8e..452fdf4 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -2153,7 +2153,7 @@ static void builtin_checkdiff(const char *name_a, const char *name_b,\n \n \t\t\tecbdata.ws_rule = data.ws_rule;\n \t\t\tcheck_blank_at_eof(&mf1, &mf2, &ecbdata);\n-\t\t\tblank_at_eof = ecbdata.blank_at_eof_in_preimage;\n+\t\t\tblank_at_eof = ecbdata.blank_at_eof_in_postimage;\n \n \t\t\tif (blank_at_eof) {\n \t\t\t\tstatic char *err;\n-- \n1.7.3\n\n"},{"id":"153125","messageId":"7vpqvitjek.fsf@alter.siamese.dyndns.org","threadId":"25365","inReplyTo":"4CADBE01.4000901@gmx.de","subject":"Re: git diff --check always shows line 1 for blank at EOF for new files","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-10-10T10:46:27Z","receivedAt":"2010-10-10T10:46:27Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christoph Mallon <christoph.mallon@gmx.de> writes:\n\n> On 07.10.2010 11:32, Jonathan Nieder wrote:\n>> Try this:\n>>\n>>      git init test\n>>      cd test\n>>      printf 'a\\nb\\nc\\n'>  file\n>>      git add -A\n>>      echo hello>>  file\n>>      echo>>  file\n>>      git diff --check\n>>\n>> As you can see, it still returns line 4, which is the beginning of the\n>> hunk that adds the blank line.\n>>\n>> A change to make it print the line number of the blank line itself\n>> does not sound so bad, though.\n>\n> You're right. I think, the attached patch corrects the issue.\n>\n> From 45eaa882dae35f2976e77cf0b6b06be78283c13f Mon Sep 17 00:00:00 2001\n> From: Christoph Mallon <christoph.mallon@gmx.de>\n> Date: Thu, 7 Oct 2010 14:22:02 +0200\n> Subject: [PATCH] When git diff --check detects a blank line at EOF, show the line number of the empty line, not the line number of the beginning of the hunk.\n>\n> ---\n\nCould you check Documentation/SubmittingPatches, please?\n\n>  diff.c |    2 +-\n>  1 files changed, 1 insertions(+), 1 deletions(-)\n>\n> diff --git a/diff.c b/diff.c\n> index 71efa8e..452fdf4 100644\n> --- a/diff.c\n> +++ b/diff.c\n> @@ -2153,7 +2153,7 @@ static void builtin_checkdiff(const char *name_a, const char *name_b,\n>  \n>  \t\t\tecbdata.ws_rule = data.ws_rule;\n>  \t\t\tcheck_blank_at_eof(&mf1, &mf2, &ecbdata);\n> -\t\t\tblank_at_eof = ecbdata.blank_at_eof_in_preimage;\n> +\t\t\tblank_at_eof = ecbdata.blank_at_eof_in_postimage;\n\nHmm, I am confused.  Your subject line claims that for this patch:\n\n        diff --git a/Makefile b/Makefile\n        index 1f1ce04..90075e0 100644\n        --- a/Makefile\n        +++ b/Makefile\n        @@ -2375,3 +2375,8 @@ cover_db: coverage-report\n\n         cover_db_html: cover_db\n                cover -report html -outputdir cover_db_html cover_db\n        +\n        +new-rule:\n        +\techo here is a new rule\n        +\n        +\n\nthe code used to diagnose the error by showing the first line of the hunk\n(2375 taken from either -2375 or +2375, it does not matter much).  The\nclaim is that your patch makes it to show the first line in the trailing\nblank line block (the line after \"here is a new rule\", i.e. line 2381 in\nthe postimage).\n\nBut my reading of the code is that it is showing (incorrectly) the first\nline of the trailing blank line block in the preimage (in this case,\nbecause our codebase is clean, there is zero line of trailing blank line\nblock in the preimage, so it points at 2378.\n\nSo the patch looks correct, but the diagnosis / description seems wrong.\nSince I am asking you to refer to SubmittingPatches to give a better\nsubject line, patch description and a sign-off anyway,...\n\nThanks.\n"}]}