touch: make sure merge commits include files from p1 and p2
authorAnton Shestakov <av6@dwimlabs.net>
Wed, 10 Jul 2019 18:16:38 +0800
changeset 4721 b69497b23d31
parent 4720 d48b689ea78a
child 4722 7839720c7c75
touch: make sure merge commits include files from p1 and p2 Otherwise touching a merge commit makes it lose all changes. This fix populates `updates` argument of rewriteutil.rewrite() with parent changesets. That argument is normally used for folding multiple changesets, but in this case it's simply used to include files from p1 and p2. Usually, rewrite() works fine using ctx.files(), but that function can return an empty list when ctx is a merge commit.
hgext3rd/evolve/cmdrewrite.py
tests/test-touch.t
--- a/hgext3rd/evolve/cmdrewrite.py	Tue Jul 09 10:56:42 2019 -0700
+++ b/hgext3rd/evolve/cmdrewrite.py	Wed Jul 10 18:16:38 2019 +0800
@@ -1397,8 +1397,11 @@
                 else:
                     duplicate = True
 
+        updates = []
+        if len(ctx.parents()) > 1:
+            updates = ctx.parents()
         extradict = {'extra': extra}
-        new, unusedvariable = rewriteutil.rewrite(repo, ctx, [], ctx,
+        new, unusedvariable = rewriteutil.rewrite(repo, ctx, updates, ctx,
                                                   [p1, p2],
                                                   commitopts=extradict)
         # store touched version to help potential children
--- a/tests/test-touch.t	Tue Jul 09 10:56:42 2019 -0700
+++ b/tests/test-touch.t	Wed Jul 10 18:16:38 2019 +0800
@@ -181,6 +181,9 @@
   2 files updated, 0 files merged, 0 files removed, 0 files unresolved
   (branch merge, don't forget to commit)
   $ hg ci -m merge
+  $ hg st --change .
+  A a
+  A b
   $ hg prune -r .
   0 files updated, 0 files merged, 2 files removed, 0 files unresolved
   working directory is now at * (glob)
@@ -194,3 +197,6 @@
   @  12: move
   |
   ~
+  $ hg st --change 17
+  A a
+  A b