{"thread":{"id":"45141","subject":"missing handling of \"No newline at end of file\" in git am","startedAt":"2017-02-14T20:11:12Z","lastAt":"2017-02-20T08:06:47Z","messageCount":6,"participants":["Olaf Hering","Junio C Hamano","Jeff King","Eric Wong"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"311570","messageId":"20170214201104.GA26407@aepfle.de","threadId":"45141","inReplyTo":null,"subject":"missing handling of \"No newline at end of file\" in git am","fromName":"Olaf Hering","fromEmail":"olaf@aepfle.de","sentAt":"2017-02-14T20:11:04Z","receivedAt":"2017-02-14T20:11:12Z","isPatch":false,"sender":{"key":"olaf@aepfle.de","avatar":"https://avatars.githubusercontent.com/u/942324?v=4"},"body":"How is git send-email and git am supposed to handle a text file which\nlacks a newline at the very end? This is about git 2.11.0.\n\nRight now the patch in an email generated with 'git send-email' ends\nwith '\\ No newline at end of file', which 'git am' can not handle.  To\nme it looks like whatever variant of \"diff\" is used does the right thing\nand indicates the lack of newline. Just the used variant of \"patch\" does\nnot deal with it.\n\n\nOlaf\n"},{"id":"311575","messageId":"xmqqh93w8q0r.fsf@gitster.mtv.corp.google.com","threadId":"45141","inReplyTo":"20170214201104.GA26407@aepfle.de","subject":"Re: missing handling of \"No newline at end of file\" in git am","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-02-14T20:40:36Z","receivedAt":"2017-02-14T20:40:43Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Olaf Hering <olaf@aepfle.de> writes:\n\n> How is git send-email and git am supposed to handle a text file which\n> lacks a newline at the very end? This is about git 2.11.0.\n\nI think this has always worked, though.\n\n    $ cd /var/tmp/x\n    $ git init am-incomplete-line\n    $ cd am-incomplete-line/\n    $ echo one line >file\n    $ git add file\n    $ git commit -a -m initial\n    [master (root-commit) 27b4668] initial\n     1 file changed, 1 insertion(+)\n     create mode 100644 file\n    $ echo -n an incomplete line >>file\n    $ git diff file\n    diff --git a/file b/file\n    index e3c0674..f2ec9f0 100644\n    --- a/file\n    +++ b/file\n    @@ -1 +1,2 @@\n     one line\n    +an incomplete line\n    \\ No newline at end of file\n    $ git commit -a -m 'incomplete second'\n    [master 57075ab] incomplete second\n     1 file changed, 1 insertion(+)\n    $ git format-patch -1\n    0001-incomplete-second.txt\n    $ cat 0001-incomplete-second.txt\n    From 57075ab402e2d3714ebc9e2e9d4efd8dbfd74d5a Mon Sep 17 00:00:00 2001\n    From: Junio C Hamano <gitster@pobox.com>\n    Date: Tue, 14 Feb 2017 12:35:50 -0800\n    Subject: [PATCH] incomplete second\n\n    ---\n     file | 1 +\n     1 file changed, 1 insertion(+)\n\n    diff --git a/file b/file\n    index e3c0674..f2ec9f0 100644\n    --- a/file\n    +++ b/file\n    @@ -1 +1,2 @@\n     one line\n    +an incomplete line\n    \\ No newline at end of file\n    -- \n    2.12.0-rc1-235-g2fb706ef99\n    $ git checkout HEAD^\n    $ git am ./0001-incomplete-second.txt\n    Applying: incomplete second\n    $ git diff master\n    $ exit\n\n"},{"id":"311576","messageId":"20170214204748.wqnsqkbig4ktw5wf@sigill.intra.peff.net","threadId":"45141","inReplyTo":"20170214201104.GA26407@aepfle.de","subject":"Re: missing handling of \"No newline at end of file\" in git am","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-02-14T20:47:49Z","receivedAt":"2017-02-14T20:48:01Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Feb 14, 2017 at 09:11:04PM +0100, Olaf Hering wrote:\n\n> How is git send-email and git am supposed to handle a text file which\n> lacks a newline at the very end? This is about git 2.11.0.\n\nThat workflow should handle this case, and the resulting applied patch\nshould not have a newline.\n\n> Right now the patch in an email generated with 'git send-email' ends\n> with '\\ No newline at end of file', which 'git am' can not handle.  To\n> me it looks like whatever variant of \"diff\" is used does the right thing\n> and indicates the lack of newline. Just the used variant of \"patch\" does\n> not deal with it.\n\nI can't reproduce here:\n\n  # new repo with nothing in it (the base commit is to have something to\n  # reset back to)\n  git init\n  git commit --allow-empty -m base\n\n  # our file with no trailing newline\n  printf foo >file\n  git add file\n  git commit -m no-newline\n\n  # now make a patch email; it should have the \"\\ No newline\" bit at the\n  # end.\n  git format-patch -1\n  cat 0001-no-newline.patch\n\n  # and now reset back and try to apply it\n  git reset --hard HEAD^\n  git am 0001-no-newline.patch\n\n  # double check that it has no newline\n  xxd <file\n\nI'm using format-patch instead of send-email, but that is the underlying\ncommand that send-email is using. Is it possible that your patch is\ngetting munged during email transit in a way that destroy the \"No\nnewline\" message?\n\n-Peff\n"},{"id":"311577","messageId":"20170214215103.7d5e5f4c@probook.ubnt.lan","threadId":"45141","inReplyTo":"xmqqh93w8q0r.fsf@gitster.mtv.corp.google.com","subject":"Re: missing handling of \"No newline at end of file\" in git am","fromName":"Olaf Hering","fromEmail":"olaf@aepfle.de","sentAt":"2017-02-14T20:51:03Z","receivedAt":"2017-02-14T20:54:21Z","isPatch":false,"sender":{"key":"olaf@aepfle.de","avatar":"https://avatars.githubusercontent.com/u/942324?v=4"},"body":"Am Tue, 14 Feb 2017 12:40:36 -0800\nschrieb Junio C Hamano <gitster@pobox.com>:\n\n> Olaf Hering <olaf@aepfle.de> writes:\n> \n> > How is git send-email and git am supposed to handle a text file\n> > which lacks a newline at the very end? This is about git 2.11.0.  \n> \n> I think this has always worked, though.\n\nFor me it complains in line 721, which is the problematic one.\nI try to apply from mutt via (cd /some/dir && git am), but that\nprobably does not make a difference.\n\nHow would I debug it?\n\nOlaf\n"},{"id":"311642","messageId":"20170215114430.GD16249@aepfle.de","threadId":"45141","inReplyTo":"20170214215103.7d5e5f4c@probook.ubnt.lan","subject":"Re: missing handling of \"No newline at end of file\" in git am","fromName":"Olaf Hering","fromEmail":"olaf@aepfle.de","sentAt":"2017-02-15T11:44:30Z","receivedAt":"2017-02-15T11:44:52Z","isPatch":false,"sender":{"key":"olaf@aepfle.de","avatar":"https://avatars.githubusercontent.com/u/942324?v=4"},"body":"On Tue, Feb 14, Olaf Hering wrote:\n\n> How would I debug it?\n\nOne line is supposed to be longer than 998 chars, but something along\nthe way truncated it and corrupted the patch. No idea why the error\ntoday is different from the error yesterday.\n'git pull' has to be used in this case.\n\nOlaf\n"},{"id":"312127","messageId":"20170220080639.GA3802@starla","threadId":"45141","inReplyTo":"20170215114430.GD16249@aepfle.de","subject":"Re: missing handling of \"No newline at end of file\" in git am","fromName":"Eric Wong","fromEmail":"e@80x24.org","sentAt":"2017-02-20T08:06:39Z","receivedAt":"2017-02-20T08:06:47Z","isPatch":false,"sender":{"key":"e@80x24.org","avatar":null},"body":"Olaf Hering <olaf@aepfle.de> wrote:\n> On Tue, Feb 14, Olaf Hering wrote:\n> \n> > How would I debug it?\n> \n> One line is supposed to be longer than 998 chars, but something along\n> the way truncated it and corrupted the patch.\n\n998 sounds like the SMTP limit.\n\nPerhaps git format-patch should emit binary diffs in that case?\nI doubt any human would bother reading excessively long lines as\ntext...\n"}]}