[PATCH] mq: prevent rewriting operation on public changeset

pierre-yves.david at logilab.fr pierre-yves.david at logilab.fr
Wed Feb 1 11:20:33 UTC 2012


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1328095210 -3600
# Branch stable
# Node ID ff656ad483ca5cb448e701b906bb50dc0c9bbcf5
# Parent  c0b2986b37b8b56991febe6e1fadf6c45d1ac0c1
mq: prevent rewriting operation on public changeset

The following operation are denied if the mq changeset is public

* qrefresh
* qpop
* qfold

note: qimport was already denied.

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -1308,10 +1308,13 @@ class queue(object):
                 raise util.Abort(_('trying to pop unknown node %s') % node)
 
             if heads != [self.applied[-1].node]:
                 raise util.Abort(_("popping would remove a revision not "
                                    "managed by this patch queue"))
+            if not repo[self.applied[-1].node].mutable():
+                raise util.Abort(_("popping would remove an immutable revision"),
+                                 hint=_('see "hg help phases" for details'))
 
             # we know there are no local changes, so we can make a simplified
             # form of hg.update.
             if update:
                 qp = self.qparents(repo, rev)
@@ -1369,10 +1372,13 @@ class queue(object):
         try:
             self.checktoppatch(repo)
             (top, patchfn) = (self.applied[-1].node, self.applied[-1].name)
             if repo.changelog.heads(top) != [top]:
                 raise util.Abort(_("cannot refresh a revision with children"))
+            if not repo[top].mutable():
+                raise util.Abort(_("cannot refresh immutable revision"),
+                                 hint=_('see "hg help phases" for details'))
 
             inclsubs = self.checksubstate(repo)
 
             cparents = repo.changelog.parents(top)
             patchparent = self.qparents(repo, top)
diff --git a/tests/test-check-code-hg.t b/tests/test-check-code-hg.t
--- a/tests/test-check-code-hg.t
+++ b/tests/test-check-code-hg.t
@@ -220,10 +220,13 @@
   hgext/mq.py:0:
    >                 except:
    warning: naked except clause
    warning: naked except clause
   hgext/mq.py:0:
+   >                 raise util.Abort(_("popping would remove an immutable revision"),
+   warning: line over 80 characters
+  hgext/mq.py:0:
    >             except:
    warning: naked except clause
    warning: naked except clause
    warning: naked except clause
    warning: naked except clause
diff --git a/tests/test-mq-safety.t b/tests/test-mq-safety.t
--- a/tests/test-mq-safety.t
+++ b/tests/test-mq-safety.t
@@ -1,7 +1,8 @@
   $ echo '[extensions]' >> $HGRCPATH
-  $ echo 'mq =' >> $HGRCPATH
+  $ echo 'hgext.mq =' >> $HGRCPATH
+  $ echo 'hgext.graphlog =' >> $HGRCPATH
 
   $ hg init repo
   $ cd repo
 
   $ echo foo > foo
@@ -15,10 +16,39 @@
 
   $ hg qnew bar
   $ echo bar >> foo
   $ hg qrefresh -m 'append bar'
 
+Try to operate on public mq changeset
+
+  $ hg qpop
+  popping bar
+  now at: foo
+  $ hg phase --public qbase
+  $ echo babar >> foo
+  $ hg qref
+  abort: cannot refresh immutable revision
+  (see "hg help phases" for details)
+  [255]
+  $ hg revert -a
+  reverting foo
+  $ hg qpop
+  abort: popping would remove an immutable revision
+  (see "hg help phases" for details)
+  [255]
+  $ hg qfold bar
+  abort: cannot refresh immutable revision
+  (see "hg help phases" for details)
+  [255]
+  $ hg revert -a
+  reverting foo
+
+restore state for remaining test
+
+  $ hg qpush
+  applying bar
+  now at: bar
 
 try to commit on top of a patch
 
   $ echo quux >> foo
   $ hg ci -m 'append quux'



More information about the Mercurial-devel mailing list