comparison doc/hgrc.5.txt @ 2155:ff255b41b4aa

support hooks written in python. to write hook in python, create module with hook function inside. make sure mercurial can import module (put it in $PYTHONPATH or load it as extension). hook function should look like this: def myhook(ui, repo, hooktype, **kwargs): if hook_passes: return True elif hook_explicitly_fails: return False elif some_other_failure: import util raise util.Abort('helpful failure message') else: return # implicit return of None makes hook fail! then in .hgrc, add hook with "python:" prefix: [hooks] commit = python:mymodule.myhook
author Vadim Gelfer <vadim.gelfer@gmail.com>
date Fri, 28 Apr 2006 15:50:22 -0700
parents 62647394e368
children 5de8b44f0446
comparison
equal deleted inserted replaced
2153:635653cd73ab 2155:ff255b41b4aa
129 # convert files to windows line ending conventions when writing 129 # convert files to windows line ending conventions when writing
130 # them to the working dir 130 # them to the working dir
131 **.txt = tempfile: unix2dos -n INFILE OUTFILE 131 **.txt = tempfile: unix2dos -n INFILE OUTFILE
132 132
133 hooks:: 133 hooks::
134 Commands that get automatically executed by various actions such as 134 Commands or Python functions that get automatically executed by
135 starting or finishing a commit. Multiple commands can be run for 135 various actions such as starting or finishing a commit. Multiple
136 the same action by appending a suffix to the action. Overriding a 136 hooks can be run for the same action by appending a suffix to the
137 site-wide hook can be done by changing its value or setting it to 137 action. Overriding a site-wide hook can be done by changing its
138 an empty string. 138 value or setting it to an empty string.
139 139
140 Example .hg/hgrc: 140 Example .hg/hgrc:
141 141
142 [hooks] 142 [hooks]
143 # do not use the site-wide hook 143 # do not use the site-wide hook
209 In earlier releases, the names of hook environment variables did not 209 In earlier releases, the names of hook environment variables did not
210 have a "HG_" prefix. These unprefixed names are still provided in 210 have a "HG_" prefix. These unprefixed names are still provided in
211 the environment for backwards compatibility, but their use is 211 the environment for backwards compatibility, but their use is
212 deprecated, and they will be removed in a future release. 212 deprecated, and they will be removed in a future release.
213 213
214 The syntax for Python hooks is as follows:
215
216 hookname = python:modulename.submodule.callable
217
218 Python hooks are run within the Mercurial process. Each hook is
219 called with at least three keyword arguments: a ui object (keyword
220 "ui"), a repository object (keyword "repo"), and a "hooktype"
221 keyword that tells what kind of hook is used. Arguments listed as
222 environment variables above are passed as keyword arguments, with no
223 "HG_" prefix, and names in lower case.
224
225 A Python hook must return a "true" value to succeed. Returning a
226 "false" value or raising an exception is treated as failure of the
227 hook.
228
214 http_proxy:: 229 http_proxy::
215 Used to access web-based Mercurial repositories through a HTTP 230 Used to access web-based Mercurial repositories through a HTTP
216 proxy. 231 proxy.
217 host;; 232 host;;
218 Host name and (optional) port of the proxy server, for example 233 Host name and (optional) port of the proxy server, for example