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