[PATCH 11 of 12] phases: prevent rebase to rebase immutable changeset

pierre-yves.david at logilab.fr pierre-yves.david at logilab.fr
Tue Oct 18 12:27:08 CDT 2011


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1318958600 -7200
# Node ID 5254346fe69ab981c3d6007e20ba831566b49cbb
# Parent  554e2172627f24ad40e7a0d2f9d58d8845846bbc
phases: prevent rebase to rebase immutable changeset.

diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -193,19 +193,28 @@ def rebase(ui, repo, **opts):
                 revgen = repo.set('(children(ancestor(%r, %d)) and ::(%r))::',
                                   base, dest, base)
 
             rebaseset = [c.rev() for c in revgen]
 
+            if rebaseset:
+                root = min(rebaseset)
+            else:
+                root = None
+
             if not rebaseset:
                 repo.ui.debug('base is ancestor of destination')
                 result = None
             elif not keepf and list(repo.set('first(children(%ld) - %ld)',
                                             rebaseset, rebaseset)):
                 raise util.Abort(
                     _("can't remove original changesets with"
                       " unrebased descendants"),
                     hint=_('use --keep to keep original changesets'))
+            elif not keepf and not repo[root].mutable():
+                raise util.Abort(_("Can't rebase immutable changeset %s")
+                                 % repo[root],
+                                 hint=_('see hg help phases for details'))
             else:
                 result = buildstate(repo, dest, rebaseset, detachf)
 
             if not result:
                 # Empty state built, nothing to rebase
diff --git a/tests/test-rebase-scenario-global.t b/tests/test-rebase-scenario-global.t
--- a/tests/test-rebase-scenario-global.t
+++ b/tests/test-rebase-scenario-global.t
@@ -16,10 +16,11 @@
   adding file changes
   added 8 changesets with 7 changes to 7 files (+2 heads)
   (run 'hg heads' to see heads, 'hg merge' to merge)
   $ hg up tip
   3 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ rm -f .hg/store/phases-heads # XXX ensure imported changeset are mutable
   $ cd ..
 
 
 Rebasing
 D onto H - simple rebase:
@@ -267,10 +268,20 @@ C onto A - rebase onto an ancestor:
   |/
   | o  1: 'B'
   |/
   o  0: 'A'
   
+
+Check rebasing public changeset
+
+  $ hg push -q -r 6 . # update phase of 6
+  $ hg rebase -d 5 -b 6
+  abort: Can't rebase immutable changeset e1c4361dd923
+  (see hg help phases for details)
+  [255]
+
+  $ hg rebase -d 5 -b 6 --keep
   $ cd ..
 
 Test for revset
 
 We need a bit different graph


More information about the Mercurial-devel mailing list