I have a hook function named precommit_bad_branch which imports hook_utils. When invoking precommit_bad_branch via a commit I get the following error message:
error: precommit.branch_check hook raised an exception: No module named hook_utils
abort: No module named hook_utils!
It looks like I’m not allowed to call hook_utils from precommit_bad_branch. The code works fine if I call it explicitly without involving Mercurial.
Is it possible for my hook to call code from another file?
My hgrc hook part looks like this:
[hooks]
precommit.branch_check = python:C:\workspaces\hg_hooks\next_hooks.py:precommit_bad_branch
precommit.debug_code_check = python:C:\workspaces\hg_hooks\common_hooks.py:precommit_contains_debug_code
preupdate.merge_check = python:C:\workspaces\hg_hooks\next_hooks.py:preupdate_bad_merge
Put the
C:\workspaces\hg_hooksdirectory in yourPYTHONPATHand you will be able to writein your configuration file and you will also be able to do
inside any Python file, including the
next_hooks.pyfile.Alternatively, you can modify
sys.pathfromnext_hooks.py, perhaps with code like this: