changeset 17461:bacde764fba0 stable

amend: preserve phase of amended revision (issue3602) New commit from the amend process were created without any phase contraint. If the amended changeset had a different phase from it's parent, the phases data were lost. The changeset ensure the new commit are created in the same phase than the original changeset.
author Pierre-Yves David <pierre-yves.david@logilab.fr>
date Thu, 30 Aug 2012 16:47:08 +0200
parents f5e86b416e05
children 8085fed2bf0a
files mercurial/cmdutil.py tests/test-commit-amend.t
diffstat 2 files changed, 22 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Fri Sep 07 00:42:42 2012 +0900
+++ b/mercurial/cmdutil.py	Thu Aug 30 16:47:08 2012 +0200
@@ -10,7 +10,7 @@
 import os, sys, errno, re, tempfile
 import util, scmutil, templater, patch, error, templatekw, revlog, copies
 import match as matchmod
-import subrepo, context, repair, bookmarks, graphmod, revset
+import subrepo, context, repair, bookmarks, graphmod, revset, phases
 
 def parsealiases(cmd):
     return cmd.lstrip("^").split("|")
@@ -1668,7 +1668,12 @@
                              user=user,
                              date=date,
                              extra=extra)
-        newid = repo.commitctx(new)
+        ph = repo.ui.config('phases', 'new-commit', phases.draft)
+        try:
+            repo.ui.setconfig('phases', 'new-commit', old.phase())
+            newid = repo.commitctx(new)
+        finally:
+            repo.ui.setconfig('phases', 'new-commit', ph)
         if newid != old.node():
             # Reroute the working copy parent to the new changeset
             repo.setparents(newid, nullid)
--- a/tests/test-commit-amend.t	Fri Sep 07 00:42:42 2012 +0900
+++ b/tests/test-commit-amend.t	Thu Aug 30 16:47:08 2012 +0200
@@ -355,3 +355,18 @@
   $ hg log -r . --debug | grep extra
   extra:       branch=a
   extra:       source=2647734878ef0236dda712fae9c1651cf694ea8a
+
+Preserve phase
+
+  $ hg phase '.^::.'
+  11: draft
+  13: draft
+  $ hg phase --secret --force .
+  $ hg phase '.^::.'
+  11: draft
+  13: secret
+  $ hg commit --amend -m 'amend for phase' -q
+  $ hg phase '.^::.'
+  11: draft
+  13: secret
+