{"thread":{"id":"40298","subject":"Bug in default commit hook (improperly forbidding a single blank line at EOF)","startedAt":"2015-09-08T01:37:29Z","lastAt":"2015-09-08T05:03:02Z","messageCount":3,"participants":["Raymond Jennings","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"269587","messageId":"55EE3BD9.7020707@gmail.com","threadId":"40298","inReplyTo":null,"subject":"Bug in default commit hook (improperly forbidding a single blank line at EOF)","fromName":"Raymond Jennings","fromEmail":"shentino@gmail.com","sentAt":"2015-09-08T01:37:29Z","receivedAt":"2015-09-08T01:37:29Z","isPatch":false,"sender":{"key":"shentino@gmail.com","avatar":null},"body":"Please see https://bugs.gentoo.org/show_bug.cgi?id=559920 for further \ndetails.\n\nFiles *should* have a single blank line at the end, because a line \nshould always have a newline at the end.\n\nAdding a newline to the end of a file whose last line doesn't have one \nshould be legal...as long as you don't create empty lines at the end.\n"},{"id":"269589","messageId":"20150908045504.GA26331@sigill.intra.peff.net","threadId":"40298","inReplyTo":"55EE3BD9.7020707@gmail.com","subject":"Re: Bug in default commit hook (improperly forbidding a single blank line at EOF)","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2015-09-08T04:55:04Z","receivedAt":"2015-09-08T04:55:04Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Sep 07, 2015 at 06:37:29PM -0700, Raymond Jennings wrote:\n\n> Please see https://bugs.gentoo.org/show_bug.cgi?id=559920 for further\n> details.\n> \n> Files *should* have a single blank line at the end, because a line should\n> always have a newline at the end.\n\nI'm not sure I follow. Lines should have a newline at the end, but there\nis no need to start a _new_ blank line. So a file with zero bytes has no\nlines (and no newline).\n\nA file that contains a single line, like \"one\\n\", has each line end in a\nnewline, and the file ends in a newline. There is no blank line.\n\nA file like \"one\\n\\n\" has two lines: one with text, and a blank line at\nthe end.\n\nCan you clarify (preferably by showing a byte sequence of the file in\nquestion) what file you are feeding to the hook, what output you get,\nand what output you expect?\n\n> Adding a newline to the end of a file whose last line doesn't have one\n> should be legal...as long as you don't create empty lines at the end.\n\nIf you mean turning \"foo\" (a file with no newline!) into \"foo\\n\", I\nagree that is legal, and does not create an empty blank line at the end.\nBut I don't think the hook complains about that.\n\nE.g., we can create a sequence of file content:\n\n  git init\n\n  echo -n one >file\n  git add file\n  git commit -m 'no newline'\n\n  echo >>file\n  git add file\n  git commit -m 'complete line'\n\n  echo >>file\n  git add file\n  git commit -m 'add a blank line'\n\nand run \"log --check\", which runs the same code that the pre-commit hook\ndoes:\n\n  git log --check\n\nGit complains only about the final, which looks right to me. If you want\nto redefine git's idea of which whitespace is worth complaining about,\ntry:\n\n  git config core.whitespace -blank-at-eof\n\nSee the description of core.whitespace in \"git help config\" for the\ncomplete list.  You can also set it per-file using gitattributes. See\n\"git help attributes\", section \"Checking whitespace errors\".\n\n-Peff\n"},{"id":"269591","messageId":"55EE6C06.7010403@gmail.com","threadId":"40298","inReplyTo":"20150908045504.GA26331@sigill.intra.peff.net","subject":"Re: Bug in default commit hook (improperly forbidding a single blank line at EOF)","fromName":"Raymond Jennings","fromEmail":"shentino@gmail.com","sentAt":"2015-09-08T05:03:02Z","receivedAt":"2015-09-08T05:03:02Z","isPatch":false,"sender":{"key":"shentino@gmail.com","avatar":null},"body":"On 09/07/15 21:55, Jeff King wrote:\n> On Mon, Sep 07, 2015 at 06:37:29PM -0700, Raymond Jennings wrote:\n>\n>> Please see https://bugs.gentoo.org/show_bug.cgi?id=559920 for further\n>> details.\n>>\n>> Files *should* have a single blank line at the end, because a line should\n>> always have a newline at the end.\n> I'm not sure I follow. Lines should have a newline at the end, but there\n> is no need to start a _new_ blank line. So a file with zero bytes has no\n> lines (and no newline).\n>\n> A file that contains a single line, like \"one\\n\", has each line end in a\n> newline, and the file ends in a newline. There is no blank line.\n>\n> A file like \"one\\n\\n\" has two lines: one with text, and a blank line at\n> the end.\n>\n> Can you clarify (preferably by showing a byte sequence of the file in\n> question) what file you are feeding to the hook, what output you get,\n> and what output you expect?\n>\n>> Adding a newline to the end of a file whose last line doesn't have one\n>> should be legal...as long as you don't create empty lines at the end.\n> If you mean turning \"foo\" (a file with no newline!) into \"foo\\n\", I\n> agree that is legal, and does not create an empty blank line at the end.\n> But I don't think the hook complains about that.\nSorry, my mistake.  I just took a look at the file on console with \nmcedit, and it looks like gedit lied to me.\n\nI'll be contacting gedit's maintainers with this instead, sorry for the \nspam.\n> E.g., we can create a sequence of file content:\n>\n>    git init\n>\n>    echo -n one >file\n>    git add file\n>    git commit -m 'no newline'\n>\n>    echo >>file\n>    git add file\n>    git commit -m 'complete line'\n>\n>    echo >>file\n>    git add file\n>    git commit -m 'add a blank line'\n>\n> and run \"log --check\", which runs the same code that the pre-commit hook\n> does:\n>\n>    git log --check\n>\n> Git complains only about the final, which looks right to me. If you want\n> to redefine git's idea of which whitespace is worth complaining about,\n> try:\n>\n>    git config core.whitespace -blank-at-eof\n>\n> See the description of core.whitespace in \"git help config\" for the\n> complete list.  You can also set it per-file using gitattributes. See\n> \"git help attributes\", section \"Checking whitespace errors\".\n>\n> -Peff\n"}]}