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.
--- a/hgext/mq.py Tue Jan 31 23:13:04 2012 -0600
+++ b/hgext/mq.py Wed Feb 01 12:20:10 2012 +0100
@@ -1313,6 +1313,10 @@
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.
@@ -1374,6 +1378,9 @@
(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)
--- a/tests/test-mq-safety.t Tue Jan 31 23:13:04 2012 -0600
+++ b/tests/test-mq-safety.t Wed Feb 01 12:20:10 2012 +0100
@@ -1,5 +1,6 @@
$ echo '[extensions]' >> $HGRCPATH
- $ echo 'mq =' >> $HGRCPATH
+ $ echo 'hgext.mq =' >> $HGRCPATH
+ $ echo 'hgext.graphlog =' >> $HGRCPATH
$ hg init repo
$ cd repo
@@ -17,6 +18,35 @@
$ 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