I have some pretxncommit hooks in my local merc开发者_如何转开发urial repository, those hooks are used to check that the commit message includes a reference to a ticket and some other sanity checks.
My problem is that when I try to use mercurial queues, commands like qnew
try to run these hooks and the one of the ticket checking fails, I have seen the same problem with histedit
and similar extensions.
Why are pretxncommit hooks executed with these commands? Do they run some kind of internal commit?
How can I make these hooks to be run only on commits?
Yes, a qnew creates a real commit and thus invokes all the relevant commit hooks. You can confirm this for yourself by temporarily disabling MQ while you have an MQ patch applied and looking at the log.
There is no way to make the pretxncommit hook apply to only some commands except by jury-rigging something with other hooks:
$ cat .hg/hgrc
[hooks]
pre-qnew = touch .hg/skiphook
post-qnew = rm .hg/skiphook
pretxncommit = test -e .hg/skiphook || echo not skipping
$ hg rm README # make some change
$ hg qnew asdf # no hook
$ hg qpop
$ hg rm README
$ hg ci -m asdf
not skipping
Here our pretxncommit hook makes sure a specific file doesn't exist before running its (trivial) hook, and the pre-/post-qnew hooks create the file and clean it up.
The function abort_commit_to_wrong_branch
in https://stackoverflow.com/a/19349636/350713
shows an approach to run a hook only on a "real" commit, not an MQ commit.
The idea is to check for the attribute _committingpatch
in repo
.
If repo
has '_committingpatch' attribute, then it is an MQ commit in progress.
The relevant line is
if hasattr(repo, "_committingpatch"):
This is mentioned in the function newcommit
in
http://hg.intevation.org/mercurial/crew/file/7032dcff290c/hgext/mq.py#l293
- pretxncommit works with all changes (recordable) inside repo
- if you want ignore mq-operation, you could look for the changeset parents and see if that's a descendant of the qparent/qbase tag or see at WC. Smth. like (dirty from head, not from test) hg id -tr .
Or (maybe delirium) - when you work with MQ, you work with qtip always, sn't it?
>hg parents
...
tag: qtip
tag: tip
..
精彩评论