transplant: do not rollback on patching error (issue3379) stable
authorPatrick Mezard <patrick@mezard.eu>
Sun, 22 Apr 2012 16:40:38 +0200
branchstable
changeset 16507 1f020021adfa
parent 16506 fc4e0fecf403
child 16508 475de53c08f4
transplant: do not rollback on patching error (issue3379) Otherwise, all transplanted revisions are gone and the failing one cannot be fixed (unless it is the first one). I do not know what is the expected behaviour with rollback, probably something pull-like. Non-conflicting cases should work as previously. But something like: $ hg transplant r1 r2 commiting r1 as c1 failing r2 $ hg transplant --continue committing r2 as c2 $ hg rollback would reset the repository to its state before the "transplant --continue" instead of the whole transplant session. To fix this we might need a way to open an existing journal file, not sure this is worth the pain.
hgext/transplant.py
tests/test-transplant.t
--- a/hgext/transplant.py	Sat Apr 21 21:40:25 2012 +0200
+++ b/hgext/transplant.py	Sun Apr 22 16:40:38 2012 +0200
@@ -20,6 +20,9 @@
 from mercurial import patch, revlog, scmutil, util, error, cmdutil
 from mercurial import revset, templatekw
 
+class TransplantError(error.Abort):
+    pass
+
 cmdtable = {}
 command = cmdutil.command(cmdtable)
 
@@ -171,11 +174,17 @@
                 del revmap[rev]
                 if patchfile or domerge:
                     try:
-                        n = self.applyone(repo, node,
-                                          source.changelog.read(node),
-                                          patchfile, merge=domerge,
-                                          log=opts.get('log'),
-                                          filter=opts.get('filter'))
+                        try:
+                            n = self.applyone(repo, node,
+                                              source.changelog.read(node),
+                                              patchfile, merge=domerge,
+                                              log=opts.get('log'),
+                                              filter=opts.get('filter'))
+                        except TransplantError:
+                            # Do not rollback, it is up to the user to
+                            # fix the merge or cancel everything
+                            tr.close()
+                            raise
                         if n and domerge:
                             self.ui.status(_('%s merged at %s\n') % (revstr,
                                       short(n)))
@@ -259,8 +268,8 @@
                 p2 = node
                 self.log(user, date, message, p1, p2, merge=merge)
                 self.ui.write(str(inst) + '\n')
-                raise util.Abort(_('fix up the merge and run '
-                                   'hg transplant --continue'))
+                raise TransplantError(_('fix up the merge and run '
+                                        'hg transplant --continue'))
         else:
             files = None
         if merge:
--- a/tests/test-transplant.t	Sat Apr 21 21:40:25 2012 +0200
+++ b/tests/test-transplant.t	Sun Apr 22 16:40:38 2012 +0200
@@ -212,7 +212,9 @@
   > baz
   > EOF
   $ echo toremove > toremove
+  $ echo baz > baz
   $ hg ci -Amfoo
+  adding baz
   adding foo
   adding toremove
   $ cat <<EOF > foo
@@ -226,17 +228,22 @@
   adding added
   removing toremove
   $ echo bar > bar
+  $ cat > baz <<EOF
+  > before baz
+  > baz
+  > after baz
+  > EOF
   $ hg ci -Ambar
   adding bar
   $ echo bar2 >> bar
   $ hg ci -mbar2
   $ hg up 0
-  2 files updated, 0 files merged, 2 files removed, 0 files unresolved
+  3 files updated, 0 files merged, 2 files removed, 0 files unresolved
   $ echo foobar > foo
   $ hg ci -mfoobar
   created new head
   $ hg transplant 1:3
-  applying a1e30dd1b8e7
+  applying 46ae92138f3c
   patching file foo
   Hunk #1 FAILED at 0
   1 out of 1 hunks FAILED -- saving rejects to file foo.rej
@@ -250,7 +257,7 @@
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ rm added
   $ hg transplant 1
-  applying a1e30dd1b8e7
+  applying 46ae92138f3c
   patching file foo
   Hunk #1 FAILED at 0
   1 out of 1 hunks FAILED -- saving rejects to file foo.rej
@@ -258,17 +265,41 @@
   abort: fix up the merge and run hg transplant --continue
   [255]
   $ hg transplant --continue
-  a1e30dd1b8e7 transplanted as f1563cf27039
+  46ae92138f3c transplanted as 9159dada197d
   $ hg transplant 1:3
-  skipping already applied revision 1:a1e30dd1b8e7
-  applying 1739ac5f6139
-  1739ac5f6139 transplanted to d649c221319f
-  applying 0282d5fbbe02
-  0282d5fbbe02 transplanted to 77418277ccb3
+  skipping already applied revision 1:46ae92138f3c
+  applying 9d6d6b5a8275
+  9d6d6b5a8275 transplanted to 2d17a10c922f
+  applying 1dab759070cf
+  1dab759070cf transplanted to e06a69927eb0
   $ hg locate
   added
   bar
+  baz
   foo
+
+test multiple revisions and --continue
+
+  $ hg up -qC 0
+  $ echo bazbaz > baz
+  $ hg ci -Am anotherbaz baz
+  created new head
+  $ hg transplant 1:3
+  applying 46ae92138f3c
+  46ae92138f3c transplanted to 1024233ea0ba
+  applying 9d6d6b5a8275
+  patching file baz
+  Hunk #1 FAILED at 0
+  1 out of 1 hunks FAILED -- saving rejects to file baz.rej
+  patch failed to apply
+  abort: fix up the merge and run hg transplant --continue
+  [255]
+  $ echo fixed > baz
+  $ hg transplant --continue
+  9d6d6b5a8275 transplanted as d80c49962290
+  applying 1dab759070cf
+  1dab759070cf transplanted to aa0ffe6bd5ae
+
   $ cd ..
 
 Issue1111: Test transplant --merge