git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* missing handling of "No newline at end of file" in git am
@ 2017-02-14 20:11 Olaf Hering
  2017-02-14 20:40 ` Junio C Hamano
  2017-02-14 20:47 ` Jeff King
  0 siblings, 2 replies; 6+ messages in thread
From: Olaf Hering @ 2017-02-14 20:11 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 441 bytes --]

How is git send-email and git am supposed to handle a text file which
lacks a newline at the very end? This is about git 2.11.0.

Right now the patch in an email generated with 'git send-email' ends
with '\ No newline at end of file', which 'git am' can not handle.  To
me it looks like whatever variant of "diff" is used does the right thing
and indicates the lack of newline. Just the used variant of "patch" does
not deal with it.


Olaf

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: missing handling of "No newline at end of file" in git am
  2017-02-14 20:11 missing handling of "No newline at end of file" in git am Olaf Hering
@ 2017-02-14 20:40 ` Junio C Hamano
  2017-02-14 20:51   ` Olaf Hering
  2017-02-14 20:47 ` Jeff King
  1 sibling, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2017-02-14 20:40 UTC (permalink / raw)
  To: Olaf Hering; +Cc: git

Olaf Hering <olaf@aepfle.de> writes:

> How is git send-email and git am supposed to handle a text file which
> lacks a newline at the very end? This is about git 2.11.0.

I think this has always worked, though.

    $ cd /var/tmp/x
    $ git init am-incomplete-line
    $ cd am-incomplete-line/
    $ echo one line >file
    $ git add file
    $ git commit -a -m initial
    [master (root-commit) 27b4668] initial
     1 file changed, 1 insertion(+)
     create mode 100644 file
    $ echo -n an incomplete line >>file
    $ git diff file
    diff --git a/file b/file
    index e3c0674..f2ec9f0 100644
    --- a/file
    +++ b/file
    @@ -1 +1,2 @@
     one line
    +an incomplete line
    \ No newline at end of file
    $ git commit -a -m 'incomplete second'
    [master 57075ab] incomplete second
     1 file changed, 1 insertion(+)
    $ git format-patch -1
    0001-incomplete-second.txt
    $ cat 0001-incomplete-second.txt
    From 57075ab402e2d3714ebc9e2e9d4efd8dbfd74d5a Mon Sep 17 00:00:00 2001
    From: Junio C Hamano <gitster@pobox.com>
    Date: Tue, 14 Feb 2017 12:35:50 -0800
    Subject: [PATCH] incomplete second

    ---
     file | 1 +
     1 file changed, 1 insertion(+)

    diff --git a/file b/file
    index e3c0674..f2ec9f0 100644
    --- a/file
    +++ b/file
    @@ -1 +1,2 @@
     one line
    +an incomplete line
    \ No newline at end of file
    -- 
    2.12.0-rc1-235-g2fb706ef99
    $ git checkout HEAD^
    $ git am ./0001-incomplete-second.txt
    Applying: incomplete second
    $ git diff master
    $ exit


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: missing handling of "No newline at end of file" in git am
  2017-02-14 20:11 missing handling of "No newline at end of file" in git am Olaf Hering
  2017-02-14 20:40 ` Junio C Hamano
@ 2017-02-14 20:47 ` Jeff King
  1 sibling, 0 replies; 6+ messages in thread
From: Jeff King @ 2017-02-14 20:47 UTC (permalink / raw)
  To: Olaf Hering; +Cc: git

On Tue, Feb 14, 2017 at 09:11:04PM +0100, Olaf Hering wrote:

> How is git send-email and git am supposed to handle a text file which
> lacks a newline at the very end? This is about git 2.11.0.

That workflow should handle this case, and the resulting applied patch
should not have a newline.

> Right now the patch in an email generated with 'git send-email' ends
> with '\ No newline at end of file', which 'git am' can not handle.  To
> me it looks like whatever variant of "diff" is used does the right thing
> and indicates the lack of newline. Just the used variant of "patch" does
> not deal with it.

I can't reproduce here:

  # new repo with nothing in it (the base commit is to have something to
  # reset back to)
  git init
  git commit --allow-empty -m base

  # our file with no trailing newline
  printf foo >file
  git add file
  git commit -m no-newline

  # now make a patch email; it should have the "\ No newline" bit at the
  # end.
  git format-patch -1
  cat 0001-no-newline.patch

  # and now reset back and try to apply it
  git reset --hard HEAD^
  git am 0001-no-newline.patch

  # double check that it has no newline
  xxd <file

I'm using format-patch instead of send-email, but that is the underlying
command that send-email is using. Is it possible that your patch is
getting munged during email transit in a way that destroy the "No
newline" message?

-Peff

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: missing handling of "No newline at end of file" in git am
  2017-02-14 20:40 ` Junio C Hamano
@ 2017-02-14 20:51   ` Olaf Hering
  2017-02-15 11:44     ` Olaf Hering
  0 siblings, 1 reply; 6+ messages in thread
From: Olaf Hering @ 2017-02-14 20:51 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Am Tue, 14 Feb 2017 12:40:36 -0800
schrieb Junio C Hamano <gitster@pobox.com>:

> Olaf Hering <olaf@aepfle.de> writes:
> 
> > How is git send-email and git am supposed to handle a text file
> > which lacks a newline at the very end? This is about git 2.11.0.  
> 
> I think this has always worked, though.

For me it complains in line 721, which is the problematic one.
I try to apply from mutt via (cd /some/dir && git am), but that
probably does not make a difference.

How would I debug it?

Olaf

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: missing handling of "No newline at end of file" in git am
  2017-02-14 20:51   ` Olaf Hering
@ 2017-02-15 11:44     ` Olaf Hering
  2017-02-20  8:06       ` Eric Wong
  0 siblings, 1 reply; 6+ messages in thread
From: Olaf Hering @ 2017-02-15 11:44 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 290 bytes --]

On Tue, Feb 14, Olaf Hering wrote:

> How would I debug it?

One line is supposed to be longer than 998 chars, but something along
the way truncated it and corrupted the patch. No idea why the error
today is different from the error yesterday.
'git pull' has to be used in this case.

Olaf

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: missing handling of "No newline at end of file" in git am
  2017-02-15 11:44     ` Olaf Hering
@ 2017-02-20  8:06       ` Eric Wong
  0 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2017-02-20  8:06 UTC (permalink / raw)
  To: Olaf Hering; +Cc: Junio C Hamano, git

Olaf Hering <olaf@aepfle.de> wrote:
> On Tue, Feb 14, Olaf Hering wrote:
> 
> > How would I debug it?
> 
> One line is supposed to be longer than 998 chars, but something along
> the way truncated it and corrupted the patch.

998 sounds like the SMTP limit.

Perhaps git format-patch should emit binary diffs in that case?
I doubt any human would bother reading excessively long lines as
text...

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-02-20  8:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-14 20:11 missing handling of "No newline at end of file" in git am Olaf Hering
2017-02-14 20:40 ` Junio C Hamano
2017-02-14 20:51   ` Olaf Hering
2017-02-15 11:44     ` Olaf Hering
2017-02-20  8:06       ` Eric Wong
2017-02-14 20:47 ` Jeff King

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).