I want to automatically bump the version of my project when I use
hg tag XXX.
I have set up a pretag hook in my hgrc (note: I have removed the stuff that ensures it is outputting to VERSION in hg root, for clarity):
pretag.bump_version = (echo "$HG_TAG" > VERSION; hg commit -m "Updated VERSION to $HG_TAG" VERSION)
When I create a new tag:
$ hg tag 1.1
I get the error:
warning: ignoring unknown working parent <revision_id>!
I can use a tag hook instead, which succeeds, but then the VERSION number is exactly one revision later than the tag: which means that updating to the tagged revision, and then building will result in the product's version number (which depends upon the VERSION file) will be incorrect.
Is there a better way to handle this? I've looked at SO question #2558531, but that deals with updating the version number each time: I just want to update the version number before I tag the repository.
Switch to a
pre-tag instead of a
pretag hook. The hook
pretag is a special hook which is aware that you're tagging. By contrast the
pre-tag hook is a generic
pre-* hook which is run before the tag command launches at all and is completely unaware that it's tagging -- which means it runs earlier too. (There are pre-* hooks for everything even, say,
I got your example to work like this:
[hooks] pre-tag.bump_version = echo $HG_ARGS > VERSION; hg commit -m "updated version to $HG_ARGS" VERSION
Using the command line only that looked like:
[email protected]:~$ hg init tagtest [email protected]:~$ cd tagtest [email protected]:~/tagtest$ echo text > VERSION [email protected]:~/tagtest$ hg commit -A -m initial adding file [email protected]:~/tagtest$ hg tag --config hooks.pre-tag='echo $HG_ARGS > VERSION; hg commit -m "updated version to $HG_ARGS" VERSION' 1.1
Notice I had to switch the argument to
$HG_ARGS since it's a
pre-* command that doesn't know we're tagging. The details are in the
Also note I'm committing only the
VERSION file when I commit in the hook by naming it explicitly. You don't want to accidentally commit a bunch of debugging stuff you'd excluded from a previous commit just because you tagged.