[PATCH STABLE] import: fix crash on --exact check of empty commit (issue5702)

Yuya Nishihara yuya at tcha.org
Tue Apr 24 12:43:55 UTC 2018


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1524572940 -32400
#      Tue Apr 24 21:29:00 2018 +0900
# Branch stable
# Node ID 3d8a3ba2d405904d00e9672131270cfe15cef06d
# Parent  58bbd14b0c621bc847d7ab4d4fbe8b6907b5afa6
import: fix crash on --exact check of empty commit (issue5702)

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1537,7 +1537,7 @@ def tryimportone(ui, repo, patchdata, pa
         # --exact with --no-commit is still useful in that it does merge
         # and branch bits
         ui.warn(_("warning: can't check exact import with --no-commit\n"))
-    elif opts.get('exact') and hex(n) != nodeid:
+    elif opts.get('exact') and (not n or hex(n) != nodeid):
         raise error.Abort(_('patch is damaged or loses information'))
     msg = _('applied to working directory')
     if n:
diff --git a/tests/test-import.t b/tests/test-import.t
--- a/tests/test-import.t
+++ b/tests/test-import.t
@@ -734,6 +734,42 @@ Test fuzziness (ambiguous patch location
   $ hg revert -a
   reverting a
 
+Test --exact failure
+
+  $ sed 's/^# Parent .*/# Parent '"`hg log -r. -T '{node}'`"'/' \
+  > < fuzzy-tip.patch > fuzzy-reparent.patch
+  $ hg import --config patch.fuzz=0 --exact fuzzy-reparent.patch
+  applying fuzzy-reparent.patch
+  patching file a
+  Hunk #1 FAILED at 0
+  1 out of 1 hunks FAILED -- saving rejects to file a.rej
+  abort: patch failed to apply
+  [255]
+  $ hg up -qC
+  $ hg import --config patch.fuzz=2 --exact fuzzy-reparent.patch
+  applying fuzzy-reparent.patch
+  patching file a
+  Hunk #1 succeeded at 2 with fuzz 1 (offset 0 lines).
+  transaction abort!
+  rollback completed
+  abort: patch is damaged or loses information
+  [255]
+  $ hg up -qC
+
+  $ grep '^#' fuzzy-tip.patch > empty.patch
+  $ cat <<'EOF' >> empty.patch
+  > change
+  > 
+  > diff -r bb90ef1daa38 -r 0e9b883378d4 a
+  > --- a/a	Thu Jan 01 00:00:00 1970 +0000
+  > --- b/a	Thu Jan 01 00:00:00 1970 +0000
+  > EOF
+  $ hg import --exact empty.patch
+  applying empty.patch
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  abort: patch is damaged or loses information
+  [255]
+  $ hg up -qC
 
 import with --no-commit should have written .hg/last-message.txt
 


More information about the Mercurial-devel mailing list