Controlling the Guards on a Patch

The qguard command lets you determine which guards should apply to a patch, or display the guards that are already in effect. Without any arguments, it displays the guards on the current topmost patch.

$ hg qguard
goodbye.patch: unguarded

To set a positive guard on a patch, prefix the name of the guard with +.

$ hg qguard +foo
$ hg qguard
goodbye.patch: +foo

To set a negative guard on a patch, prefix the name of the guard with -.

$ hg qguard -- hello.patch -quux
$ hg qguard hello.patch
hello.patch: -quux

Notice that we prefixed the arguments to the hg + qguard command with a -- here, so that Mercurial would not interpret the text -quux as an option.

Setting versus modifying

The qguard command sets the guards on a patch; it doesn’t modify them. What this means is that if you run hg qguard +a +b on a patch, then hg qguard +c on the same patch, the only guard that will be set on it afterwards is +c.

Mercurial stores guards in the series file; the form in which they are stored is easy both to understand and to edit by hand. (In other words, you don’t have to use the qguard command if you don’t want to; it’s okay to simply edit the series file.)

$ cat .hg/patches/series
hello.patch #-quux
goodbye.patch #+foo

Get Mercurial: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.