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
Junio C Hamano <gitster@pobox.com>
Date
Feb 14, 2017, 20:40 UTC
Message-ID
<xmqqh93w8q0r.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20170214201104.GA26407@aepfle.de>
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
Previous: Olaf HeringNext: Olaf Hering
Message 2 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.