Updated git_doc to git 1.8
[TortoiseGit.git] / doc / source / en / TortoiseGit / git_doc / githooks.xml
blobeceadfdc6d5fe08e8c0f844b6642df0456fcc753
1 <?xml version="1.0" encoding="UTF-8"?>\r
2 <!DOCTYPE sect2 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">\r
3 \r
4 <sect2 lang="en" id="githooks(5)">\r
5     <title>githooks(5)</title>\r
6 <indexterm>\r
7 <primary>githooks(5)</primary>\r
8 </indexterm>\r
9 <simplesect id="githooks(5)__name">\r
10 <title>NAME</title>\r
11 <simpara>githooks - Hooks used by git</simpara>\r
12 </simplesect>\r
13 <simplesect id="githooks(5)__synopsis">\r
14 <title>SYNOPSIS</title>\r
15 <simpara>$GIT_DIR/hooks/*</simpara>\r
16 </simplesect>\r
17 <simplesect id="githooks(5)__description">\r
18 <title>DESCRIPTION</title>\r
19 <simpara>Hooks are little scripts you can place in <emphasis>$GIT_DIR/hooks</emphasis>\r
20 directory to trigger action at certain points.  When\r
21 <emphasis>git init</emphasis> is run, a handful of example hooks are copied into the\r
22 <emphasis>hooks</emphasis> directory of the new repository, but by default they are\r
23 all disabled.  To enable a hook, rename it by removing its <emphasis>.sample</emphasis>\r
24 suffix.</simpara>\r
25 <note><simpara>It is also a requirement for a given hook to be executable.\r
26 However - in a freshly initialized repository - the <emphasis>.sample</emphasis> files are\r
27 executable by default.</simpara></note>\r
28 <simpara>This document describes the currently defined hooks.</simpara>\r
29 </simplesect>\r
30 <simplesect id="githooks(5)__hooks">\r
31 <title>HOOKS</title>\r
32 <section id="githooks(5)__applypatch_msg">\r
33 <title>applypatch-msg</title>\r
34 <simpara>This hook is invoked by <emphasis>git am</emphasis> script.  It takes a single\r
35 parameter, the name of the file that holds the proposed commit\r
36 log message.  Exiting with non-zero status causes\r
37 <emphasis>git am</emphasis> to abort before applying the patch.</simpara>\r
38 <simpara>The hook is allowed to edit the message file in place, and can\r
39 be used to normalize the message into some project standard\r
40 format (if the project has one). It can also be used to refuse\r
41 the commit after inspecting the message file.</simpara>\r
42 <simpara>The default <emphasis>applypatch-msg</emphasis> hook, when enabled, runs the\r
43 <emphasis>commit-msg</emphasis> hook, if the latter is enabled.</simpara>\r
44 </section>\r
45 <section id="githooks(5)__pre_applypatch">\r
46 <title>pre-applypatch</title>\r
47 <simpara>This hook is invoked by <emphasis>git am</emphasis>.  It takes no parameter, and is\r
48 invoked after the patch is applied, but before a commit is made.</simpara>\r
49 <simpara>If it exits with non-zero status, then the working tree will not be\r
50 committed after applying the patch.</simpara>\r
51 <simpara>It can be used to inspect the current working tree and refuse to\r
52 make a commit if it does not pass certain test.</simpara>\r
53 <simpara>The default <emphasis>pre-applypatch</emphasis> hook, when enabled, runs the\r
54 <emphasis>pre-commit</emphasis> hook, if the latter is enabled.</simpara>\r
55 </section>\r
56 <section id="githooks(5)__post_applypatch">\r
57 <title>post-applypatch</title>\r
58 <simpara>This hook is invoked by <emphasis>git am</emphasis>.  It takes no parameter,\r
59 and is invoked after the patch is applied and a commit is made.</simpara>\r
60 <simpara>This hook is meant primarily for notification, and cannot affect\r
61 the outcome of <emphasis>git am</emphasis>.</simpara>\r
62 </section>\r
63 <section id="githooks(5)__pre_commit">\r
64 <title>pre-commit</title>\r
65 <simpara>This hook is invoked by <emphasis>git commit</emphasis>, and can be bypassed\r
66 with <emphasis>--no-verify</emphasis> option.  It takes no parameter, and is\r
67 invoked before obtaining the proposed commit log message and\r
68 making a commit.  Exiting with non-zero status from this script\r
69 causes the <emphasis>git commit</emphasis> to abort.</simpara>\r
70 <simpara>The default <emphasis>pre-commit</emphasis> hook, when enabled, catches introduction\r
71 of lines with trailing whitespaces and aborts the commit when\r
72 such a line is found.</simpara>\r
73 <simpara>All the <emphasis>git commit</emphasis> hooks are invoked with the environment\r
74 variable <emphasis>GIT_EDITOR=:</emphasis> if the command will not bring up an editor\r
75 to modify the commit message.</simpara>\r
76 </section>\r
77 <section id="githooks(5)__prepare_commit_msg">\r
78 <title>prepare-commit-msg</title>\r
79 <simpara>This hook is invoked by <emphasis>git commit</emphasis> right after preparing the\r
80 default log message, and before the editor is started.</simpara>\r
81 <simpara>It takes one to three parameters.  The first is the name of the file\r
82 that contains the commit log message.  The second is the source of the commit\r
83 message, and can be: <emphasis>message</emphasis> (if a <emphasis>-m</emphasis> or <emphasis>-F</emphasis> option was\r
84 given); <emphasis>template</emphasis> (if a <emphasis>-t</emphasis> option was given or the\r
85 configuration option <emphasis>commit.template</emphasis> is set); <emphasis>merge</emphasis> (if the\r
86 commit is a merge or a <emphasis>.git/MERGE_MSG</emphasis> file exists); <emphasis>squash</emphasis>\r
87 (if a <emphasis>.git/SQUASH_MSG</emphasis> file exists); or <emphasis>commit</emphasis>, followed by\r
88 a commit SHA1 (if a <emphasis>-c</emphasis>, <emphasis>-C</emphasis> or <emphasis>--amend</emphasis> option was given).</simpara>\r
89 <simpara>If the exit status is non-zero, <emphasis>git commit</emphasis> will abort.</simpara>\r
90 <simpara>The purpose of the hook is to edit the message file in place, and\r
91 it is not suppressed by the <emphasis>--no-verify</emphasis> option.  A non-zero exit\r
92 means a failure of the hook and aborts the commit.  It should not\r
93 be used as replacement for pre-commit hook.</simpara>\r
94 <simpara>The sample <emphasis>prepare-commit-msg</emphasis> hook that comes with git comments\r
95 out the <emphasis>Conflicts:</emphasis> part of a merge's commit message.</simpara>\r
96 </section>\r
97 <section id="githooks(5)__commit_msg">\r
98 <title>commit-msg</title>\r
99 <simpara>This hook is invoked by <emphasis>git commit</emphasis>, and can be bypassed\r
100 with <emphasis>--no-verify</emphasis> option.  It takes a single parameter, the\r
101 name of the file that holds the proposed commit log message.\r
102 Exiting with non-zero status causes the <emphasis>git commit</emphasis> to\r
103 abort.</simpara>\r
104 <simpara>The hook is allowed to edit the message file in place, and can\r
105 be used to normalize the message into some project standard\r
106 format (if the project has one). It can also be used to refuse\r
107 the commit after inspecting the message file.</simpara>\r
108 <simpara>The default <emphasis>commit-msg</emphasis> hook, when enabled, detects duplicate\r
109 "Signed-off-by" lines, and aborts the commit if one is found.</simpara>\r
110 </section>\r
111 <section id="githooks(5)__post_commit">\r
112 <title>post-commit</title>\r
113 <simpara>This hook is invoked by <emphasis>git commit</emphasis>.  It takes no\r
114 parameter, and is invoked after a commit is made.</simpara>\r
115 <simpara>This hook is meant primarily for notification, and cannot affect\r
116 the outcome of <emphasis>git commit</emphasis>.</simpara>\r
117 </section>\r
118 <section id="githooks(5)__pre_rebase">\r
119 <title>pre-rebase</title>\r
120 <simpara>This hook is called by <emphasis>git rebase</emphasis> and can be used to prevent a branch\r
121 from getting rebased.</simpara>\r
122 </section>\r
123 <section id="githooks(5)__post_checkout">\r
124 <title>post-checkout</title>\r
125 <simpara>This hook is invoked when a <emphasis>git checkout</emphasis> is run after having updated the\r
126 worktree.  The hook is given three parameters: the ref of the previous HEAD,\r
127 the ref of the new HEAD (which may or may not have changed), and a flag\r
128 indicating whether the checkout was a branch checkout (changing branches,\r
129 flag=1) or a file checkout (retrieving a file from the index, flag=0).\r
130 This hook cannot affect the outcome of <emphasis>git checkout</emphasis>.</simpara>\r
131 <simpara>It is also run after <emphasis>git clone</emphasis>, unless the --no-checkout (-n) option is\r
132 used. The first parameter given to the hook is the null-ref, the second the\r
133 ref of the new HEAD and the flag is always 1.</simpara>\r
134 <simpara>This hook can be used to perform repository validity checks, auto-display\r
135 differences from the previous HEAD if different, or set working dir metadata\r
136 properties.</simpara>\r
137 </section>\r
138 <section id="githooks(5)__post_merge">\r
139 <title>post-merge</title>\r
140 <simpara>This hook is invoked by <emphasis>git merge</emphasis>, which happens when a <emphasis>git pull</emphasis>\r
141 is done on a local repository.  The hook takes a single parameter, a status\r
142 flag specifying whether or not the merge being done was a squash merge.\r
143 This hook cannot affect the outcome of <emphasis>git merge</emphasis> and is not executed,\r
144 if the merge failed due to conflicts.</simpara>\r
145 <simpara>This hook can be used in conjunction with a corresponding pre-commit hook to\r
146 save and restore any form of metadata associated with the working tree\r
147 (eg: permissions/ownership, ACLS, etc).  See contrib/hooks/setgitperms.perl\r
148 for an example of how to do this.</simpara>\r
149 </section>\r
150 <section id="githooks(5)_pre-receive">\r
151 <title>pre-receive</title>\r
152 <simpara>This hook is invoked by <emphasis>git-receive-pack</emphasis> on the remote repository,\r
153 which happens when a <emphasis>git push</emphasis> is done on a local repository.\r
154 Just before starting to update refs on the remote repository, the\r
155 pre-receive hook is invoked.  Its exit status determines the success\r
156 or failure of the update.</simpara>\r
157 <simpara>This hook executes once for the receive operation. It takes no\r
158 arguments, but for each ref to be updated it receives on standard\r
159 input a line of the format:</simpara>\r
160 <literallayout class="monospaced">&lt;old-value&gt; SP &lt;new-value&gt; SP &lt;ref-name&gt; LF</literallayout>\r
161 <simpara>where <emphasis>&lt;old-value&gt;</emphasis> is the old object name stored in the ref,\r
162 <emphasis>&lt;new-value&gt;</emphasis> is the new object name to be stored in the ref and\r
163 <emphasis>&lt;ref-name&gt;</emphasis> is the full name of the ref.\r
164 When creating a new ref, <emphasis>&lt;old-value&gt;</emphasis> is 40 <emphasis>0</emphasis>.</simpara>\r
165 <simpara>If the hook exits with non-zero status, none of the refs will be\r
166 updated. If the hook exits with zero, updating of individual refs can\r
167 still be prevented by the <link linkend="githooks(5)_update"><emphasis>update</emphasis></link> hook.</simpara>\r
168 <simpara>Both standard output and standard error output are forwarded to\r
169 <emphasis>git send-pack</emphasis> on the other end, so you can simply <emphasis>echo</emphasis> messages\r
170 for the user.</simpara>\r
171 </section>\r
172 <section id="githooks(5)_update">\r
173 <title>update</title>\r
174 <simpara>This hook is invoked by <emphasis>git-receive-pack</emphasis> on the remote repository,\r
175 which happens when a <emphasis>git push</emphasis> is done on a local repository.\r
176 Just before updating the ref on the remote repository, the update hook\r
177 is invoked.  Its exit status determines the success or failure of\r
178 the ref update.</simpara>\r
179 <simpara>The hook executes once for each ref to be updated, and takes\r
180 three parameters:</simpara>\r
181 <itemizedlist>\r
182 <listitem>\r
183 <simpara>\r
184 the name of the ref being updated,\r
185 </simpara>\r
186 </listitem>\r
187 <listitem>\r
188 <simpara>\r
189 the old object name stored in the ref,\r
190 </simpara>\r
191 </listitem>\r
192 <listitem>\r
193 <simpara>\r
194 and the new objectname to be stored in the ref.\r
195 </simpara>\r
196 </listitem>\r
197 </itemizedlist>\r
198 <simpara>A zero exit from the update hook allows the ref to be updated.\r
199 Exiting with a non-zero status prevents <emphasis>git-receive-pack</emphasis>\r
200 from updating that ref.</simpara>\r
201 <simpara>This hook can be used to prevent <emphasis>forced</emphasis> update on certain refs by\r
202 making sure that the object name is a commit object that is a\r
203 descendant of the commit object named by the old object name.\r
204 That is, to enforce a "fast-forward only" policy.</simpara>\r
205 <simpara>It could also be used to log the old..new status.  However, it\r
206 does not know the entire set of branches, so it would end up\r
207 firing one e-mail per ref when used naively, though.  The\r
208 <link linkend="githooks(5)_post-receive"><emphasis>post-receive</emphasis></link> hook is more suited to that.</simpara>\r
209 <simpara>Another use suggested on the mailing list is to use this hook to\r
210 implement access control which is finer grained than the one\r
211 based on filesystem group.</simpara>\r
212 <simpara>Both standard output and standard error output are forwarded to\r
213 <emphasis>git send-pack</emphasis> on the other end, so you can simply <emphasis>echo</emphasis> messages\r
214 for the user.</simpara>\r
215 <simpara>The default <emphasis>update</emphasis> hook, when enabled--and with\r
216 <emphasis>hooks.allowunannotated</emphasis> config option unset or set to false--prevents\r
217 unannotated tags to be pushed.</simpara>\r
218 </section>\r
219 <section id="githooks(5)_post-receive">\r
220 <title>post-receive</title>\r
221 <simpara>This hook is invoked by <emphasis>git-receive-pack</emphasis> on the remote repository,\r
222 which happens when a <emphasis>git push</emphasis> is done on a local repository.\r
223 It executes on the remote repository once after all the refs have\r
224 been updated.</simpara>\r
225 <simpara>This hook executes once for the receive operation.  It takes no\r
226 arguments, but gets the same information as the\r
227 <link linkend="githooks(5)_pre-receive"><emphasis>pre-receive</emphasis></link>\r
228 hook does on its standard input.</simpara>\r
229 <simpara>This hook does not affect the outcome of <emphasis>git-receive-pack</emphasis>, as it\r
230 is called after the real work is done.</simpara>\r
231 <simpara>This supersedes the <link linkend="githooks(5)_post-update"><emphasis>post-update</emphasis></link> hook in that it gets\r
232 both old and new values of all the refs in addition to their\r
233 names.</simpara>\r
234 <simpara>Both standard output and standard error output are forwarded to\r
235 <emphasis>git send-pack</emphasis> on the other end, so you can simply <emphasis>echo</emphasis> messages\r
236 for the user.</simpara>\r
237 <simpara>The default <emphasis>post-receive</emphasis> hook is empty, but there is\r
238 a sample script <emphasis>post-receive-email</emphasis> provided in the <emphasis>contrib/hooks</emphasis>\r
239 directory in git distribution, which implements sending commit\r
240 emails.</simpara>\r
241 </section>\r
242 <section id="githooks(5)_post-update">\r
243 <title>post-update</title>\r
244 <simpara>This hook is invoked by <emphasis>git-receive-pack</emphasis> on the remote repository,\r
245 which happens when a <emphasis>git push</emphasis> is done on a local repository.\r
246 It executes on the remote repository once after all the refs have\r
247 been updated.</simpara>\r
248 <simpara>It takes a variable number of parameters, each of which is the\r
249 name of ref that was actually updated.</simpara>\r
250 <simpara>This hook is meant primarily for notification, and cannot affect\r
251 the outcome of <emphasis>git-receive-pack</emphasis>.</simpara>\r
252 <simpara>The <emphasis>post-update</emphasis> hook can tell what are the heads that were pushed,\r
253 but it does not know what their original and updated values are,\r
254 so it is a poor place to do log old..new. The\r
255 <link linkend="githooks(5)_post-receive"><emphasis>post-receive</emphasis></link> hook does get both original and\r
256 updated values of the refs. You might consider it instead if you need\r
257 them.</simpara>\r
258 <simpara>When enabled, the default <emphasis>post-update</emphasis> hook runs\r
259 <emphasis>git update-server-info</emphasis> to keep the information used by dumb\r
260 transports (e.g., HTTP) up-to-date.  If you are publishing\r
261 a git repository that is accessible via HTTP, you should\r
262 probably enable this hook.</simpara>\r
263 <simpara>Both standard output and standard error output are forwarded to\r
264 <emphasis>git send-pack</emphasis> on the other end, so you can simply <emphasis>echo</emphasis> messages\r
265 for the user.</simpara>\r
266 </section>\r
267 <section id="githooks(5)__pre_auto_gc">\r
268 <title>pre-auto-gc</title>\r
269 <simpara>This hook is invoked by <emphasis>git gc --auto</emphasis>. It takes no parameter, and\r
270 exiting with non-zero status from this script causes the <emphasis>git gc --auto</emphasis>\r
271 to abort.</simpara>\r
272 </section>\r
273 <section id="githooks(5)__post_rewrite">\r
274 <title>post-rewrite</title>\r
275 <simpara>This hook is invoked by commands that rewrite commits (<emphasis>git commit\r
276 --amend</emphasis>, <emphasis>git-rebase</emphasis>; currently <emphasis>git-filter-branch</emphasis> does <emphasis>not</emphasis> call\r
277 it!).  Its first argument denotes the command it was invoked by:\r
278 currently one of <emphasis>amend</emphasis> or <emphasis>rebase</emphasis>.  Further command-dependent\r
279 arguments may be passed in the future.</simpara>\r
280 <simpara>The hook receives a list of the rewritten commits on stdin, in the\r
281 format</simpara>\r
282 <literallayout class="monospaced">&lt;old-sha1&gt; SP &lt;new-sha1&gt; [ SP &lt;extra-info&gt; ] LF</literallayout>\r
283 <simpara>The <emphasis>extra-info</emphasis> is again command-dependent.  If it is empty, the\r
284 preceding SP is also omitted.  Currently, no commands pass any\r
285 <emphasis>extra-info</emphasis>.</simpara>\r
286 <simpara>The hook always runs after the automatic note copying (see\r
287 "notes.rewrite.&lt;command&gt;" in linkgit:git-config.txt) has happened, and\r
288 thus has access to these notes.</simpara>\r
289 <simpara>The following command-specific comments apply:</simpara>\r
290 <variablelist>\r
291 <varlistentry>\r
292 <term>\r
293 rebase\r
294 </term>\r
295 <listitem>\r
296 <simpara>\r
297         For the <emphasis>squash</emphasis> and <emphasis>fixup</emphasis> operation, all commits that were\r
298         squashed are listed as being rewritten to the squashed commit.\r
299         This means that there will be several lines sharing the same\r
300         <emphasis>new-sha1</emphasis>.\r
301 </simpara>\r
302 <simpara>The commits are guaranteed to be listed in the order that they were\r
303 processed by rebase.</simpara>\r
304 </listitem>\r
305 </varlistentry>\r
306 </variablelist>\r
307 </section>\r
308 </simplesect>\r
309 <simplesect id="githooks(5)__git">\r
310 <title>GIT</title>\r
311 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>\r
312 </simplesect>\r
313 </sect2>\r