[Bug 6127] New: hg import fails to apply patches with trailing `\r` and `\ No newline at end of file`

mercurial-bugs at mercurial-scm.org mercurial-bugs at mercurial-scm.org
Tue Apr 30 14:48:00 EDT 2019


https://bz.mercurial-scm.org/show_bug.cgi?id=6127

            Bug ID: 6127
           Summary: hg import fails to apply patches with trailing `\r`
                    and `\ No newline at end of file`
           Product: Mercurial
           Version: 4.9
          Hardware: PC
                OS: Linux
            Status: UNCONFIRMED
          Severity: bug
          Priority: wish
         Component: Mercurial
          Assignee: bugzilla at mercurial-scm.org
          Reporter: steven at smacleod.ca
                CC: mercurial-devel at mercurial-scm.org

Patches with files that end with a \r character, but no \n, fail to be applied
by `hg import`. It is possible to directly `hg export` a commit which touches
this file, and have the output fail to be `hg import`ed.


$ hg version
> Mercurial Distributed SCM (version 4.9.1)
> (see https://mercurial-scm.org for more information)
> 
> Copyright (C) 2005-2019 Matt Mackall and others
> This is free software; see the source for copying conditions. There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Steps to reproduce:
$ hg init test

$ cd test

$ printf "hello\r" > test-file

$ hg add test-file

$ hg commit -m "file added"

$ hg rm test-file

$ hg commit -m "file removed"

$ hg export > ../removal.patch

$ cat ../removal.patch
> # HG changeset patch
> # User Steven MacLeod <steven at smacleod.ca>
> # Date 1556663458 14400
> #      Tue Apr 30 18:30:58 2019 -0400
> # Node ID 9674160f57ccb3c16e519ecbb5c0445e885ba253
> # Parent  5a913ad89c97c139d297cc4a0b5d1f62f07e71ea
> file removed
> 
> diff --git a/test-file b/test-file
> deleted file mode 100644
> --- a/test-file
> +++ /dev/null
> @@ -1,1 +0,0 @@
> -hello
> \ No newline at end of file

$ hg --config extensions.strip= strip -r .
> 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
> saved backup bundle to /test/.hg/strip-backup/5a913ad89c97-fc8decea-backup.hg

$ hg import ../removal.patch
> applying ../removed.patch
> patching file test-file
> Hunk #1 FAILED at 0
> 1 out of 1 hunks FAILED -- saving rejects to file test-file.rej
> abort: patch failed to apply

This `hg import` resulted in a failure to apply, where it should have been
possible.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the Mercurial-devel mailing list