changeset 37815:32a75a8a5b0f stable

import: fix crash on --exact check of empty commit (issue5702)
author Yuya Nishihara <yuya@tcha.org>
date Tue, 24 Apr 2018 21:29:00 +0900
parents 265c122b69aa
children 33817e09c663 cf6605c2d135
files mercurial/cmdutil.py tests/test-import.t
diffstat 2 files changed, 37 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Tue Apr 24 08:20:15 2018 -0700
+++ b/mercurial/cmdutil.py	Tue Apr 24 21:29:00 2018 +0900
@@ -1537,7 +1537,7 @@
         # --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:
--- a/tests/test-import.t	Tue Apr 24 08:20:15 2018 -0700
+++ b/tests/test-import.t	Tue Apr 24 21:29:00 2018 +0900
@@ -734,6 +734,42 @@
   $ 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