merge with stable
authorSteve Borho <steve@borho.org>
Mon, 14 Feb 2011 14:12:48 -0600
changeset 13373 900a92862a7b
parent 13372 5bced0d28a39 (current diff)
parent 13369 69238d0ca60f (diff)
child 13388 a184dbd9b2c5
merge with stable
hgext/mq.py
--- a/hgext/mq.py	Sun Feb 13 12:19:58 2011 -0600
+++ b/hgext/mq.py	Mon Feb 14 14:12:48 2011 -0600
@@ -1061,15 +1061,17 @@
             # go backwards with qpush)
             if patch:
                 info = self.isapplied(patch)
-                if info:
-                    if info[0] < len(self.applied) - 1:
-                        raise util.Abort(
-                            _("cannot push to a previous patch: %s") % patch)
+                if info and info[0] >= len(self.applied) - 1:
                     self.ui.warn(
                         _('qpush: %s is already at the top\n') % patch)
                     return 0
+
                 pushable, reason = self.pushable(patch)
-                if not pushable:
+                if pushable:
+                    if self.series.index(patch) < self.series_end():
+                        raise util.Abort(
+                            _("cannot push to a previous patch: %s") % patch)
+                else:
                     if reason:
                         reason = _('guarded by %r') % reason
                     else:
--- a/tests/test-mq-qpush-fail.t	Sun Feb 13 12:19:58 2011 -0600
+++ b/tests/test-mq-qpush-fail.t	Mon Feb 14 14:12:48 2011 -0600
@@ -88,3 +88,49 @@
   applying patch1
   unable to read patch1
   [1]
+
+Test qpush to a patch below the currently applied patch.
+
+  $ hg qq -c guardedseriesorder
+  $ hg qnew a
+  $ hg qguard +block
+  $ hg qnew b
+  $ hg qnew c
+
+  $ hg qpop -a
+  popping c
+  popping b
+  popping a
+  patch queue now empty
+
+try to push and pop while a is guarded
+
+  $ hg qpush a
+  cannot push 'a' - guarded by ['+block']
+  [1]
+  $ hg qpush -a
+  applying b
+  patch b is empty
+  applying c
+  patch c is empty
+  now at: c
+
+now try it when a is unguarded, and we're at the top of the queue
+  $ hg qsel block
+  number of guarded, applied patches has changed from 1 to 0
+  $ hg qpush b
+  abort: cannot push to a previous patch: b
+  [255]
+  $ hg qpush a
+  abort: cannot push to a previous patch: a
+  [255]
+
+and now we try it one more time with a unguarded, while we're not at the top of the queue
+
+  $ hg qpop b
+  popping c
+  now at: b
+  $ hg qpush a
+  abort: cannot push to a previous patch: a
+  [255]
+