I've recently started working with MQ as I like the idea of working on isolated patches and committing without affecting the repo until the changeset is refined enough. Before that, I used to work with Mercurial's shelves extension, but found it a bit unstable. What I'm still trying to figure out in MQ is how to keep patches separate from each other and apply them in no particular order, and across different branches. Here's my normal flow -
1. Start working on a new patch:
hg qnew fix-bug-1234 -m "fix bug 1234"
# do some work
hg qrefresh
2. Get a new feature/bug to work on:
hg qpop fix-bug-1234
hg qnew some-feature -m "implement feature X"
# some work on feature X (perhaps in a different branch)
hg qrefresh
3. At this point, I'd like to get back to working on bugfix, and put aside the feature work. I thought it's as simple as:
hg qpop some-feature
hg qpush fix-bug-1234
# wrap up bug fix
hg qfinish fix-bug-1234
# get back to work on feature
However, MQ seems to always use the latest patch created in the series, and apply it regardless of the qpop/qpush command I'm using. I should note that the files I work on are completely separate as well (though they can sometimes be the same).
Am I missing something here? Should I be using hg qqueue
for this? Thanks.
hg qpop -a
to remove all patches from the stackhg qpush --move some-patch
to apply "some-patch" without applying whatever other patches may be before it in the patch stackYou could use guards. They allow you to maintain an ordering of patches without rearranging your
series
file, and selectively apply only a subset of patches, still in a stack-ordered fashion.An example in your case would be:
At this point, you're in a situation where patch
feature
comes beforebugfix
in your stack. Now you can use guards to select one or the other, and switch between the two:If you want to work on
feature
:If you want to work on
bugfix
:Note that since you selected the positive guard
bugfixguard
, MQ leap-frogged overfeature
(because it's positive guard was different than the one selected) and applied the patchbugfix
instead (which did match the selected guard).Some useful tools when working with guards are
hg qseries -v
, which will display aG
instead of the usualU
for a guarded, unapplied patch, andhg qselect -l
which will display the guards associated with each patch.No, you aren't missing anything. The
mq
extension does make a pretty strong assumption that patch queues are linear. If you're going to be creating multi-patch features/fixes thenqqueue
would work… But if your features/fixes are just single patches and you want to be able to apply one with out applying the others, it might be easier to just re-arrange.hg/patches/series
(which stores the order that patches will be applied).I do this (and hand-editing patches) enough that I've got a shell alias:
Alternately, if you don't mind applying multiple patches at the same time, you could use
qgoto
: