hgbook

view en/ch10-hook.xml @ 625:cfdb601a3c8b

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