hgbook

view en/ch10-hook.xml @ 559:b90b024729f1

WIP DocBook snapshot that all compiles. Mirabile dictu!
author Bryan O'Sullivan <bos@serpentine.com>
date Wed Feb 18 00:22:09 2009 -0800 (2009-02-18)
parents en/ch10-hook.tex@5cd47f721686
children 21c62e09b99f
line source
1 <!-- vim: set filetype=docbkxml shiftwidth=2 autoindent expandtab tw=77 : -->
3 <chapter id="chap:hook">
4 <title>Handling repository events with hooks</title>
6 <para>Mercurial offers a powerful mechanism to let you perform
7 automated actions in response to events that occur in a
8 repository. In some cases, you can even control Mercurial's
9 response to those events.</para>
11 <para>The name Mercurial uses for one of these actions is a
12 <emphasis>hook</emphasis>. Hooks are called
13 <quote>triggers</quote> in some revision control systems, but the
14 two names refer to the same idea.</para>
16 <sect1>
17 <title>An overview of hooks in Mercurial</title>
19 <para>Here is a brief list of the hooks that Mercurial supports.
20 We will revisit each of these hooks in more detail later, in
21 section <xref linkend="sec:hook:ref"/>.</para>
23 <itemizedlist>
24 <listitem><para><literal role="hook">changegroup</literal>: This
25 is run after a group of changesets has been brought into the
26 repository from elsewhere.</para>
27 </listitem>
28 <listitem><para><literal role="hook">commit</literal>: This is
29 run after a new changeset has been created in the local
30 repository.</para>
31 </listitem>
32 <listitem><para><literal role="hook">incoming</literal>: This is
33 run once for each new changeset that is brought into the
34 repository from elsewhere. Notice the difference from
35 <literal role="hook">changegroup</literal>, which is run
36 once per <emphasis>group</emphasis> of changesets brought
37 in.</para>
38 </listitem>
39 <listitem><para><literal role="hook">outgoing</literal>: This is
40 run after a group of changesets has been transmitted from
41 this repository.</para>
42 </listitem>
43 <listitem><para><literal role="hook">prechangegroup</literal>:
44 This is run before starting to bring a group of changesets
45 into the repository.
46 </para>
47 </listitem>
48 <listitem><para><literal role="hook">precommit</literal>:
49 Controlling. This is run before starting a commit.
50 </para>
51 </listitem>
52 <listitem><para><literal role="hook">preoutgoing</literal>:
53 Controlling. This is run before starting to transmit a group
54 of changesets from this repository.
55 </para>
56 </listitem>
57 <listitem><para><literal role="hook">pretag</literal>:
58 Controlling. This is run before creating a tag.
59 </para>
60 </listitem>
61 <listitem><para><literal
62 role="hook">pretxnchangegroup</literal>: Controlling. This
63 is run after a group of changesets has been brought into the
64 local repository from another, but before the transaction
65 completes that will make the changes permanent in the
66 repository.
67 </para>
68 </listitem>
69 <listitem><para><literal role="hook">pretxncommit</literal>:
70 Controlling. This is run after a new changeset has been
71 created in the local repository, but before the transaction
72 completes that will make it permanent.
73 </para>
74 </listitem>
75 <listitem><para><literal role="hook">preupdate</literal>:
76 Controlling. This is run before starting an update or merge
77 of the working directory.
78 </para>
79 </listitem>
80 <listitem><para><literal role="hook">tag</literal>: This is run
81 after a tag is created.
82 </para>
83 </listitem>
84 <listitem><para><literal role="hook">update</literal>: This is
85 run after an update or merge of the working directory has
86 finished.
87 </para>
88 </listitem></itemizedlist>
89 <para>Each of the hooks whose description begins with the word
90 <quote>Controlling</quote> has the ability to determine whether
91 an activity can proceed. If the hook succeeds, the activity may
92 proceed; if it fails, the activity is either not permitted or
93 undone, depending on the hook.
94 </para>
96 </sect1>
97 <sect1>
98 <title>Hooks and security</title>
100 <sect2>
101 <title>Hooks are run with your privileges</title>
103 <para>When you run a Mercurial command in a repository, and the
104 command causes a hook to run, that hook runs on
105 <emphasis>your</emphasis> system, under
106 <emphasis>your</emphasis> user account, with
107 <emphasis>your</emphasis> privilege level. Since hooks are
108 arbitrary pieces of executable code, you should treat them
109 with an appropriate level of suspicion. Do not install a hook
110 unless you are confident that you know who created it and what
111 it does.
112 </para>
114 <para>In some cases, you may be exposed to hooks that you did
115 not install yourself. If you work with Mercurial on an
116 unfamiliar system, Mercurial will run hooks defined in that
117 system's global <filename role="special"> /.hgrc</filename>\
118 file.
119 </para>
121 <para>If you are working with a repository owned by another
122 user, Mercurial can run hooks defined in that user's
123 repository, but it will still run them as <quote>you</quote>.
124 For example, if you <command role="hg-cmd">hg pull</command>
125 from that repository, and its <filename
126 role="special">.hg/hgrc</filename> defines a local <literal
127 role="hook">outgoing</literal> hook, that hook will run
128 under your user account, even though you don't own that
129 repository.
130 </para>
132 <note>
133 <para> This only applies if you are pulling from a repository
134 on a local or network filesystem. If you're pulling over
135 http or ssh, any <literal role="hook">outgoing</literal>
136 hook will run under whatever account is executing the server
137 process, on the server.
138 </para>
139 </note>
141 <para>XXX To see what hooks are defined in a repository, use the
142 <command role="hg-cmd">hg config hooks</command> command. If
143 you are working in one repository, but talking to another that
144 you do not own (e.g. using <command role="hg-cmd">hg
145 pull</command> or <command role="hg-cmd">hg
146 incoming</command>), remember that it is the other
147 repository's hooks you should be checking, not your own.
148 </para>
150 </sect2>
151 <sect2>
152 <title>Hooks do not propagate</title>
154 <para>In Mercurial, hooks are not revision controlled, and do
155 not propagate when you clone, or pull from, a repository. The
156 reason for this is simple: a hook is a completely arbitrary
157 piece of executable code. It runs under your user identity,
158 with your privilege level, on your machine.
159 </para>
161 <para>It would be extremely reckless for any distributed
162 revision control system to implement revision-controlled
163 hooks, as this would offer an easily exploitable way to
164 subvert the accounts of users of the revision control system.
165 </para>
167 <para>Since Mercurial does not propagate hooks, if you are
168 collaborating with other people on a common project, you
169 should not assume that they are using the same Mercurial hooks
170 as you are, or that theirs are correctly configured. You
171 should document the hooks you expect people to use.
172 </para>
174 <para>In a corporate intranet, this is somewhat easier to
175 control, as you can for example provide a
176 <quote>standard</quote> installation of Mercurial on an NFS
177 filesystem, and use a site-wide <filename role="special">
178 /.hgrc</filename>\ file to define hooks that all users will
179 see. However, this too has its limits; see below.
180 </para>
182 </sect2>
183 <sect2>
184 <title>Hooks can be overridden</title>
186 <para>Mercurial allows you to override a hook definition by
187 redefining the hook. You can disable it by setting its value
188 to the empty string, or change its behaviour as you wish.
189 </para>
191 <para>If you deploy a system- or site-wide <filename
192 role="special"> /.hgrc</filename>\ file that defines some
193 hooks, you should thus understand that your users can disable
194 or override those hooks.
195 </para>
197 </sect2>
198 <sect2>
199 <title>Ensuring that critical hooks are run</title>
201 <para>Sometimes you may want to enforce a policy that you do not
202 want others to be able to work around. For example, you may
203 have a requirement that every changeset must pass a rigorous
204 set of tests. Defining this requirement via a hook in a
205 site-wide <filename role="special"> /.hgrc</filename>\ won't
206 work for remote users on laptops, and of course local users
207 can subvert it at will by overriding the hook.
208 </para>
210 <para>Instead, you can set up your policies for use of Mercurial
211 so that people are expected to propagate changes through a
212 well-known <quote>canonical</quote> server that you have
213 locked down and configured appropriately.
214 </para>
216 <para>One way to do this is via a combination of social
217 engineering and technology. Set up a restricted-access
218 account; users can push changes over the network to
219 repositories managed by this account, but they cannot log into
220 the account and run normal shell commands. In this scenario,
221 a user can commit a changeset that contains any old garbage
222 they want.
223 </para>
225 <para>When someone pushes a changeset to the server that
226 everyone pulls from, the server will test the changeset before
227 it accepts it as permanent, and reject it if it fails to pass
228 the test suite. If people only pull changes from this
229 filtering server, it will serve to ensure that all changes
230 that people pull have been automatically vetted.
231 </para>
233 </sect2>
234 </sect1>
235 <sect1>
236 <title>Care with <literal>pretxn</literal> hooks in a
237 shared-access repository</title>
239 <para>If you want to use hooks to do some automated work in a
240 repository that a number of people have shared access to, you
241 need to be careful in how you do this.
242 </para>
244 <para>Mercurial only locks a repository when it is writing to the
245 repository, and only the parts of Mercurial that write to the
246 repository pay attention to locks. Write locks are necessary to
247 prevent multiple simultaneous writers from scribbling on each
248 other's work, corrupting the repository.
249 </para>
251 <para>Because Mercurial is careful with the order in which it
252 reads and writes data, it does not need to acquire a lock when
253 it wants to read data from the repository. The parts of
254 Mercurial that read from the repository never pay attention to
255 locks. This lockless reading scheme greatly increases
256 performance and concurrency.
257 </para>
259 <para>With great performance comes a trade-off, though, one which
260 has the potential to cause you trouble unless you're aware of
261 it. To describe this requires a little detail about how
262 Mercurial adds changesets to a repository and reads those
263 changes.
264 </para>
266 <para>When Mercurial <emphasis>writes</emphasis> metadata, it
267 writes it straight into the destination file. It writes file
268 data first, then manifest data (which contains pointers to the
269 new file data), then changelog data (which contains pointers to
270 the new manifest data). Before the first write to each file, it
271 stores a record of where the end of the file was in its
272 transaction log. If the transaction must be rolled back,
273 Mercurial simply truncates each file back to the size it was
274 before the transaction began.
275 </para>
277 <para>When Mercurial <emphasis>reads</emphasis> metadata, it reads
278 the changelog first, then everything else. Since a reader will
279 only access parts of the manifest or file metadata that it can
280 see in the changelog, it can never see partially written data.
281 </para>
283 <para>Some controlling hooks (<literal
284 role="hook">pretxncommit</literal> and <literal
285 role="hook">pretxnchangegroup</literal>) run when a
286 transaction is almost complete. All of the metadata has been
287 written, but Mercurial can still roll the transaction back and
288 cause the newly-written data to disappear.
289 </para>
291 <para>If one of these hooks runs for long, it opens a window of
292 time during which a reader can see the metadata for changesets
293 that are not yet permanent, and should not be thought of as
294 <quote>really there</quote>. The longer the hook runs, the
295 longer that window is open.
296 </para>
298 <sect2>
299 <title>The problem illustrated</title>
301 <para>In principle, a good use for the <literal
302 role="hook">pretxnchangegroup</literal> hook would be to
303 automatically build and test incoming changes before they are
304 accepted into a central repository. This could let you
305 guarantee that nobody can push changes to this repository that
306 <quote>break the build</quote>. But if a client can pull
307 changes while they're being tested, the usefulness of the test
308 is zero; an unsuspecting someone can pull untested changes,
309 potentially breaking their build.
310 </para>
312 <para>The safest technological answer to this challenge is to
313 set up such a <quote>gatekeeper</quote> repository as
314 <emphasis>unidirectional</emphasis>. Let it take changes
315 pushed in from the outside, but do not allow anyone to pull
316 changes from it (use the <literal
317 role="hook">preoutgoing</literal> hook to lock it down).
318 Configure a <literal role="hook">changegroup</literal> hook so
319 that if a build or test succeeds, the hook will push the new
320 changes out to another repository that people
321 <emphasis>can</emphasis> pull from.
322 </para>
324 <para>In practice, putting a centralised bottleneck like this in
325 place is not often a good idea, and transaction visibility has
326 nothing to do with the problem. As the size of a
327 project&emdash;and the time it takes to build and
328 test&emdash;grows, you rapidly run into a wall with this
329 <quote>try before you buy</quote> approach, where you have
330 more changesets to test than time in which to deal with them.
331 The inevitable result is frustration on the part of all
332 involved.
333 </para>
335 <para>An approach that scales better is to get people to build
336 and test before they push, then run automated builds and tests
337 centrally <emphasis>after</emphasis> a push, to be sure all is
338 well. The advantage of this approach is that it does not
339 impose a limit on the rate at which the repository can accept
340 changes.
341 </para>
343 </sect2>
344 </sect1>
345 <sect1 id="sec:hook:simple">
346 <title>A short tutorial on using hooks</title>
348 <para>It is easy to write a Mercurial hook. Let's start with a
349 hook that runs when you finish a <command role="hg-cmd">hg
350 commit</command>, and simply prints the hash of the changeset
351 you just created. The hook is called <literal
352 role="hook">commit</literal>.
353 </para>
355 <para>All hooks follow the pattern in this example.</para>
357 <!-- &interaction.hook.simple.init; -->
359 <para>You add an entry to the <literal
360 role="rc-hooks">hooks</literal> section of your <filename
361 role="special"> /.hgrc</filename>. On the left is the name of
362 the event to trigger on; on the right is the action to take. As
363 you can see, you can run an arbitrary shell command in a hook.
364 Mercurial passes extra information to the hook using environment
365 variables (look for <envar>HG_NODE</envar> in the example).
366 </para>
368 <sect2>
369 <title>Performing multiple actions per event</title>
371 <para>Quite often, you will want to define more than one hook
372 for a particular kind of event, as shown below.</para>
374 <!-- &interaction.hook.simple.ext; -->
376 <para>Mercurial lets you do this by adding an
377 <emphasis>extension</emphasis> to the end of a hook's name.
378 You extend a hook's name by giving the name of the hook,
379 followed by a full stop (the
380 <quote><literal>.</literal></quote> character), followed by
381 some more text of your choosing. For example, Mercurial will
382 run both <literal>commit.foo</literal> and
383 <literal>commit.bar</literal> when the
384 <literal>commit</literal> event occurs.
385 </para>
387 <para>To give a well-defined order of execution when there are
388 multiple hooks defined for an event, Mercurial sorts hooks by
389 extension, and executes the hook commands in this sorted
390 order. In the above example, it will execute
391 <literal>commit.bar</literal> before
392 <literal>commit.foo</literal>, and <literal>commit</literal>
393 before both.
394 </para>
396 <para>It is a good idea to use a somewhat descriptive extension
397 when you define a new hook. This will help you to remember
398 what the hook was for. If the hook fails, you'll get an error
399 message that contains the hook name and extension, so using a
400 descriptive extension could give you an immediate hint as to
401 why the hook failed (see section <xref
402 linkend="sec:hook:perm"/> for an example).
403 </para>
405 </sect2>
406 <sect2 id="sec:hook:perm">
407 <title>Controlling whether an activity can proceed</title>
409 <para>In our earlier examples, we used the <literal
410 role="hook">commit</literal> hook, which is run after a
411 commit has completed. This is one of several Mercurial hooks
412 that run after an activity finishes. Such hooks have no way
413 of influencing the activity itself.
414 </para>
416 <para>Mercurial defines a number of events that occur before an
417 activity starts; or after it starts, but before it finishes.
418 Hooks that trigger on these events have the added ability to
419 choose whether the activity can continue, or will abort.
420 </para>
422 <para>The <literal role="hook">pretxncommit</literal> hook runs
423 after a commit has all but completed. In other words, the
424 metadata representing the changeset has been written out to
425 disk, but the transaction has not yet been allowed to
426 complete. The <literal role="hook">pretxncommit</literal>
427 hook has the ability to decide whether the transaction can
428 complete, or must be rolled back.
429 </para>
431 <para>If the <literal role="hook">pretxncommit</literal> hook
432 exits with a status code of zero, the transaction is allowed
433 to complete; the commit finishes; and the <literal
434 role="hook">commit</literal> hook is run. If the <literal
435 role="hook">pretxncommit</literal> hook exits with a
436 non-zero status code, the transaction is rolled back; the
437 metadata representing the changeset is erased; and the
438 <literal role="hook">commit</literal> hook is not run.
439 </para>
441 <!-- &interaction.hook.simple.pretxncommit; -->
443 <para>The hook in the example above checks that a commit comment
444 contains a bug ID. If it does, the commit can complete. If
445 not, the commit is rolled back.
446 </para>
448 </sect2>
449 </sect1>
450 <sect1>
451 <title>Writing your own hooks</title>
453 <para>When you are writing a hook, you might find it useful to run
454 Mercurial either with the <option
455 role="hg-opt-global">-v</option> option, or the <envar
456 role="rc-item-ui">verbose</envar> config item set to
457 <quote>true</quote>. When you do so, Mercurial will print a
458 message before it calls each hook.
459 </para>
461 <sect2 id="sec:hook:lang">
462 <title>Choosing how your hook should run</title>
464 <para>You can write a hook either as a normal
465 program&emdash;typically a shell script&emdash;or as a Python
466 function that is executed within the Mercurial process.
467 </para>
469 <para>Writing a hook as an external program has the advantage
470 that it requires no knowledge of Mercurial's internals. You
471 can call normal Mercurial commands to get any added
472 information you need. The trade-off is that external hooks
473 are slower than in-process hooks.
474 </para>
476 <para>An in-process Python hook has complete access to the
477 Mercurial API, and does not <quote>shell out</quote> to
478 another process, so it is inherently faster than an external
479 hook. It is also easier to obtain much of the information
480 that a hook requires by using the Mercurial API than by
481 running Mercurial commands.
482 </para>
484 <para>If you are comfortable with Python, or require high
485 performance, writing your hooks in Python may be a good
486 choice. However, when you have a straightforward hook to
487 write and you don't need to care about performance (probably
488 the majority of hooks), a shell script is perfectly fine.
489 </para>
491 </sect2>
492 <sect2 id="sec:hook:param">
493 <title>Hook parameters</title>
495 <para>Mercurial calls each hook with a set of well-defined
496 parameters. In Python, a parameter is passed as a keyword
497 argument to your hook function. For an external program, a
498 parameter is passed as an environment variable.
499 </para>
501 <para>Whether your hook is written in Python or as a shell
502 script, the hook-specific parameter names and values will be
503 the same. A boolean parameter will be represented as a
504 boolean value in Python, but as the number 1 (for
505 <quote>true</quote>) or 0 (for <quote>false</quote>) as an
506 environment variable for an external hook. If a hook
507 parameter is named <literal>foo</literal>, the keyword
508 argument for a Python hook will also be named
509 <literal>foo</literal>, while the environment variable for an
510 external hook will be named <literal>HG_FOO</literal>.
511 </para>
513 </sect2>
514 <sect2>
515 <title>Hook return values and activity control</title>
517 <para>A hook that executes successfully must exit with a status
518 of zero if external, or return boolean <quote>false</quote> if
519 in-process. Failure is indicated with a non-zero exit status
520 from an external hook, or an in-process hook returning boolean
521 <quote>true</quote>. If an in-process hook raises an
522 exception, the hook is considered to have failed.
523 </para>
525 <para>For a hook that controls whether an activity can proceed,
526 zero/false means <quote>allow</quote>, while
527 non-zero/true/exception means <quote>deny</quote>.
528 </para>
530 </sect2>
531 <sect2>
532 <title>Writing an external hook</title>
534 <para>When you define an external hook in your <filename
535 role="special"> /.hgrc</filename>\ and the hook is run, its
536 value is passed to your shell, which interprets it. This
537 means that you can use normal shell constructs in the body of
538 the hook.
539 </para>
541 <para>An executable hook is always run with its current
542 directory set to a repository's root directory.
543 </para>
545 <para>Each hook parameter is passed in as an environment
546 variable; the name is upper-cased, and prefixed with the
547 string <quote><literal>HG_</literal></quote>.
548 </para>
550 <para>With the exception of hook parameters, Mercurial does not
551 set or modify any environment variables when running a hook.
552 This is useful to remember if you are writing a site-wide hook
553 that may be run by a number of different users with differing
554 environment variables set. In multi-user situations, you
555 should not rely on environment variables being set to the
556 values you have in your environment when testing the hook.
557 </para>
559 </sect2>
560 <sect2>
561 <title>Telling Mercurial to use an in-process hook</title>
563 <para>The <filename role="special"> /.hgrc</filename>\ syntax
564 for defining an in-process hook is slightly different than for
565 an executable hook. The value of the hook must start with the
566 text <quote><literal>python:</literal></quote>, and continue
567 with the fully-qualified name of a callable object to use as
568 the hook's value.
569 </para>
571 <para>The module in which a hook lives is automatically imported
572 when a hook is run. So long as you have the module name and
573 <envar>PYTHONPATH</envar> right, it should <quote>just
574 work</quote>.
575 </para>
577 <para>The following <filename role="special"> /.hgrc</filename>\
578 example snippet illustrates the syntax and meaning of the
579 notions we just described.
580 </para>
581 <programlisting>[hooks] commit.example =
582 python:mymodule.submodule.myhook</programlisting>
583 <para>When Mercurial runs the <literal>commit.example</literal>
584 hook, it imports <literal>mymodule.submodule</literal>, looks
585 for the callable object named <literal>myhook</literal>, and
586 calls it.
587 </para>
589 </sect2>
590 <sect2>
591 <title>Writing an in-process hook</title>
593 <para>The simplest in-process hook does nothing, but illustrates
594 the basic shape of the hook API:
595 </para>
596 <programlisting>def myhook(ui, repo, **kwargs):
597 pass</programlisting>
598 <para>The first argument to a Python hook is always a <literal
599 role="py-mod-mercurial.ui">ui</literal> object. The second
600 is a repository object; at the moment, it is always an
601 instance of <literal
602 role="py-mod-mercurial.localrepo">localrepository</literal>.
603 Following these two arguments are other keyword arguments.
604 Which ones are passed in depends on the hook being called, but
605 a hook can ignore arguments it doesn't care about by dropping
606 them into a keyword argument dict, as with
607 <literal>**kwargs</literal> above.
608 </para>
610 </sect2>
611 </sect1>
612 <sect1>
613 <title>Some hook examples</title>
615 <sect2>
616 <title>Writing meaningful commit messages</title>
618 <para>It's hard to imagine a useful commit message being very
619 short. The simple <literal role="hook">pretxncommit</literal>
620 hook of the example below will prevent you from committing a
621 changeset with a message that is less than ten bytes long.
622 </para>
624 <!-- &interaction.hook.msglen.go; -->
626 </sect2>
627 <sect2>
628 <title>Checking for trailing whitespace</title>
630 <para>An interesting use of a commit-related hook is to help you
631 to write cleaner code. A simple example of <quote>cleaner
632 code</quote> is the dictum that a change should not add any
633 new lines of text that contain <quote>trailing
634 whitespace</quote>. Trailing whitespace is a series of
635 space and tab characters at the end of a line of text. In
636 most cases, trailing whitespace is unnecessary, invisible
637 noise, but it is occasionally problematic, and people often
638 prefer to get rid of it.
639 </para>
641 <para>You can use either the <literal
642 role="hook">precommit</literal> or <literal
643 role="hook">pretxncommit</literal> hook to tell whether you
644 have a trailing whitespace problem. If you use the <literal
645 role="hook">precommit</literal> hook, the hook will not know
646 which files you are committing, so it will have to check every
647 modified file in the repository for trailing white space. If
648 you want to commit a change to just the file
649 <filename>foo</filename>, but the file
650 <filename>bar</filename> contains trailing whitespace, doing a
651 check in the <literal role="hook">precommit</literal> hook
652 will prevent you from committing <filename>foo</filename> due
653 to the problem with <filename>bar</filename>. This doesn't
654 seem right.
655 </para>
657 <para>Should you choose the <literal
658 role="hook">pretxncommit</literal> hook, the check won't
659 occur until just before the transaction for the commit
660 completes. This will allow you to check for problems only the
661 exact files that are being committed. However, if you entered
662 the commit message interactively and the hook fails, the
663 transaction will roll back; you'll have to re-enter the commit
664 message after you fix the trailing whitespace and run <command
665 role="hg-cmd">hg commit</command> again.
666 </para>
668 <!-- &interaction.hook.ws.simple; -->
670 <para>In this example, we introduce a simple <literal
671 role="hook">pretxncommit</literal> hook that checks for
672 trailing whitespace. This hook is short, but not very
673 helpful. It exits with an error status if a change adds a
674 line with trailing whitespace to any file, but does not print
675 any information that might help us to identify the offending
676 file or line. It also has the nice property of not paying
677 attention to unmodified lines; only lines that introduce new
678 trailing whitespace cause problems.
679 </para>
681 <para>The above version is much more complex, but also more
682 useful. It parses a unified diff to see if any lines add
683 trailing whitespace, and prints the name of the file and the
684 line number of each such occurrence. Even better, if the
685 change adds trailing whitespace, this hook saves the commit
686 comment and prints the name of the save file before exiting
687 and telling Mercurial to roll the transaction back, so you can
688 use the <option role="hg-opt-commit">-l filename</option>
689 option to <command role="hg-cmd">hg commit</command> to reuse
690 the saved commit message once you've corrected the problem.
691 </para>
693 <!-- &interaction.hook.ws.better; -->
695 <para>As a final aside, note in the example above the use of
696 <command>perl</command>'s in-place editing feature to get rid
697 of trailing whitespace from a file. This is concise and
698 useful enough that I will reproduce it here.
699 </para>
700 <programlisting>perl -pi -e 's,\s+$,,' filename</programlisting>
702 </sect2>
703 </sect1>
704 <sect1>
705 <title>Bundled hooks</title>
707 <para>Mercurial ships with several bundled hooks. You can find
708 them in the <filename class="directory">hgext</filename>
709 directory of a Mercurial source tree. If you are using a
710 Mercurial binary package, the hooks will be located in the
711 <filename class="directory">hgext</filename> directory of
712 wherever your package installer put Mercurial.
713 </para>
715 <sect2>
716 <title><literal role="hg-ext">acl</literal>&emdash;access
717 control for parts of a repository</title>
719 <para>The <literal role="hg-ext">acl</literal> extension lets
720 you control which remote users are allowed to push changesets
721 to a networked server. You can protect any portion of a
722 repository (including the entire repo), so that a specific
723 remote user can push changes that do not affect the protected
724 portion.
725 </para>
727 <para>This extension implements access control based on the
728 identity of the user performing a push,
729 <emphasis>not</emphasis> on who committed the changesets
730 they're pushing. It makes sense to use this hook only if you
731 have a locked-down server environment that authenticates
732 remote users, and you want to be sure that only specific users
733 are allowed to push changes to that server.
734 </para>
736 <sect3>
737 <title>Configuring the <literal role="hook">acl</literal>
738 hook</title>
740 <para>In order to manage incoming changesets, the <literal
741 role="hg-ext">acl</literal> hook must be used as a
742 <literal role="hook">pretxnchangegroup</literal> hook. This
743 lets it see which files are modified by each incoming
744 changeset, and roll back a group of changesets if they
745 modify <quote>forbidden</quote> files. Example:
746 </para>
747 <programlisting>[hooks] pretxnchangegroup.acl =
748 python:hgext.acl.hook</programlisting>
750 <para>The <literal role="hg-ext">acl</literal> extension is
751 configured using three sections.
752 </para>
754 <para>The <literal role="rc-acl">acl</literal> section has
755 only one entry, <envar role="rc-item-acl">sources</envar>,
756 which lists the sources of incoming changesets that the hook
757 should pay attention to. You don't normally need to
758 configure this section.
759 </para>
760 <itemizedlist>
761 <listitem><para><envar role="rc-item-acl">serve</envar>:
762 Control incoming changesets that are arriving from a
763 remote repository over http or ssh. This is the default
764 value of <envar role="rc-item-acl">sources</envar>, and
765 usually the only setting you'll need for this
766 configuration item.
767 </para>
768 </listitem>
769 <listitem><para><envar role="rc-item-acl">pull</envar>:
770 Control incoming changesets that are arriving via a pull
771 from a local repository.
772 </para>
773 </listitem>
774 <listitem><para><envar role="rc-item-acl">push</envar>:
775 Control incoming changesets that are arriving via a push
776 from a local repository.
777 </para>
778 </listitem>
779 <listitem><para><envar role="rc-item-acl">bundle</envar>:
780 Control incoming changesets that are arriving from
781 another repository via a bundle.
782 </para>
783 </listitem></itemizedlist>
785 <para>The <literal role="rc-acl.allow">acl.allow</literal>
786 section controls the users that are allowed to add
787 changesets to the repository. If this section is not
788 present, all users that are not explicitly denied are
789 allowed. If this section is present, all users that are not
790 explicitly allowed are denied (so an empty section means
791 that all users are denied).
792 </para>
794 <para>The <literal role="rc-acl.deny">acl.deny</literal>
795 section determines which users are denied from adding
796 changesets to the repository. If this section is not
797 present or is empty, no users are denied.
798 </para>
800 <para>The syntaxes for the <literal
801 role="rc-acl.allow">acl.allow</literal> and <literal
802 role="rc-acl.deny">acl.deny</literal> sections are
803 identical. On the left of each entry is a glob pattern that
804 matches files or directories, relative to the root of the
805 repository; on the right, a user name.
806 </para>
808 <para>In the following example, the user
809 <literal>docwriter</literal> can only push changes to the
810 <filename class="directory">docs</filename> subtree of the
811 repository, while <literal>intern</literal> can push changes
812 to any file or directory except <filename
813 class="directory">source/sensitive</filename>.
814 </para>
815 <programlisting>[acl.allow] docs/** = docwriter [acl.deny]
816 source/sensitive/** = intern</programlisting>
818 </sect3>
819 <sect3>
820 <title>Testing and troubleshooting</title>
822 <para>If you want to test the <literal
823 role="hg-ext">acl</literal> hook, run it with Mercurial's
824 debugging output enabled. Since you'll probably be running
825 it on a server where it's not convenient (or sometimes
826 possible) to pass in the <option
827 role="hg-opt-global">--debug</option> option, don't forget
828 that you can enable debugging output in your <filename
829 role="special"> /.hgrc</filename>:
830 </para>
831 <programlisting>[ui] debug = true</programlisting>
832 <para>With this enabled, the <literal
833 role="hg-ext">acl</literal> hook will print enough
834 information to let you figure out why it is allowing or
835 forbidding pushes from specific users.
836 </para>
838 </sect3>
839 </sect2>
840 <sect2>
841 <title><literal
842 role="hg-ext">bugzilla</literal>&emdash;integration with
843 Bugzilla</title>
845 <para>The <literal role="hg-ext">bugzilla</literal> extension
846 adds a comment to a Bugzilla bug whenever it finds a reference
847 to that bug ID in a commit comment. You can install this hook
848 on a shared server, so that any time a remote user pushes
849 changes to this server, the hook gets run.
850 </para>
852 <para>It adds a comment to the bug that looks like this (you can
853 configure the contents of the comment&emdash;see below):
854 </para>
855 <programlisting>Changeset aad8b264143a, made by Joe User
856 &lt;joe.user@domain.com&gt; in the frobnitz repository, refers
857 to this bug. For complete details, see
858 http://hg.domain.com/frobnitz?cmd=changeset;node=aad8b264143a
859 Changeset description: Fix bug 10483 by guarding against some
860 NULL pointers</programlisting>
861 <para>The value of this hook is that it automates the process of
862 updating a bug any time a changeset refers to it. If you
863 configure the hook properly, it makes it easy for people to
864 browse straight from a Bugzilla bug to a changeset that refers
865 to that bug.
866 </para>
868 <para>You can use the code in this hook as a starting point for
869 some more exotic Bugzilla integration recipes. Here are a few
870 possibilities:
871 </para>
872 <itemizedlist>
873 <listitem><para>Require that every changeset pushed to the
874 server have a valid bug ID in its commit comment. In this
875 case, you'd want to configure the hook as a <literal
876 role="hook">pretxncommit</literal> hook. This would
877 allow the hook to reject changes that didn't contain bug
878 IDs.
879 </para>
880 </listitem>
881 <listitem><para>Allow incoming changesets to automatically
882 modify the <emphasis>state</emphasis> of a bug, as well as
883 simply adding a comment. For example, the hook could
884 recognise the string <quote>fixed bug 31337</quote> as
885 indicating that it should update the state of bug 31337 to
886 <quote>requires testing</quote>.
887 </para>
888 </listitem></itemizedlist>
890 <sect3 id="sec:hook:bugzilla:config">
891 <title>Configuring the <literal role="hook">bugzilla</literal>
892 hook</title>
894 <para>You should configure this hook in your server's
895 <filename role="special"> /.hgrc</filename>\ as an <literal
896 role="hook">incoming</literal> hook, for example as
897 follows:
898 </para>
899 <programlisting>[hooks] incoming.bugzilla =
900 python:hgext.bugzilla.hook</programlisting>
902 <para>Because of the specialised nature of this hook, and
903 because Bugzilla was not written with this kind of
904 integration in mind, configuring this hook is a somewhat
905 involved process.
906 </para>
908 <para>Before you begin, you must install the MySQL bindings
909 for Python on the host(s) where you'll be running the hook.
910 If this is not available as a binary package for your
911 system, you can download it from
912 <citation>web:mysql-python</citation>.
913 </para>
915 <para>Configuration information for this hook lives in the
916 <literal role="rc-bugzilla">bugzilla</literal> section of
917 your <filename role="special"> /.hgrc</filename>.
918 </para>
919 <itemizedlist>
920 <listitem><para><envar
921 role="rc-item-bugzilla">version</envar>: The version
922 of Bugzilla installed on the server. The database
923 schema that Bugzilla uses changes occasionally, so this
924 hook has to know exactly which schema to use. At the
925 moment, the only version supported is
926 <literal>2.16</literal>.
927 </para>
928 </listitem>
929 <listitem><para><envar role="rc-item-bugzilla">host</envar>:
930 The hostname of the MySQL server that stores your
931 Bugzilla data. The database must be configured to allow
932 connections from whatever host you are running the
933 <literal role="hook">bugzilla</literal> hook on.
934 </para>
935 </listitem>
936 <listitem><para><envar role="rc-item-bugzilla">user</envar>:
937 The username with which to connect to the MySQL server.
938 The database must be configured to allow this user to
939 connect from whatever host you are running the <literal
940 role="hook">bugzilla</literal> hook on. This user
941 must be able to access and modify Bugzilla tables. The
942 default value of this item is <literal>bugs</literal>,
943 which is the standard name of the Bugzilla user in a
944 MySQL database.
945 </para>
946 </listitem>
947 <listitem><para><envar
948 role="rc-item-bugzilla">password</envar>: The MySQL
949 password for the user you configured above. This is
950 stored as plain text, so you should make sure that
951 unauthorised users cannot read the <filename
952 role="special"> /.hgrc</filename>\ file where you
953 store this information.
954 </para>
955 </listitem>
956 <listitem><para><envar role="rc-item-bugzilla">db</envar>:
957 The name of the Bugzilla database on the MySQL server.
958 The default value of this item is
959 <literal>bugs</literal>, which is the standard name of
960 the MySQL database where Bugzilla stores its data.
961 </para>
962 </listitem>
963 <listitem><para><envar
964 role="rc-item-bugzilla">notify</envar>: If you want
965 Bugzilla to send out a notification email to subscribers
966 after this hook has added a comment to a bug, you will
967 need this hook to run a command whenever it updates the
968 database. The command to run depends on where you have
969 installed Bugzilla, but it will typically look something
970 like this, if you have Bugzilla installed in <filename
971 class="directory">/var/www/html/bugzilla</filename>:
972 </para>
973 <programlisting>cd /var/www/html/bugzilla &amp;&amp;
974 ./processmail %s nobody@nowhere.com</programlisting>
975 </listitem>
976 <listitem><para> The Bugzilla
977 <literal>processmail</literal> program expects to be
978 given a bug ID (the hook replaces
979 <quote><literal>%s</literal></quote> with the bug ID)
980 and an email address. It also expects to be able to
981 write to some files in the directory that it runs in.
982 If Bugzilla and this hook are not installed on the same
983 machine, you will need to find a way to run
984 <literal>processmail</literal> on the server where
985 Bugzilla is installed.
986 </para>
987 </listitem></itemizedlist>
989 </sect3>
990 <sect3>
991 <title>Mapping committer names to Bugzilla user names</title>
993 <para>By default, the <literal
994 role="hg-ext">bugzilla</literal> hook tries to use the
995 email address of a changeset's committer as the Bugzilla
996 user name with which to update a bug. If this does not suit
997 your needs, you can map committer email addresses to
998 Bugzilla user names using a <literal
999 role="rc-usermap">usermap</literal> section.
1000 </para>
1002 <para>Each item in the <literal
1003 role="rc-usermap">usermap</literal> section contains an
1004 email address on the left, and a Bugzilla user name on the
1005 right.
1006 </para>
1007 <programlisting>[usermap] jane.user@example.com =
1008 jane</programlisting>
1009 <para>You can either keep the <literal
1010 role="rc-usermap">usermap</literal> data in a normal
1011 <filename role="special">~/.hgrc</filename>, or tell the
1012 <literal role="hg-ext">bugzilla</literal> hook to read the
1013 information from an external <filename>usermap</filename>
1014 file. In the latter case, you can store
1015 <filename>usermap</filename> data by itself in (for example)
1016 a user-modifiable repository. This makes it possible to let
1017 your users maintain their own <envar
1018 role="rc-item-bugzilla">usermap</envar> entries. The main
1019 <filename role="special"> /.hgrc</filename>\ file might look
1020 like this:
1021 </para>
1022 <programlisting># regular hgrc file refers to external usermap
1023 file [bugzilla] usermap =
1024 /home/hg/repos/userdata/bugzilla-usermap.conf</programlisting>
1025 <para>While the <filename>usermap</filename> file that it
1026 refers to might look like this:
1027 </para>
1028 <programlisting># bugzilla-usermap.conf - inside a hg
1029 repository [usermap] stephanie@example.com =
1030 steph</programlisting>
1032 </sect3>
1033 <sect3>
1034 <title>Configuring the text that gets added to a bug</title>
1036 <para>You can configure the text that this hook adds as a
1037 comment; you specify it in the form of a Mercurial template.
1038 Several <filename role="special"> /.hgrc</filename>\ entries
1039 (still in the <literal role="rc-bugzilla">bugzilla</literal>
1040 section) control this behaviour.
1041 </para>
1042 <itemizedlist>
1043 <listitem><para><literal>strip</literal>: The number of
1044 leading path elements to strip from a repository's path
1045 name to construct a partial path for a URL. For example,
1046 if the repositories on your server live under <filename
1047 class="directory">/home/hg/repos</filename>, and you
1048 have a repository whose path is <filename
1049 class="directory">/home/hg/repos/app/tests</filename>,
1050 then setting <literal>strip</literal> to
1051 <literal>4</literal> will give a partial path of
1052 <filename class="directory">app/tests</filename>. The
1053 hook will make this partial path available when
1054 expanding a template, as <literal>webroot</literal>.
1055 </para>
1056 </listitem>
1057 <listitem><para><literal>template</literal>: The text of the
1058 template to use. In addition to the usual
1059 changeset-related variables, this template can use
1060 <literal>hgweb</literal> (the value of the
1061 <literal>hgweb</literal> configuration item above) and
1062 <literal>webroot</literal> (the path constructed using
1063 <literal>strip</literal> above).
1064 </para>
1065 </listitem></itemizedlist>
1067 <para>In addition, you can add a <envar
1068 role="rc-item-web">baseurl</envar> item to the <literal
1069 role="rc-web">web</literal> section of your <filename
1070 role="special"> /.hgrc</filename>. The <literal
1071 role="hg-ext">bugzilla</literal> hook will make this
1072 available when expanding a template, as the base string to
1073 use when constructing a URL that will let users browse from
1074 a Bugzilla comment to view a changeset. Example:
1075 </para>
1076 <programlisting>[web] baseurl =
1077 http://hg.domain.com/</programlisting>
1079 <para>Here is an example set of <literal
1080 role="hg-ext">bugzilla</literal> hook config information.
1081 </para>
1082 <programlisting>[bugzilla] host = bugzilla.example.com
1083 password = mypassword version = 2.16 # server-side repos
1084 live in /home/hg/repos, so strip 4 leading # separators
1085 strip = 4 hgweb = http://hg.example.com/ usermap =
1086 /home/hg/repos/notify/bugzilla.conf template = Changeset
1087 {node|short}, made by {author} in the {webroot} repo, refers
1088 to this bug.\\nFor complete details, see
1089 {hgweb}{webroot}?cmd=changeset;node={node|short}\\nChangeset
1090 description:\\n\\t{desc|tabindent}</programlisting>
1092 </sect3>
1093 <sect3>
1094 <title>Testing and troubleshooting</title>
1096 <para>The most common problems with configuring the <literal
1097 role="hg-ext">bugzilla</literal> hook relate to running
1098 Bugzilla's <filename>processmail</filename> script and
1099 mapping committer names to user names.
1100 </para>
1102 <para>Recall from section <xref
1103 linkend="sec:hook:bugzilla:config"/> above that the user
1104 that runs the Mercurial process on the server is also the
1105 one that will run the <filename>processmail</filename>
1106 script. The <filename>processmail</filename> script
1107 sometimes causes Bugzilla to write to files in its
1108 configuration directory, and Bugzilla's configuration files
1109 are usually owned by the user that your web server runs
1110 under.
1111 </para>
1113 <para>You can cause <filename>processmail</filename> to be run
1114 with the suitable user's identity using the
1115 <command>sudo</command> command. Here is an example entry
1116 for a <filename>sudoers</filename> file.
1117 </para>
1118 <programlisting>hg_user = (httpd_user) NOPASSWD:
1119 /var/www/html/bugzilla/processmail-wrapper
1120 %s</programlisting>
1121 <para>This allows the <literal>hg_user</literal> user to run a
1122 <filename>processmail-wrapper</filename> program under the
1123 identity of <literal>httpd_user</literal>.
1124 </para>
1126 <para>This indirection through a wrapper script is necessary,
1127 because <filename>processmail</filename> expects to be run
1128 with its current directory set to wherever you installed
1129 Bugzilla; you can't specify that kind of constraint in a
1130 <filename>sudoers</filename> file. The contents of the
1131 wrapper script are simple:
1132 </para>
1133 <programlisting>#!/bin/sh cd `dirname $0` &amp;&amp;
1134 ./processmail "$1" nobody@example.com</programlisting>
1135 <para>It doesn't seem to matter what email address you pass to
1136 <filename>processmail</filename>.
1137 </para>
1139 <para>If your <literal role="rc-usermap">usermap</literal> is
1140 not set up correctly, users will see an error message from
1141 the <literal role="hg-ext">bugzilla</literal> hook when they
1142 push changes to the server. The error message will look
1143 like this:
1144 </para>
1145 <programlisting>cannot find bugzilla user id for
1146 john.q.public@example.com</programlisting>
1147 <para>What this means is that the committer's address,
1148 <literal>john.q.public@example.com</literal>, is not a valid
1149 Bugzilla user name, nor does it have an entry in your
1150 <literal role="rc-usermap">usermap</literal> that maps it to
1151 a valid Bugzilla user name.
1152 </para>
1154 </sect3>
1155 </sect2>
1156 <sect2>
1157 <title><literal role="hg-ext">notify</literal>&emdash;send email
1158 notifications</title>
1160 <para>Although Mercurial's built-in web server provides RSS
1161 feeds of changes in every repository, many people prefer to
1162 receive change notifications via email. The <literal
1163 role="hg-ext">notify</literal> hook lets you send out
1164 notifications to a set of email addresses whenever changesets
1165 arrive that those subscribers are interested in.
1166 </para>
1168 <para>As with the <literal role="hg-ext">bugzilla</literal>
1169 hook, the <literal role="hg-ext">notify</literal> hook is
1170 template-driven, so you can customise the contents of the
1171 notification messages that it sends.
1172 </para>
1174 <para>By default, the <literal role="hg-ext">notify</literal>
1175 hook includes a diff of every changeset that it sends out; you
1176 can limit the size of the diff, or turn this feature off
1177 entirely. It is useful for letting subscribers review changes
1178 immediately, rather than clicking to follow a URL.
1179 </para>
1181 <sect3>
1182 <title>Configuring the <literal role="hg-ext">notify</literal>
1183 hook</title>
1185 <para>You can set up the <literal
1186 role="hg-ext">notify</literal> hook to send one email
1187 message per incoming changeset, or one per incoming group of
1188 changesets (all those that arrived in a single pull or
1189 push).
1190 </para>
1191 <programlisting>[hooks] # send one email per group of changes
1192 changegroup.notify = python:hgext.notify.hook # send one
1193 email per change incoming.notify =
1194 python:hgext.notify.hook</programlisting>
1196 <para>Configuration information for this hook lives in the
1197 <literal role="rc-notify">notify</literal> section of a
1198 <filename role="special"> /.hgrc</filename>\ file.
1199 </para>
1200 <itemizedlist>
1201 <listitem><para><envar role="rc-item-notify">test</envar>:
1202 By default, this hook does not send out email at all;
1203 instead, it prints the message that it
1204 <emphasis>would</emphasis> send. Set this item to
1205 <literal>false</literal> to allow email to be sent. The
1206 reason that sending of email is turned off by default is
1207 that it takes several tries to configure this extension
1208 exactly as you would like, and it would be bad form to
1209 spam subscribers with a number of <quote>broken</quote>
1210 notifications while you debug your configuration.
1211 </para>
1212 </listitem>
1213 <listitem><para><envar role="rc-item-notify">config</envar>:
1214 The path to a configuration file that contains
1215 subscription information. This is kept separate from
1216 the main <filename role="special"> /.hgrc</filename>\ so
1217 that you can maintain it in a repository of its own.
1218 People can then clone that repository, update their
1219 subscriptions, and push the changes back to your server.
1220 </para>
1221 </listitem>
1222 <listitem><para><envar role="rc-item-notify">strip</envar>:
1223 The number of leading path separator characters to strip
1224 from a repository's path, when deciding whether a
1225 repository has subscribers. For example, if the
1226 repositories on your server live in <filename
1227 class="directory">/home/hg/repos</filename>, and
1228 <literal role="hg-ext">notify</literal> is considering a
1229 repository named <filename
1230 class="directory">/home/hg/repos/shared/test</filename>,
1231 setting <envar role="rc-item-notify">strip</envar> to
1232 <literal>4</literal> will cause <literal
1233 role="hg-ext">notify</literal> to trim the path it
1234 considers down to <filename
1235 class="directory">shared/test</filename>, and it will
1236 match subscribers against that.
1237 </para>
1238 </listitem>
1239 <listitem><para><envar
1240 role="rc-item-notify">template</envar>: The template
1241 text to use when sending messages. This specifies both
1242 the contents of the message header and its body.
1243 </para>
1244 </listitem>
1245 <listitem><para><envar
1246 role="rc-item-notify">maxdiff</envar>: The maximum
1247 number of lines of diff data to append to the end of a
1248 message. If a diff is longer than this, it is
1249 truncated. By default, this is set to 300. Set this to
1250 <literal>0</literal> to omit diffs from notification
1251 emails.
1252 </para>
1253 </listitem>
1254 <listitem><para><envar
1255 role="rc-item-notify">sources</envar>: A list of
1256 sources of changesets to consider. This lets you limit
1257 <literal role="hg-ext">notify</literal> to only sending
1258 out email about changes that remote users pushed into
1259 this repository via a server, for example. See section
1260 <xref
1261 linkend="sec:hook:sources"/> for the sources you can
1262 specify here.
1263 </para>
1264 </listitem></itemizedlist>
1266 <para>If you set the <envar role="rc-item-web">baseurl</envar>
1267 item in the <literal role="rc-web">web</literal> section,
1268 you can use it in a template; it will be available as
1269 <literal>webroot</literal>.
1270 </para>
1272 <para>Here is an example set of <literal
1273 role="hg-ext">notify</literal> configuration information.
1274 </para>
1275 <programlisting>
1276 [notify] # really send email test = false # subscriber data
1277 lives in the notify repo config =
1278 /home/hg/repos/notify/notify.conf # repos live in
1279 /home/hg/repos on server, so strip 4 "/" chars strip = 4
1280 template = X-Hg-Repo: {webroot} Subject: {webroot}:
1281 {desc|firstline|strip} From: {author} changeset {node|short}
1282 in {root} details:
1283 {baseurl}{webroot}?cmd=changeset;node={node|short}
1284 description: {desc|tabindent|strip} [web] baseurl =
1285 http://hg.example.com/
1286 </programlisting>
1288 <para>This will produce a message that looks like the
1289 following:
1290 </para>
1291 <programlisting>
1292 X-Hg-Repo: tests/slave Subject: tests/slave: Handle error
1293 case when slave has no buffers Date: Wed, 2 Aug 2006
1294 15:25:46 -0700 (PDT) changeset 3cba9bfe74b5 in
1295 /home/hg/repos/tests/slave details:
1296 http://hg.example.com/tests/slave?cmd=changeset;node=3cba9bfe74b5
1297 description: Handle error case when slave has no buffers
1298 diffs (54 lines): diff -r 9d95df7cf2ad -r 3cba9bfe74b5
1299 include/tests.h --- a/include/tests.h Wed Aug 02
1300 15:19:52 2006 -0700 +++ b/include/tests.h Wed Aug 02
1301 15:25:26 2006 -0700 @@ -212,6 +212,15 @@ static __inline__
1302 void test_headers(void *h) [...snip...]
1303 </programlisting>
1305 </sect3>
1306 <sect3>
1307 <title>Testing and troubleshooting</title>
1309 <para>Do not forget that by default, the <literal
1310 role="hg-ext">notify</literal> extension \emph{will not
1311 send any mail} until you explicitly configure it to do so,
1312 by setting <envar role="rc-item-notify">test</envar> to
1313 <literal>false</literal>. Until you do that, it simply
1314 prints the message it <emphasis>would</emphasis> send.
1315 </para>
1317 </sect3>
1318 </sect2>
1319 </sect1>
1320 <sect1 id="sec:hook:ref">
1321 <title>Information for writers of hooks</title>
1323 <sect2>
1324 <title>In-process hook execution</title>
1326 <para>An in-process hook is called with arguments of the
1327 following form:
1328 </para>
1329 <programlisting>
1330 def myhook(ui, repo, **kwargs): pass
1331 </programlisting>
1332 <para>The <literal>ui</literal> parameter is a <literal
1333 role="py-mod-mercurial.ui">ui</literal> object. The
1334 <literal>repo</literal> parameter is a <literal
1335 role="py-mod-mercurial.localrepo">localrepository</literal>
1336 object. The names and values of the
1337 <literal>**kwargs</literal> parameters depend on the hook
1338 being invoked, with the following common features:
1339 </para>
1340 <itemizedlist>
1341 <listitem><para>If a parameter is named
1342 <literal>node</literal> or <literal>parentN</literal>, it
1343 will contain a hexadecimal changeset ID. The empty string
1344 is used to represent <quote>null changeset ID</quote>
1345 instead of a string of zeroes.
1346 </para>
1347 </listitem>
1348 <listitem><para>If a parameter is named
1349 <literal>url</literal>, it will contain the URL of a
1350 remote repository, if that can be determined.
1351 </para>
1352 </listitem>
1353 <listitem><para>Boolean-valued parameters are represented as
1354 Python <literal>bool</literal> objects.
1355 </para>
1356 </listitem></itemizedlist>
1358 <para>An in-process hook is called without a change to the
1359 process's working directory (unlike external hooks, which are
1360 run in the root of the repository). It must not change the
1361 process's working directory, or it will cause any calls it
1362 makes into the Mercurial API to fail.
1363 </para>
1365 <para>If a hook returns a boolean <quote>false</quote> value, it
1366 is considered to have succeeded. If it returns a boolean
1367 <quote>true</quote> value or raises an exception, it is
1368 considered to have failed. A useful way to think of the
1369 calling convention is <quote>tell me if you fail</quote>.
1370 </para>
1372 <para>Note that changeset IDs are passed into Python hooks as
1373 hexadecimal strings, not the binary hashes that Mercurial's
1374 APIs normally use. To convert a hash from hex to binary, use
1375 the \pymodfunc{mercurial.node}{bin} function.
1376 </para>
1378 </sect2>
1379 <sect2>
1380 <title>External hook execution</title>
1382 <para>An external hook is passed to the shell of the user
1383 running Mercurial. Features of that shell, such as variable
1384 substitution and command redirection, are available. The hook
1385 is run in the root directory of the repository (unlike
1386 in-process hooks, which are run in the same directory that
1387 Mercurial was run in).
1388 </para>
1390 <para>Hook parameters are passed to the hook as environment
1391 variables. Each environment variable's name is converted in
1392 upper case and prefixed with the string
1393 <quote><literal>HG_</literal></quote>. For example, if the
1394 name of a parameter is <quote><literal>node</literal></quote>,
1395 the name of the environment variable representing that
1396 parameter will be <quote><literal>HG_NODE</literal></quote>.
1397 </para>
1399 <para>A boolean parameter is represented as the string
1400 <quote><literal>1</literal></quote> for <quote>true</quote>,
1401 <quote><literal>0</literal></quote> for <quote>false</quote>.
1402 If an environment variable is named <envar>HG_NODE</envar>,
1403 <envar>HG_PARENT1</envar> or <envar>HG_PARENT2</envar>, it
1404 contains a changeset ID represented as a hexadecimal string.
1405 The empty string is used to represent <quote>null changeset
1406 ID</quote> instead of a string of zeroes. If an environment
1407 variable is named <envar>HG_URL</envar>, it will contain the
1408 URL of a remote repository, if that can be determined.
1409 </para>
1411 <para>If a hook exits with a status of zero, it is considered to
1412 have succeeded. If it exits with a non-zero status, it is
1413 considered to have failed.
1414 </para>
1416 </sect2>
1417 <sect2>
1418 <title>Finding out where changesets come from</title>
1420 <para>A hook that involves the transfer of changesets between a
1421 local repository and another may be able to find out
1422 information about the <quote>far side</quote>. Mercurial
1423 knows <emphasis>how</emphasis> changes are being transferred,
1424 and in many cases <emphasis>where</emphasis> they are being
1425 transferred to or from.
1426 </para>
1428 <sect3 id="sec:hook:sources">
1429 <title>Sources of changesets</title>
1431 <para>Mercurial will tell a hook what means are, or were, used
1432 to transfer changesets between repositories. This is
1433 provided by Mercurial in a Python parameter named
1434 <literal>source</literal>, or an environment variable named
1435 <envar>HG_SOURCE</envar>.
1436 </para>
1438 <itemizedlist>
1439 <listitem><para><literal>serve</literal>: Changesets are
1440 transferred to or from a remote repository over http or
1441 ssh.
1442 </para>
1443 </listitem>
1444 <listitem><para><literal>pull</literal>: Changesets are
1445 being transferred via a pull from one repository into
1446 another.
1447 </para>
1448 </listitem>
1449 <listitem><para><literal>push</literal>: Changesets are
1450 being transferred via a push from one repository into
1451 another.
1452 </para>
1453 </listitem>
1454 <listitem><para><literal>bundle</literal>: Changesets are
1455 being transferred to or from a bundle.
1456 </para>
1457 </listitem></itemizedlist>
1459 </sect3>
1460 <sect3 id="sec:hook:url">
1461 <title>Where changes are going&emdash;remote repository
1462 URLs</title>
1464 <para>When possible, Mercurial will tell a hook the location
1465 of the <quote>far side</quote> of an activity that transfers
1466 changeset data between repositories. This is provided by
1467 Mercurial in a Python parameter named
1468 <literal>url</literal>, or an environment variable named
1469 <envar>HG_URL</envar>.
1470 </para>
1472 <para>This information is not always known. If a hook is
1473 invoked in a repository that is being served via http or
1474 ssh, Mercurial cannot tell where the remote repository is,
1475 but it may know where the client is connecting from. In
1476 such cases, the URL will take one of the following forms:
1477 </para>
1478 <itemizedlist>
1479 <listitem><para><literal>remote:ssh:1.2.3.4</literal>&emdash;remote
1480 ssh client, at the IP address
1481 <literal>1.2.3.4</literal>.
1482 </para>
1483 </listitem>
1484 <listitem><para><literal>remote:http:1.2.3.4</literal>&emdash;remote
1485 http client, at the IP address
1486 <literal>1.2.3.4</literal>. If the client is using SSL,
1487 this will be of the form
1488 <literal>remote:https:1.2.3.4</literal>.
1489 </para>
1490 </listitem>
1491 <listitem><para>Empty&emdash;no information could be
1492 discovered about the remote client.
1493 </para>
1494 </listitem></itemizedlist>
1496 </sect3>
1497 </sect2>
1498 </sect1>
1499 <sect1>
1500 <title>Hook reference</title>
1502 <sect2 id="sec:hook:changegroup">
1503 <title><literal role="hook">changegroup</literal>&emdash;after
1504 remote changesets added</title>
1506 <para>This hook is run after a group of pre-existing changesets
1507 has been added to the repository, for example via a <command
1508 role="hg-cmd">hg pull</command> or <command role="hg-cmd">hg
1509 unbundle</command>. This hook is run once per operation
1510 that added one or more changesets. This is in contrast to the
1511 <literal role="hook">incoming</literal> hook, which is run
1512 once per changeset, regardless of whether the changesets
1513 arrive in a group.
1514 </para>
1516 <para>Some possible uses for this hook include kicking off an
1517 automated build or test of the added changesets, updating a
1518 bug database, or notifying subscribers that a repository
1519 contains new changes.
1520 </para>
1522 <para>Parameters to this hook:
1523 </para>
1524 <itemizedlist>
1525 <listitem><para><literal>node</literal>: A changeset ID. The
1526 changeset ID of the first changeset in the group that was
1527 added. All changesets between this and
1528 \index{tags!<literal>tip</literal>}<literal>tip</literal>,
1529 inclusive, were added by a single <command
1530 role="hg-cmd">hg pull</command>, <command
1531 role="hg-cmd">hg push</command> or <command
1532 role="hg-cmd">hg unbundle</command>.
1533 </para>
1534 </listitem>
1535 <listitem><para><literal>source</literal>: A string. The
1536 source of these changes. See section <xref
1537 linkend="sec:hook:sources"/> for details.
1538 </para>
1539 </listitem>
1540 <listitem><para><literal>url</literal>: A URL. The location
1541 of the remote repository, if known. See section <xref
1542 linkend="sec:hook:url"/> for more
1543 information.
1544 </para>
1545 </listitem></itemizedlist>
1547 <para>See also: <literal role="hook">incoming</literal> (section
1548 <xref linkend="sec:hook:incoming"/>), <literal
1549 role="hook">prechangegroup</literal> (section <xref
1550 linkend="sec:hook:prechangegroup"/>), <literal
1551 role="hook">pretxnchangegroup</literal> (section <xref
1552 linkend="sec:hook:pretxnchangegroup"/>)
1553 </para>
1555 </sect2>
1556 <sect2 id="sec:hook:commit">
1557 <title><literal role="hook">commit</literal>&emdash;after a new
1558 changeset is created</title>
1560 <para>This hook is run after a new changeset has been created.
1561 </para>
1563 <para>Parameters to this hook:
1564 </para>
1565 <itemizedlist>
1566 <listitem><para><literal>node</literal>: A changeset ID. The
1567 changeset ID of the newly committed changeset.
1568 </para>
1569 </listitem>
1570 <listitem><para><literal>parent1</literal>: A changeset ID.
1571 The changeset ID of the first parent of the newly
1572 committed changeset.
1573 </para>
1574 </listitem>
1575 <listitem><para><literal>parent2</literal>: A changeset ID.
1576 The changeset ID of the second parent of the newly
1577 committed changeset.
1578 </para>
1579 </listitem></itemizedlist>
1581 <para>See also: <literal role="hook">precommit</literal>
1582 (section <xref linkend="sec:hook:precommit"/>), <literal
1583 role="hook">pretxncommit</literal> (section <xref
1584 linkend="sec:hook:pretxncommit"/>)
1585 </para>
1587 </sect2>
1588 <sect2 id="sec:hook:incoming">
1589 <title><literal role="hook">incoming</literal>&emdash;after one
1590 remote changeset is added</title>
1592 <para>This hook is run after a pre-existing changeset has been
1593 added to the repository, for example via a <command
1594 role="hg-cmd">hg push</command>. If a group of changesets
1595 was added in a single operation, this hook is called once for
1596 each added changeset.
1597 </para>
1599 <para>You can use this hook for the same purposes as the
1600 <literal role="hook">changegroup</literal> hook (section <xref
1601 linkend="sec:hook:changegroup"/>); it's simply
1602 more convenient sometimes to run a hook once per group of
1603 changesets, while other times it's handier once per changeset.
1604 </para>
1606 <para>Parameters to this hook:
1607 </para>
1608 <itemizedlist>
1609 <listitem><para><literal>node</literal>: A changeset ID. The
1610 ID of the newly added changeset.
1611 </para>
1612 </listitem>
1613 <listitem><para><literal>source</literal>: A string. The
1614 source of these changes. See section <xref
1615 linkend="sec:hook:sources"/> for details.
1616 </para>
1617 </listitem>
1618 <listitem><para><literal>url</literal>: A URL. The location
1619 of the remote repository, if known. See section <xref
1620 linkend="sec:hook:url"/> for more
1621 information.
1622 </para>
1623 </listitem></itemizedlist>
1625 <para>See also: <literal role="hook">changegroup</literal>
1626 (section <xref linkend="sec:hook:changegroup"/>) <literal
1627 role="hook">prechangegroup</literal> (section <xref
1628 linkend="sec:hook:prechangegroup"/>), <literal
1629 role="hook">pretxnchangegroup</literal> (section <xref
1630 linkend="sec:hook:pretxnchangegroup"/>)
1631 </para>
1633 </sect2>
1634 <sect2 id="sec:hook:outgoing">
1635 <title><literal role="hook">outgoing</literal>&emdash;after
1636 changesets are propagated</title>
1638 <para>This hook is run after a group of changesets has been
1639 propagated out of this repository, for example by a <command
1640 role="hg-cmd">hg push</command> or <command role="hg-cmd">hg
1641 bundle</command> command.
1642 </para>
1644 <para>One possible use for this hook is to notify administrators
1645 that changes have been pulled.
1646 </para>
1648 <para>Parameters to this hook:
1649 </para>
1650 <itemizedlist>
1651 <listitem><para><literal>node</literal>: A changeset ID. The
1652 changeset ID of the first changeset of the group that was
1653 sent.
1654 </para>
1655 </listitem>
1656 <listitem><para><literal>source</literal>: A string. The
1657 source of the of the operation (see section <xref
1658 linkend="sec:hook:sources"/>). If a remote
1659 client pulled changes from this repository,
1660 <literal>source</literal> will be
1661 <literal>serve</literal>. If the client that obtained
1662 changes from this repository was local,
1663 <literal>source</literal> will be
1664 <literal>bundle</literal>, <literal>pull</literal>, or
1665 <literal>push</literal>, depending on the operation the
1666 client performed.
1667 </para>
1668 </listitem>
1669 <listitem><para><literal>url</literal>: A URL. The location
1670 of the remote repository, if known. See section <xref
1671 linkend="sec:hook:url"/> for more
1672 information.
1673 </para>
1674 </listitem></itemizedlist>
1676 <para>See also: <literal role="hook">preoutgoing</literal>
1677 (section <xref linkend="sec:hook:preoutgoing"/>)
1678 </para>
1680 </sect2>
1681 <sect2 id="sec:hook:prechangegroup">
1682 <title><literal
1683 role="hook">prechangegroup</literal>&emdash;before starting
1684 to add remote changesets</title>
1686 <para>This controlling hook is run before Mercurial begins to
1687 add a group of changesets from another repository.
1688 </para>
1690 <para>This hook does not have any information about the
1691 changesets to be added, because it is run before transmission
1692 of those changesets is allowed to begin. If this hook fails,
1693 the changesets will not be transmitted.
1694 </para>
1696 <para>One use for this hook is to prevent external changes from
1697 being added to a repository. For example, you could use this
1698 to <quote>freeze</quote> a server-hosted branch temporarily or
1699 permanently so that users cannot push to it, while still
1700 allowing a local administrator to modify the repository.
1701 </para>
1703 <para>Parameters to this hook:
1704 </para>
1705 <itemizedlist>
1706 <listitem><para><literal>source</literal>: A string. The
1707 source of these changes. See section <xref
1708 linkend="sec:hook:sources"/> for details.
1709 </para>
1710 </listitem>
1711 <listitem><para><literal>url</literal>: A URL. The location
1712 of the remote repository, if known. See section <xref
1713 linkend="sec:hook:url"/> for more
1714 information.
1715 </para>
1716 </listitem></itemizedlist>
1718 <para>See also: <literal role="hook">changegroup</literal>
1719 (section <xref linkend="sec:hook:changegroup"/>), <literal
1720 role="hook">incoming</literal> (section <xref
1721 linkend="sec:hook:incoming"/>), , <literal
1722 role="hook">pretxnchangegroup</literal> (section <xref
1723 linkend="sec:hook:pretxnchangegroup"/>)
1724 </para>
1726 </sect2>
1727 <sect2 id="sec:hook:precommit">
1728 <title><literal role="hook">precommit</literal>&emdash;before
1729 starting to commit a changeset</title>
1731 <para>This hook is run before Mercurial begins to commit a new
1732 changeset. It is run before Mercurial has any of the metadata
1733 for the commit, such as the files to be committed, the commit
1734 message, or the commit date.
1735 </para>
1737 <para>One use for this hook is to disable the ability to commit
1738 new changesets, while still allowing incoming changesets.
1739 Another is to run a build or test, and only allow the commit
1740 to begin if the build or test succeeds.
1741 </para>
1743 <para>Parameters to this hook:
1744 </para>
1745 <itemizedlist>
1746 <listitem><para><literal>parent1</literal>: A changeset ID.
1747 The changeset ID of the first parent of the working
1748 directory.
1749 </para>
1750 </listitem>
1751 <listitem><para><literal>parent2</literal>: A changeset ID.
1752 The changeset ID of the second parent of the working
1753 directory.
1754 </para>
1755 </listitem></itemizedlist>
1756 <para>If the commit proceeds, the parents of the working
1757 directory will become the parents of the new changeset.
1758 </para>
1760 <para>See also: <literal role="hook">commit</literal> (section
1761 <xref linkend="sec:hook:commit"/>), <literal
1762 role="hook">pretxncommit</literal> (section <xref
1763 linkend="sec:hook:pretxncommit"/>)
1764 </para>
1766 </sect2>
1767 <sect2 id="sec:hook:preoutgoing">
1768 <title><literal role="hook">preoutgoing</literal>&emdash;before
1769 starting to propagate changesets</title>
1771 <para>This hook is invoked before Mercurial knows the identities
1772 of the changesets to be transmitted.
1773 </para>
1775 <para>One use for this hook is to prevent changes from being
1776 transmitted to another repository.
1777 </para>
1779 <para>Parameters to this hook:
1780 </para>
1781 <itemizedlist>
1782 <listitem><para><literal>source</literal>: A string. The
1783 source of the operation that is attempting to obtain
1784 changes from this repository (see section <xref
1785 linkend="sec:hook:sources"/>). See the documentation
1786 for the <literal>source</literal> parameter to the
1787 <literal role="hook">outgoing</literal> hook, in section
1788 <xref linkend="sec:hook:outgoing"/>, for possible values
1789 of
1790 this parameter.
1791 </para>
1792 </listitem>
1793 <listitem><para><literal>url</literal>: A URL. The location
1794 of the remote repository, if known. See section <xref
1795 linkend="sec:hook:url"/> for more
1796 information.
1797 </para>
1798 </listitem></itemizedlist>
1800 <para>See also: <literal role="hook">outgoing</literal> (section
1801 <xref linkend="sec:hook:outgoing"/>)
1802 </para>
1804 </sect2>
1805 <sect2 id="sec:hook:pretag">
1806 <title><literal role="hook">pretag</literal>&emdash;before
1807 tagging a changeset</title>
1809 <para>This controlling hook is run before a tag is created. If
1810 the hook succeeds, creation of the tag proceeds. If the hook
1811 fails, the tag is not created.
1812 </para>
1814 <para>Parameters to this hook:
1815 </para>
1816 <itemizedlist>
1817 <listitem><para><literal>local</literal>: A boolean. Whether
1818 the tag is local to this repository instance (i.e. stored
1819 in <filename role="special">.hg/localtags</filename>) or
1820 managed by Mercurial (stored in <filename
1821 role="special">.hgtags</filename>).
1822 </para>
1823 </listitem>
1824 <listitem><para><literal>node</literal>: A changeset ID. The
1825 ID of the changeset to be tagged.
1826 </para>
1827 </listitem>
1828 <listitem><para><literal>tag</literal>: A string. The name of
1829 the tag to be created.
1830 </para>
1831 </listitem></itemizedlist>
1833 <para>If the tag to be created is revision-controlled, the
1834 <literal role="hook">precommit</literal> and <literal
1835 role="hook">pretxncommit</literal> hooks (sections <xref
1836 linkend="sec:hook:commit"/> and <xref
1837 linkend="sec:hook:pretxncommit"/>) will also be run.
1838 </para>
1840 <para>See also: <literal role="hook">tag</literal> (section
1841 <xref linkend="sec:hook:tag"/>)
1842 </para>
1843 </sect2>
1844 <sect2 id="sec:hook:pretxnchangegroup">
1845 <title><literal
1846 role="hook">pretxnchangegroup</literal>&emdash;before
1847 completing addition of remote changesets</title>
1849 <para>This controlling hook is run before a
1850 transaction&emdash;that manages the addition of a group of new
1851 changesets from outside the repository&emdash;completes. If
1852 the hook succeeds, the transaction completes, and all of the
1853 changesets become permanent within this repository. If the
1854 hook fails, the transaction is rolled back, and the data for
1855 the changesets is erased.
1856 </para>
1858 <para>This hook can access the metadata associated with the
1859 almost-added changesets, but it should not do anything
1860 permanent with this data. It must also not modify the working
1861 directory.
1862 </para>
1864 <para>While this hook is running, if other Mercurial processes
1865 access this repository, they will be able to see the
1866 almost-added changesets as if they are permanent. This may
1867 lead to race conditions if you do not take steps to avoid
1868 them.
1869 </para>
1871 <para>This hook can be used to automatically vet a group of
1872 changesets. If the hook fails, all of the changesets are
1873 <quote>rejected</quote> when the transaction rolls back.
1874 </para>
1876 <para>Parameters to this hook:
1877 </para>
1878 <itemizedlist>
1879 <listitem><para><literal>node</literal>: A changeset ID. The
1880 changeset ID of the first changeset in the group that was
1881 added. All changesets between this and
1882 \index{tags!<literal>tip</literal>}<literal>tip</literal>,
1883 inclusive, were added by a single <command
1884 role="hg-cmd">hg pull</command>, <command
1885 role="hg-cmd">hg push</command> or <command
1886 role="hg-cmd">hg unbundle</command>.
1887 </para>
1888 </listitem>
1889 <listitem><para><literal>source</literal>: A string. The
1890 source of these changes. See section <xref
1891 linkend="sec:hook:sources"/> for details.
1892 </para>
1893 </listitem>
1894 <listitem><para><literal>url</literal>: A URL. The location
1895 of the remote repository, if known. See section <xref
1896 linkend="sec:hook:url"/> for more
1897 information.
1898 </para>
1899 </listitem></itemizedlist>
1901 <para>See also: <literal role="hook">changegroup</literal>
1902 (section <xref linkend="sec:hook:changegroup"/>), <literal
1903 role="hook">incoming</literal> (section <xref
1904 linkend="sec:hook:incoming"/>), <literal
1905 role="hook">prechangegroup</literal> (section <xref
1906 linkend="sec:hook:prechangegroup"/>)
1907 </para>
1909 </sect2>
1910 <sect2 id="sec:hook:pretxncommit">
1911 <title><literal role="hook">pretxncommit</literal>&emdash;before
1912 completing commit of new changeset</title>
1914 <para>This controlling hook is run before a
1915 transaction&emdash;that manages a new commit&emdash;completes.
1916 If the hook succeeds, the transaction completes and the
1917 changeset becomes permanent within this repository. If the
1918 hook fails, the transaction is rolled back, and the commit
1919 data is erased.
1920 </para>
1922 <para>This hook can access the metadata associated with the
1923 almost-new changeset, but it should not do anything permanent
1924 with this data. It must also not modify the working
1925 directory.
1926 </para>
1928 <para>While this hook is running, if other Mercurial processes
1929 access this repository, they will be able to see the
1930 almost-new changeset as if it is permanent. This may lead to
1931 race conditions if you do not take steps to avoid them.
1932 </para>
1934 <para>Parameters to this hook:
1935 </para>
1936 <itemizedlist>
1937 <listitem><para><literal>node</literal>: A changeset ID. The
1938 changeset ID of the newly committed changeset.
1939 </para>
1940 </listitem>
1941 <listitem><para><literal>parent1</literal>: A changeset ID.
1942 The changeset ID of the first parent of the newly
1943 committed changeset.
1944 </para>
1945 </listitem>
1946 <listitem><para><literal>parent2</literal>: A changeset ID.
1947 The changeset ID of the second parent of the newly
1948 committed changeset.
1949 </para>
1950 </listitem></itemizedlist>
1952 <para>See also: <literal role="hook">precommit</literal>
1953 (section <xref linkend="sec:hook:precommit"/>)
1954 </para>
1956 </sect2>
1957 <sect2 id="sec:hook:preupdate">
1958 <title><literal role="hook">preupdate</literal>&emdash;before
1959 updating or merging working directory</title>
1961 <para>This controlling hook is run before an update or merge of
1962 the working directory begins. It is run only if Mercurial's
1963 normal pre-update checks determine that the update or merge
1964 can proceed. If the hook succeeds, the update or merge may
1965 proceed; if it fails, the update or merge does not start.
1966 </para>
1968 <para>Parameters to this hook:
1969 </para>
1970 <itemizedlist>
1971 <listitem><para><literal>parent1</literal>: A changeset ID.
1972 The ID of the parent that the working directory is to be
1973 updated to. If the working directory is being merged, it
1974 will not change this parent.
1975 </para>
1976 </listitem>
1977 <listitem><para><literal>parent2</literal>: A changeset ID.
1978 Only set if the working directory is being merged. The ID
1979 of the revision that the working directory is being merged
1980 with.
1981 </para>
1982 </listitem></itemizedlist>
1984 <para>See also: <literal role="hook">update</literal> (section
1985 <xref linkend="sec:hook:update"/>)
1986 </para>
1988 </sect2>
1989 <sect2 id="sec:hook:tag">
1990 <title><literal role="hook">tag</literal>&emdash;after tagging a
1991 changeset</title>
1993 <para>This hook is run after a tag has been created.
1994 </para>
1996 <para>Parameters to this hook:
1997 </para>
1998 <itemizedlist>
1999 <listitem><para><literal>local</literal>: A boolean. Whether
2000 the new tag is local to this repository instance (i.e.
2001 stored in <filename
2002 role="special">.hg/localtags</filename>) or managed by
2003 Mercurial (stored in <filename
2004 role="special">.hgtags</filename>).
2005 </para>
2006 </listitem>
2007 <listitem><para><literal>node</literal>: A changeset ID. The
2008 ID of the changeset that was tagged.
2009 </para>
2010 </listitem>
2011 <listitem><para><literal>tag</literal>: A string. The name of
2012 the tag that was created.
2013 </para>
2014 </listitem></itemizedlist>
2016 <para>If the created tag is revision-controlled, the <literal
2017 role="hook">commit</literal> hook (section <xref
2018 linkend="sec:hook:commit"/>) is run before this hook.
2019 </para>
2021 <para>See also: <literal role="hook">pretag</literal> (section
2022 <xref linkend="sec:hook:pretag"/>)
2023 </para>
2025 </sect2>
2026 <sect2 id="sec:hook:update">
2027 <title><literal role="hook">update</literal>&emdash;after
2028 updating or merging working directory</title>
2030 <para>This hook is run after an update or merge of the working
2031 directory completes. Since a merge can fail (if the external
2032 <command>hgmerge</command> command fails to resolve conflicts
2033 in a file), this hook communicates whether the update or merge
2034 completed cleanly.
2035 </para>
2037 <itemizedlist>
2038 <listitem><para><literal>error</literal>: A boolean.
2039 Indicates whether the update or merge completed
2040 successfully.
2041 </para>
2042 </listitem>
2043 <listitem><para><literal>parent1</literal>: A changeset ID.
2044 The ID of the parent that the working directory was
2045 updated to. If the working directory was merged, it will
2046 not have changed this parent.
2047 </para>
2048 </listitem>
2049 <listitem><para><literal>parent2</literal>: A changeset ID.
2050 Only set if the working directory was merged. The ID of
2051 the revision that the working directory was merged with.
2052 </para>
2053 </listitem></itemizedlist>
2055 <para>See also: <literal role="hook">preupdate</literal>
2056 (section <xref linkend="sec:hook:preupdate"/>)
2057 </para>
2059 </sect2>
2060 </sect1>
2061 </chapter>
2063 <!--
2064 local variables:
2065 sgml-parent-document: ("00book.xml" "book" "chapter")
2066 end:
2067 -->