3

I'm coding a simple hook in order to check syntax of project's files. I want check syntax only before a commit.

My problem is : When I do a shelve, Mercurial run pre-commit hook. The syntax checking take 4-5 minutes.

How can I avoid to run my hook on shelve ?

My .hrgc line of hook :

precommit = python ~/tools/check_syntax.py $($HG root)

I can add parameter in my check_syntax.py to avoid checking if it's required.

Samuel Dauzon
  • 10,744
  • 13
  • 61
  • 94
  • 1
    I don't believe you are able to do this. As it looks like mercurial activates those along with the commit hooks according to [this answer](http://stackoverflow.com/a/30661561/6061947). One thing you could maybe do is to have it run on `outgoing` which would then only be prior to pushing the changes to the repo. – Cory Shay Apr 21 '16 at 15:47
  • I have already read the answer of the link. I hoped there was a way to distinguish **hg commit** and **hg shelve** in **pre-commit** hook. But you're right, I should do my verification on outgoing. Thanks. – Samuel Dauzon Apr 21 '16 at 15:53
  • Checking on outgoing is too late - the commit is done and possibly it's not the last commit but the first in a series which causes the issue. Thus either you'll end up with "fix syntax" commits anyway or a lot of rewriting changes. – planetmaker Apr 21 '16 at 16:38
  • I agree, but if there are no other way... I can't slow each shelve by checking syntax during 5 minutes. So I prefer that my teammate commit rarely a commit **fix syntax**. But I agree, it's better to do it before each commit. – Samuel Dauzon Apr 21 '16 at 19:43
  • Possible duplicate of [ignore certain mercurial commands in mercurial hook](https://stackoverflow.com/questions/30648564/ignore-certain-mercurial-commands-in-mercurial-hook) – ederag Feb 18 '18 at 17:34

1 Answers1

3

You can just override the config for this particular command invocation:

hg shelve --config hooks.precommit= --name abcd

ikostia
  • 7,395
  • 6
  • 30
  • 39
  • Thank you for your answer. Can I add a line to **.hgrc** to define this at default behaviour ? EDIT : No, that's not possible. I must run this config args only with shelve command. Thanks for the trick :) I think it's the best way. – Samuel Dauzon Apr 25 '16 at 07:26
  • I get "abort: error in definition for alias 'shelve': --config may only be given on the command line" if I try the alias trick. – mrtnlrsn Jun 07 '18 at 14:37
  • uh what? That doesn't make sense - hg can't tell that you used a shell alias. It works for me. – iCodeSometime Aug 20 '19 at 13:53