[PATCH stable] graft: don't drop the second parent on unsuccessful merge (issue3498)

Yuya Nishihara yuya at tcha.org
Sat Jun 16 03:45:45 CDT 2012


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1339833955 -32400
# Branch stable
# Node ID 85bddcd2699d6928b9395ee413a5e5097a9f4d6c
# Parent  d1a0ac9b6b8aa9b18edad7943cd001e6fe800f09
graft: don't drop the second parent on unsuccessful merge (issue3498)

This replicates the strategy of rebase, which postpones setparents and
duplicatecopies after checking the merge stats.

Without the second parent, resolve cannot redo merge.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2696,11 +2696,6 @@ def graft(ui, repo, *revs, **opts):
                                             ctx.p1().node())
                 finally:
                     repo.ui.setconfig('ui', 'forcemerge', '')
-                # drop the second merge parent
-                repo.setparents(current.node(), nullid)
-                repo.dirstate.write()
-                # fix up dirstate for copies and renames
-                cmdutil.duplicatecopies(repo, ctx.rev(), ctx.p1().rev())
                 # report any conflicts
                 if stats and stats[3] > 0:
                     # write out state for --continue
@@ -2712,6 +2707,12 @@ def graft(ui, repo, *revs, **opts):
             else:
                 cont = False
 
+            # drop the second merge parent
+            repo.setparents(current.node(), nullid)
+            repo.dirstate.write()
+            # fix up dirstate for copies and renames
+            cmdutil.duplicatecopies(repo, ctx.rev(), ctx.p1().rev())
+
             # commit
             source = ctx.extra().get('source')
             if not source:
diff --git a/tests/test-graft.t b/tests/test-graft.t
--- a/tests/test-graft.t
+++ b/tests/test-graft.t
@@ -275,3 +275,58 @@ Disallow grafting already grafted csets 
   $ hg graft tip
   skipping already grafted revision 12 (same origin 2)
   [255]
+
+Resolve conflicted graft
+  $ hg up -q 0
+  $ echo b > a
+  $ hg ci -m 8
+  created new head
+  $ echo a > a
+  $ hg ci -m 9
+  $ hg graft 1 --tool internal:fail
+  grafting revision 1
+  abort: unresolved conflicts, can't continue
+  (use hg resolve and hg graft --continue)
+  [255]
+  $ hg resolve --all
+  merging a
+  $ hg graft -c
+  grafting revision 1
+  $ hg export tip --git
+  # HG changeset patch
+  # User bar
+  # Date 0 0
+  # Node ID 64ecd9071ce83c6e62f538d8ce7709d53f32ebf7
+  # Parent  4bdb9a9d0b84ffee1d30f0dfc7744cade17aa19c
+  1
+  
+  diff --git a/a b/a
+  --- a/a
+  +++ b/a
+  @@ -1,1 +1,1 @@
+  -a
+  +b
+
+Resolve conflicted graft with rename
+  $ echo c > a
+  $ hg ci -m 10
+  $ hg graft 2 --tool internal:fail
+  grafting revision 2
+  abort: unresolved conflicts, can't continue
+  (use hg resolve and hg graft --continue)
+  [255]
+  $ hg resolve --all
+  merging a and b to b
+  $ hg graft -c
+  grafting revision 2
+  $ hg export tip --git
+  # HG changeset patch
+  # User test
+  # Date 0 0
+  # Node ID 2e80e1351d6ed50302fe1e05f8bd1d4d412b6e11
+  # Parent  e5a51ae854a8bbaaf25cc5c6a57ff46042dadbb4
+  2
+  
+  diff --git a/a b/b
+  rename from a
+  rename to b


More information about the Mercurial-devel mailing list