git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: missing handling of "No newline at end of file" in git am

From
Jeff King <peff@peff.net>
Date
Feb 14, 2017, 20:47 UTC
Message-ID
<20170214204748.wqnsqkbig4ktw5wf@sigill.intra.peff.net>
In-Reply-To
<20170214201104.GA26407@aepfle.de>
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.

Show 5 quoted lines
> 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
Previous: Eric Wong
Message 6 of 6 in “missing handling of "No newline at end of file" in git am”
  1. Olaf HeringFeb 14, 2017
  2. Junio C HamanoFeb 14, 2017
  3. Olaf HeringFeb 14, 2017
  4. Olaf HeringFeb 15, 2017
  5. Eric WongFeb 20, 2017
  6. Jeff KingFeb 14, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.