diff hgext/mq.py @ 13369:69238d0ca60f stable

mq: catch attempt to qpush to an earlier patch (issue2587) We can't assume that all pushable patches early in the series have already been applied. If a hg qselect is done while you already have patches applied, some patches with guards may now be pushable, even though they come earlier in the series. So instead of checking only applied patches, explicitly check where we are in the series against the position of the patch we want to qpush to.
author Afuna <afunamatata@gmail.com>
date Sat, 12 Feb 2011 16:08:41 +0800
parents 0a1eefaf98f2
children 900a92862a7b
line wrap: on
line diff
--- a/hgext/mq.py	Thu Feb 03 00:27:44 2011 -0600
+++ b/hgext/mq.py	Sat Feb 12 16:08:41 2011 +0800
@@ -1029,15 +1029,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: