blob: 912957de678cf1867c8f72aa333d12a83fd843ae [file] [log] [blame]
Junio C Hamano1a4e8412005-12-27 08:17:231<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
2 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Junio C Hamano818f7d62006-03-26 01:49:306<meta name="generator" content="AsciiDoc 7.0.2" />
Junio C Hamano1a4e8412005-12-27 08:17:237<style type="text/css">
8/* Debug borders */
9p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
10/*
11 border: 1px solid red;
12*/
13}
14
15body {
16 margin: 1em 5% 1em 5%;
17}
18
19a { color: blue; }
20a:visited { color: fuchsia; }
21
22em {
23 font-style: italic;
24}
25
26strong {
27 font-weight: bold;
28}
29
30tt {
31 color: navy;
32}
33
34h1, h2, h3, h4, h5, h6 {
35 color: #527bbd;
36 font-family: sans-serif;
37 margin-top: 1.2em;
38 margin-bottom: 0.5em;
39 line-height: 1.3;
40}
41
42h1 {
43 border-bottom: 2px solid silver;
44}
45h2 {
46 border-bottom: 2px solid silver;
47 padding-top: 0.5em;
48}
49
50div.sectionbody {
51 font-family: serif;
52 margin-left: 0;
53}
54
55hr {
56 border: 1px solid silver;
57}
58
59p {
60 margin-top: 0.5em;
61 margin-bottom: 0.5em;
62}
63
64pre {
65 padding: 0;
66 margin: 0;
67}
68
69span#author {
70 color: #527bbd;
71 font-family: sans-serif;
72 font-weight: bold;
73 font-size: 1.2em;
74}
75span#email {
76}
77span#revision {
78 font-family: sans-serif;
79}
80
81div#footer {
82 font-family: sans-serif;
83 font-size: small;
84 border-top: 2px solid silver;
85 padding-top: 0.5em;
86 margin-top: 4.0em;
87}
88div#footer-text {
89 float: left;
90 padding-bottom: 0.5em;
91}
92div#footer-badges {
93 float: right;
94 padding-bottom: 0.5em;
95}
96
97div#preamble,
98div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
99div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
100div.admonitionblock {
101 margin-right: 10%;
102 margin-top: 1.5em;
103 margin-bottom: 1.5em;
104}
105div.admonitionblock {
106 margin-top: 2.5em;
107 margin-bottom: 2.5em;
108}
109
110div.content { /* Block element content. */
111 padding: 0;
112}
113
114/* Block element titles. */
115div.title, caption.title {
116 font-family: sans-serif;
117 font-weight: bold;
118 text-align: left;
119 margin-top: 1.0em;
120 margin-bottom: 0.5em;
121}
122div.title + * {
123 margin-top: 0;
124}
125
126td div.title:first-child {
127 margin-top: 0.0em;
128}
129div.content div.title:first-child {
130 margin-top: 0.0em;
131}
132div.content + div.title {
133 margin-top: 0.0em;
134}
135
136div.sidebarblock > div.content {
137 background: #ffffee;
138 border: 1px solid silver;
139 padding: 0.5em;
140}
141
142div.listingblock > div.content {
143 border: 1px solid silver;
144 background: #f4f4f4;
145 padding: 0.5em;
146}
147
148div.quoteblock > div.content {
149 padding-left: 2.0em;
150}
151div.quoteblock .attribution {
152 text-align: right;
153}
154
155div.admonitionblock .icon {
156 vertical-align: top;
157 font-size: 1.1em;
158 font-weight: bold;
159 text-decoration: underline;
160 color: #527bbd;
161 padding-right: 0.5em;
162}
163div.admonitionblock td.content {
164 padding-left: 0.5em;
165 border-left: 2px solid silver;
166}
167
168div.exampleblock > div.content {
169 border-left: 2px solid silver;
170 padding: 0.5em;
171}
172
173div.verseblock div.content {
174 white-space: pre;
175}
176
177div.imageblock div.content { padding-left: 0; }
178div.imageblock img { border: 1px solid silver; }
179span.image img { border-style: none; }
180
181dl {
182 margin-top: 0.8em;
183 margin-bottom: 0.8em;
184}
185dt {
186 margin-top: 0.5em;
187 margin-bottom: 0;
188 font-style: italic;
189}
190dd > *:first-child {
191 margin-top: 0;
192}
193
194ul, ol {
195 list-style-position: outside;
196}
197ol.olist2 {
198 list-style-type: lower-alpha;
199}
200
201div.tableblock > table {
202 border-color: #527bbd;
203 border-width: 3px;
204}
205thead {
206 font-family: sans-serif;
207 font-weight: bold;
208}
209tfoot {
210 font-weight: bold;
211}
212
213div.hlist {
214 margin-top: 0.8em;
215 margin-bottom: 0.8em;
216}
217td.hlist1 {
218 vertical-align: top;
219 font-style: italic;
220 padding-right: 0.8em;
221}
222td.hlist2 {
223 vertical-align: top;
224}
225
226@media print {
227 div#footer-badges { display: none; }
228}
229/* Workarounds for IE6's broken and incomplete CSS2. */
230
231div.sidebar-content {
232 background: #ffffee;
233 border: 1px solid silver;
234 padding: 0.5em;
235}
236div.sidebar-title, div.image-title {
237 font-family: sans-serif;
238 font-weight: bold;
239 margin-top: 0.0em;
240 margin-bottom: 0.5em;
241}
242
243div.listingblock div.content {
244 border: 1px solid silver;
245 background: #f4f4f4;
246 padding: 0.5em;
247}
248
249div.quoteblock-content {
250 padding-left: 2.0em;
251}
252
253div.exampleblock-content {
254 border-left: 2px solid silver;
255 padding-left: 0.5em;
256}
257</style>
258<title>Hooks used by git</title>
259</head>
260<body>
261<div id="header">
262<h1>Hooks used by git</h1>
263</div>
264<div id="preamble">
265<div class="sectionbody">
266<p>Hooks are little scripts you can place in <tt>$GIT_DIR/hooks</tt>
267directory to trigger action at certain points. When
Junio C Hamano24351a82007-01-13 08:09:17268<tt>git-init</tt> is run, a handful example hooks are copied in the
Junio C Hamano1a4e8412005-12-27 08:17:23269<tt>hooks</tt> directory of the new repository, but by default they are
Junio C Hamanod5784132006-09-20 21:29:27270all disabled. To enable a hook, make it executable with <tt>chmod +x</tt>.</p>
Junio C Hamano1a4e8412005-12-27 08:17:23271<p>This document describes the currently defined hooks.</p>
272</div>
273</div>
274<h2>applypatch-msg</h2>
275<div class="sectionbody">
Junio C Hamano38b693c2007-06-03 08:40:14276<p>This hook is invoked by <tt>git-am</tt> script. It takes a single
Junio C Hamano1a4e8412005-12-27 08:17:23277parameter, the name of the file that holds the proposed commit
Junio C Hamanod5784132006-09-20 21:29:27278log message. Exiting with non-zero status causes
Junio C Hamano38b693c2007-06-03 08:40:14279<tt>git-am</tt> to abort before applying the patch.</p>
Junio C Hamano1a4e8412005-12-27 08:17:23280<p>The hook is allowed to edit the message file in place, and can
281be used to normalize the message into some project standard
282format (if the project has one). It can also be used to refuse
283the commit after inspecting the message file.</p>
Junio C Hamanod5784132006-09-20 21:29:27284<p>The default <em>applypatch-msg</em> hook, when enabled, runs the
285<em>commit-msg</em> hook, if the latter is enabled.</p>
Junio C Hamano1a4e8412005-12-27 08:17:23286</div>
287<h2>pre-applypatch</h2>
288<div class="sectionbody">
Junio C Hamano38b693c2007-06-03 08:40:14289<p>This hook is invoked by <tt>git-am</tt>. It takes no parameter,
Junio C Hamano1a4e8412005-12-27 08:17:23290and is invoked after the patch is applied, but before a commit
291is made. Exiting with non-zero status causes the working tree
292after application of the patch not committed.</p>
293<p>It can be used to inspect the current working tree and refuse to
294make a commit if it does not pass certain test.</p>
Junio C Hamanod5784132006-09-20 21:29:27295<p>The default <em>pre-applypatch</em> hook, when enabled, runs the
296<em>pre-commit</em> hook, if the latter is enabled.</p>
Junio C Hamano1a4e8412005-12-27 08:17:23297</div>
298<h2>post-applypatch</h2>
299<div class="sectionbody">
Junio C Hamano38b693c2007-06-03 08:40:14300<p>This hook is invoked by <tt>git-am</tt>. It takes no parameter,
Junio C Hamano1a4e8412005-12-27 08:17:23301and is invoked after the patch is applied and a commit is made.</p>
302<p>This hook is meant primarily for notification, and cannot affect
Junio C Hamano38b693c2007-06-03 08:40:14303the outcome of <tt>git-am</tt>.</p>
Junio C Hamano1a4e8412005-12-27 08:17:23304</div>
305<h2>pre-commit</h2>
306<div class="sectionbody">
307<p>This hook is invoked by <tt>git-commit</tt>, and can be bypassed
308with <tt>--no-verify</tt> option. It takes no parameter, and is
309invoked before obtaining the proposed commit log message and
310making a commit. Exiting with non-zero status from this script
311causes the <tt>git-commit</tt> to abort.</p>
Junio C Hamanod5784132006-09-20 21:29:27312<p>The default <em>pre-commit</em> hook, when enabled, catches introduction
Junio C Hamano1a4e8412005-12-27 08:17:23313of lines with trailing whitespaces and aborts the commit when
Junio C Hamanod5784132006-09-20 21:29:27314such a line is found.</p>
Junio C Hamano26e590a2008-02-17 03:53:51315<p>All the <tt>git-commit</tt> hooks are invoked with the environment
316variable <tt>GIT_EDITOR=:</tt> if the command will not bring up an editor
317to modify the commit message.</p>
318</div>
319<h2>prepare-commit-msg</h2>
320<div class="sectionbody">
321<p>This hook is invoked by <tt>git-commit</tt> right after preparing the
322default log message, and before the editor is started.</p>
323<p>It takes one to three parameters. The first is the name of the file
324that the commit log message. The second is the source of the commit
325message, and can be: <tt>message</tt> (if a <tt>\-m</tt> or <tt>\-F</tt> option was
326given); <tt>template</tt> (if a <tt>\-t</tt> option was given or the
327configuration option <tt>commit.template</tt> is set); <tt>merge</tt> (if the
328commit is a merge or a <tt>.git/MERGE_MSG</tt> file exists); <tt>squash</tt>
329(if a <tt>.git/SQUASH_MSG</tt> file exists); or <tt>commit</tt>, followed by
330a commit SHA1 (if a <tt>\-c</tt>, <tt>\-C</tt> or <tt>--amend</tt> option was given).</p>
331<p>If the exit status is non-zero, <tt>git-commit</tt> will abort.</p>
332<p>The purpose of the hook is to edit the message file in place, and
333it is not suppressed by the <tt>--no-verify</tt> option. A non-zero exit
334means a failure of the hook and aborts the commit. It should not
335be used as replacement for pre-commit hook.</p>
336<p>The sample <tt>prepare-commit-msg</tt> hook that comes with git comments
337out the <tt>Conflicts:</tt> part of a merge's commit message.</p>
Junio C Hamano1a4e8412005-12-27 08:17:23338</div>
339<h2>commit-msg</h2>
340<div class="sectionbody">
341<p>This hook is invoked by <tt>git-commit</tt>, and can be bypassed
342with <tt>--no-verify</tt> option. It takes a single parameter, the
343name of the file that holds the proposed commit log message.
344Exiting with non-zero status causes the <tt>git-commit</tt> to
345abort.</p>
346<p>The hook is allowed to edit the message file in place, and can
347be used to normalize the message into some project standard
348format (if the project has one). It can also be used to refuse
349the commit after inspecting the message file.</p>
Junio C Hamanod5784132006-09-20 21:29:27350<p>The default <em>commit-msg</em> hook, when enabled, detects duplicate
351"Signed-off-by" lines, and aborts the commit if one is found.</p>
Junio C Hamano1a4e8412005-12-27 08:17:23352</div>
353<h2>post-commit</h2>
354<div class="sectionbody">
355<p>This hook is invoked by <tt>git-commit</tt>. It takes no
356parameter, and is invoked after a commit is made.</p>
357<p>This hook is meant primarily for notification, and cannot affect
358the outcome of <tt>git-commit</tt>.</p>
Junio C Hamano1a4e8412005-12-27 08:17:23359</div>
Junio C Hamano1b50ce92007-10-03 12:05:53360<h2>post-checkout</h2>
361<div class="sectionbody">
362<p>This hook is invoked when a <tt>git-checkout</tt> is run after having updated the
363worktree. The hook is given three parameters: the ref of the previous HEAD,
364the ref of the new HEAD (which may or may not have changed), and a flag
365indicating whether the checkout was a branch checkout (changing branches,
366flag=1) or a file checkout (retrieving a file from the index, flag=0).
367This hook cannot affect the outcome of <tt>git-checkout</tt>.</p>
368<p>This hook can be used to perform repository validity checks, auto-display
369differences from the previous HEAD if different, or set working dir metadata
370properties.</p>
371</div>
Junio C Hamano01d8f832007-09-24 07:37:30372<h2>post-merge</h2>
373<div class="sectionbody">
374<p>This hook is invoked by <tt>git-merge</tt>, which happens when a <tt>git pull</tt>
375is done on a local repository. The hook takes a single parameter, a status
376flag specifying whether or not the merge being done was a squash merge.
377This hook cannot affect the outcome of <tt>git-merge</tt>.</p>
378<p>This hook can be used in conjunction with a corresponding pre-commit hook to
379save and restore any form of metadata associated with the working tree
380(eg: permissions/ownership, ACLS, etc). See contrib/hooks/setgitperms.perl
381for an example of how to do this.</p>
382</div>
Junio C Hamano8638c922007-05-12 20:50:08383<h2><a id="pre-receive"></a>pre-receive</h2>
384<div class="sectionbody">
385<p>This hook is invoked by <tt>git-receive-pack</tt> on the remote repository,
386which happens when a <tt>git push</tt> is done on a local repository.
387Just before starting to update refs on the remote repository, the
388pre-receive hook is invoked. Its exit status determines the success
389or failure of the update.</p>
390<p>This hook executes once for the receive operation. It takes no
391arguments, but for each ref to be updated it receives on standard
392input a line of the format:</p>
393<div class="literalblock">
394<div class="content">
395<pre><tt>&lt;old-value&gt; SP &lt;new-value&gt; SP &lt;ref-name&gt; LF</tt></pre>
396</div></div>
397<p>where <tt>&lt;old-value&gt;</tt> is the old object name stored in the ref,
398<tt>&lt;new-value&gt;</tt> is the new object name to be stored in the ref and
399<tt>&lt;ref-name&gt;</tt> is the full name of the ref.
400When creating a new ref, <tt>&lt;old-value&gt;</tt> is 40 <tt>0</tt>.</p>
401<p>If the hook exits with non-zero status, none of the refs will be
402updated. If the hook exits with zero, updating of individual refs can
403still be prevented by the <a href="#update"><em>update</em></a> hook.</p>
Junio C Hamano323e52d2007-05-13 22:19:53404<p>Both standard output and standard error output are forwarded to
405<tt>git-send-pack</tt> on the other end, so you can simply <tt>echo</tt> messages
406for the user.</p>
Junio C Hamano8638c922007-05-12 20:50:08407</div>
408<h2><a id="update"></a>update</h2>
Junio C Hamano1a4e8412005-12-27 08:17:23409<div class="sectionbody">
Junio C Hamano818f7d62006-03-26 01:49:30410<p>This hook is invoked by <tt>git-receive-pack</tt> on the remote repository,
Junio C Hamanod5784132006-09-20 21:29:27411which happens when a <tt>git push</tt> is done on a local repository.
Junio C Hamano818f7d62006-03-26 01:49:30412Just before updating the ref on the remote repository, the update hook
Junio C Hamano33db4372006-06-07 19:51:45413is invoked. Its exit status determines the success or failure of
Junio C Hamano818f7d62006-03-26 01:49:30414the ref update.</p>
415<p>The hook executes once for each ref to be updated, and takes
Junio C Hamanod5784132006-09-20 21:29:27416three parameters:</p>
417<ul>
418<li>
419<p>
420the name of the ref being updated,
421</p>
422</li>
423<li>
424<p>
425the old object name stored in the ref,
426</p>
427</li>
428<li>
429<p>
430and the new objectname to be stored in the ref.
431</p>
432</li>
433</ul>
Junio C Hamano818f7d62006-03-26 01:49:30434<p>A zero exit from the update hook allows the ref to be updated.
435Exiting with a non-zero status prevents <tt>git-receive-pack</tt>
Junio C Hamano8638c922007-05-12 20:50:08436from updating that ref.</p>
Junio C Hamano818f7d62006-03-26 01:49:30437<p>This hook can be used to prevent <em>forced</em> update on certain refs by
Junio C Hamano1a4e8412005-12-27 08:17:23438making sure that the object name is a commit object that is a
439descendant of the commit object named by the old object name.
Junio C Hamano818f7d62006-03-26 01:49:30440That is, to enforce a "fast forward only" policy.</p>
441<p>It could also be used to log the old..new status. However, it
442does not know the entire set of branches, so it would end up
Junio C Hamano8638c922007-05-12 20:50:08443firing one e-mail per ref when used naively, though. The
444<a href="#post-receive"><em>post-receive</em></a> hook is more suited to that.</p>
Junio C Hamano818f7d62006-03-26 01:49:30445<p>Another use suggested on the mailing list is to use this hook to
Junio C Hamano1a4e8412005-12-27 08:17:23446implement access control which is finer grained than the one
447based on filesystem group.</p>
Junio C Hamano323e52d2007-05-13 22:19:53448<p>Both standard output and standard error output are forwarded to
449<tt>git-send-pack</tt> on the other end, so you can simply <tt>echo</tt> messages
450for the user.</p>
Junio C Hamano8638c922007-05-12 20:50:08451<p>The default <em>update</em> hook, when enabled&#8212;and with
452<tt>hooks.allowunannotated</tt> config option turned on&#8212;prevents
453unannotated tags to be pushed.</p>
Junio C Hamano1a4e8412005-12-27 08:17:23454</div>
Junio C Hamano8638c922007-05-12 20:50:08455<h2><a id="post-receive"></a>post-receive</h2>
456<div class="sectionbody">
457<p>This hook is invoked by <tt>git-receive-pack</tt> on the remote repository,
458which happens when a <tt>git push</tt> is done on a local repository.
459It executes on the remote repository once after all the refs have
460been updated.</p>
461<p>This hook executes once for the receive operation. It takes no
Junio C Hamano323e52d2007-05-13 22:19:53462arguments, but gets the same information as the
463<a href="#pre-receive"><em>pre-receive</em></a>
Junio C Hamano8638c922007-05-12 20:50:08464hook does on its standard input.</p>
465<p>This hook does not affect the outcome of <tt>git-receive-pack</tt>, as it
466is called after the real work is done.</p>
Junio C Hamanoa6387422007-08-25 03:54:27467<p>This supersedes the <a href="#post-update"><em>post-update</em></a> hook in that it gets
Junio C Hamano323e52d2007-05-13 22:19:53468both old and new values of all the refs in addition to their
469names.</p>
470<p>Both standard output and standard error output are forwarded to
471<tt>git-send-pack</tt> on the other end, so you can simply <tt>echo</tt> messages
472for the user.</p>
Junio C Hamano8638c922007-05-12 20:50:08473<p>The default <em>post-receive</em> hook is empty, but there is
474a sample script <tt>post-receive-email</tt> provided in the <tt>contrib/hooks</tt>
475directory in git distribution, which implements sending commit
476emails.</p>
477</div>
478<h2><a id="post-update"></a>post-update</h2>
Junio C Hamano1a4e8412005-12-27 08:17:23479<div class="sectionbody">
Junio C Hamano818f7d62006-03-26 01:49:30480<p>This hook is invoked by <tt>git-receive-pack</tt> on the remote repository,
Junio C Hamanod5784132006-09-20 21:29:27481which happens when a <tt>git push</tt> is done on a local repository.
Junio C Hamano818f7d62006-03-26 01:49:30482It executes on the remote repository once after all the refs have
483been updated.</p>
484<p>It takes a variable number of parameters, each of which is the
485name of ref that was actually updated.</p>
Junio C Hamano1a4e8412005-12-27 08:17:23486<p>This hook is meant primarily for notification, and cannot affect
487the outcome of <tt>git-receive-pack</tt>.</p>
Junio C Hamanod5784132006-09-20 21:29:27488<p>The <em>post-update</em> hook can tell what are the heads that were pushed,
Junio C Hamano818f7d62006-03-26 01:49:30489but it does not know what their original and updated values are,
Junio C Hamano323e52d2007-05-13 22:19:53490so it is a poor place to do log old..new. The
491<a href="#post-receive"><em>post-receive</em></a> hook does get both original and
492updated values of the refs. You might consider it instead if you need
493them.</p>
Junio C Hamanod5784132006-09-20 21:29:27494<p>When enabled, the default <em>post-update</em> hook runs
Junio C Hamano1a4e8412005-12-27 08:17:23495<tt>git-update-server-info</tt> to keep the information used by dumb
Junio C Hamanod5784132006-09-20 21:29:27496transports (e.g., HTTP) up-to-date. If you are publishing
497a git repository that is accessible via HTTP, you should
Junio C Hamano818f7d62006-03-26 01:49:30498probably enable this hook.</p>
Junio C Hamano8638c922007-05-12 20:50:08499<p>Both standard output and standard error output are forwarded to
Junio C Hamano323e52d2007-05-13 22:19:53500<tt>git-send-pack</tt> on the other end, so you can simply <tt>echo</tt> messages
501for the user.</p>
Junio C Hamano1a4e8412005-12-27 08:17:23502</div>
503<div id="footer">
504<div id="footer-text">
Junio C Hamano26e590a2008-02-17 03:53:51505Last updated 17-Feb-2008 03:50:10 UTC
Junio C Hamano1a4e8412005-12-27 08:17:23506</div>
507</div>
508</body>
509</html>