make some more strings translatable
[TortoiseGit.git] / doc / source / en / TortoiseGit / git_doc / githooks.html.xml
blob47ea5935c80a20096d178546cbd55a541b68cc06
1 <?xml version="1.0" encoding="UTF-8"?>\r
2 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/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 <literal>$GIT_DIR/hooks</literal>\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 <literal>hooks</literal> directory of the new repository, but by default they are\r
25 all disabled.  To enable a hook, rename it by removing its <literal>.sample</literal>\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 <literal>.sample</literal> 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="_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 </simplesect>\r
45 <simplesect id="_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 </simplesect>\r
56 <simplesect id="_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 </simplesect>\r
63 <simplesect id="_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 <literal>--no-verify</literal> 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 <literal>GIT_EDITOR=:</literal> if the command will not bring up an editor\r
75 to modify the commit message.</simpara>\r
76 </simplesect>\r
77 <simplesect id="_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: <literal>message</literal> (if a <literal>-m</literal> or <literal>-F</literal> option was\r
84 given); <literal>template</literal> (if a <literal>-t</literal> option was given or the\r
85 configuration option <literal>commit.template</literal> is set); <literal>merge</literal> (if the\r
86 commit is a merge or a <literal>.git/MERGE_MSG</literal> file exists); <literal>squash</literal>\r
87 (if a <literal>.git/SQUASH_MSG</literal> file exists); or <literal>commit</literal>, followed by\r
88 a commit SHA1 (if a <literal>-c</literal>, <literal>-C</literal> or <literal>--amend</literal> 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 <literal>--no-verify</literal> 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 <literal>prepare-commit-msg</literal> hook that comes with git comments\r
95 out the <literal>Conflicts:</literal> part of a merge&#8217;s commit message.</simpara>\r
96 </simplesect>\r
97 <simplesect id="_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 <literal>--no-verify</literal> 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 </simplesect>\r
111 <simplesect id="_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 </simplesect>\r
118 <simplesect id="_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 </simplesect>\r
123 <simplesect id="_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>This hook can be used to perform repository validity checks, auto-display\r
132 differences from the previous HEAD if different, or set working dir metadata\r
133 properties.</simpara>\r
134 </simplesect>\r
135 <simplesect id="_post_merge">\r
136 <title>post-merge</title>\r
137 <simpara>This hook is invoked by <emphasis>git-merge</emphasis>, which happens when a <emphasis>git-pull</emphasis>\r
138 is done on a local repository.  The hook takes a single parameter, a status\r
139 flag specifying whether or not the merge being done was a squash merge.\r
140 This hook cannot affect the outcome of <emphasis>git-merge</emphasis> and is not executed,\r
141 if the merge failed due to conflicts.</simpara>\r
142 <simpara>This hook can be used in conjunction with a corresponding pre-commit hook to\r
143 save and restore any form of metadata associated with the working tree\r
144 (eg: permissions/ownership, ACLS, etc).  See contrib/hooks/setgitperms.perl\r
145 for an example of how to do this.</simpara>\r
146 </simplesect>\r
147 <simplesect id="pre-receive">\r
148 <title>pre-receive</title>\r
149 <simpara>This hook is invoked by <emphasis>git-receive-pack</emphasis> on the remote repository,\r
150 which happens when a <emphasis>git-push</emphasis> is done on a local repository.\r
151 Just before starting to update refs on the remote repository, the\r
152 pre-receive hook is invoked.  Its exit status determines the success\r
153 or failure of the update.</simpara>\r
154 <simpara>This hook executes once for the receive operation. It takes no\r
155 arguments, but for each ref to be updated it receives on standard\r
156 input a line of the format:</simpara>\r
157 <literallayout class="monospaced">&lt;old-value&gt; SP &lt;new-value&gt; SP &lt;ref-name&gt; LF</literallayout>\r
158 <simpara>where <literal>&lt;old-value&gt;</literal> is the old object name stored in the ref,\r
159 <literal>&lt;new-value&gt;</literal> is the new object name to be stored in the ref and\r
160 <literal>&lt;ref-name&gt;</literal> is the full name of the ref.\r
161 When creating a new ref, <literal>&lt;old-value&gt;</literal> is 40 <literal>0</literal>.</simpara>\r
162 <simpara>If the hook exits with non-zero status, none of the refs will be\r
163 updated. If the hook exits with zero, updating of individual refs can\r
164 still be prevented by the <link linkend="update"><emphasis>update</emphasis></link> hook.</simpara>\r
165 <simpara>Both standard output and standard error output are forwarded to\r
166 <emphasis>git-send-pack</emphasis> on the other end, so you can simply <literal>echo</literal> messages\r
167 for the user.</simpara>\r
168 </simplesect>\r
169 <simplesect id="update">\r
170 <title>update</title>\r
171 <simpara>This hook is invoked by <emphasis>git-receive-pack</emphasis> on the remote repository,\r
172 which happens when a <emphasis>git-push</emphasis> is done on a local repository.\r
173 Just before updating the ref on the remote repository, the update hook\r
174 is invoked.  Its exit status determines the success or failure of\r
175 the ref update.</simpara>\r
176 <simpara>The hook executes once for each ref to be updated, and takes\r
177 three parameters:</simpara>\r
178 <itemizedlist>\r
179 <listitem>\r
180 <simpara>\r
181 the name of the ref being updated,\r
182 </simpara>\r
183 </listitem>\r
184 <listitem>\r
185 <simpara>\r
186 the old object name stored in the ref,\r
187 </simpara>\r
188 </listitem>\r
189 <listitem>\r
190 <simpara>\r
191 and the new objectname to be stored in the ref.\r
192 </simpara>\r
193 </listitem>\r
194 </itemizedlist>\r
195 <simpara>A zero exit from the update hook allows the ref to be updated.\r
196 Exiting with a non-zero status prevents <emphasis>git-receive-pack</emphasis>\r
197 from updating that ref.</simpara>\r
198 <simpara>This hook can be used to prevent <emphasis>forced</emphasis> update on certain refs by\r
199 making sure that the object name is a commit object that is a\r
200 descendant of the commit object named by the old object name.\r
201 That is, to enforce a "fast forward only" policy.</simpara>\r
202 <simpara>It could also be used to log the old..new status.  However, it\r
203 does not know the entire set of branches, so it would end up\r
204 firing one e-mail per ref when used naively, though.  The\r
205 <link linkend="post-receive"><emphasis>post-receive</emphasis></link> hook is more suited to that.</simpara>\r
206 <simpara>Another use suggested on the mailing list is to use this hook to\r
207 implement access control which is finer grained than the one\r
208 based on filesystem group.</simpara>\r
209 <simpara>Both standard output and standard error output are forwarded to\r
210 <emphasis>git-send-pack</emphasis> on the other end, so you can simply <literal>echo</literal> messages\r
211 for the user.</simpara>\r
212 <simpara>The default <emphasis>update</emphasis> hook, when enabled&#8212;and with\r
213 <literal>hooks.allowunannotated</literal> config option turned on&#8212;prevents\r
214 unannotated tags to be pushed.</simpara>\r
215 </simplesect>\r
216 <simplesect id="post-receive">\r
217 <title>post-receive</title>\r
218 <simpara>This hook is invoked by <emphasis>git-receive-pack</emphasis> on the remote repository,\r
219 which happens when a <emphasis>git-push</emphasis> is done on a local repository.\r
220 It executes on the remote repository once after all the refs have\r
221 been updated.</simpara>\r
222 <simpara>This hook executes once for the receive operation.  It takes no\r
223 arguments, but gets the same information as the\r
224 <link linkend="pre-receive"><emphasis>pre-receive</emphasis></link>\r
225 hook does on its standard input.</simpara>\r
226 <simpara>This hook does not affect the outcome of <emphasis>git-receive-pack</emphasis>, as it\r
227 is called after the real work is done.</simpara>\r
228 <simpara>This supersedes the <link linkend="post-update"><emphasis>post-update</emphasis></link> hook in that it gets\r
229 both old and new values of all the refs in addition to their\r
230 names.</simpara>\r
231 <simpara>Both standard output and standard error output are forwarded to\r
232 <emphasis>git-send-pack</emphasis> on the other end, so you can simply <literal>echo</literal> messages\r
233 for the user.</simpara>\r
234 <simpara>The default <emphasis>post-receive</emphasis> hook is empty, but there is\r
235 a sample script <literal>post-receive-email</literal> provided in the <literal>contrib/hooks</literal>\r
236 directory in git distribution, which implements sending commit\r
237 emails.</simpara>\r
238 </simplesect>\r
239 <simplesect id="post-update">\r
240 <title>post-update</title>\r
241 <simpara>This hook is invoked by <emphasis>git-receive-pack</emphasis> on the remote repository,\r
242 which happens when a <emphasis>git-push</emphasis> is done on a local repository.\r
243 It executes on the remote repository once after all the refs have\r
244 been updated.</simpara>\r
245 <simpara>It takes a variable number of parameters, each of which is the\r
246 name of ref that was actually updated.</simpara>\r
247 <simpara>This hook is meant primarily for notification, and cannot affect\r
248 the outcome of <emphasis>git-receive-pack</emphasis>.</simpara>\r
249 <simpara>The <emphasis>post-update</emphasis> hook can tell what are the heads that were pushed,\r
250 but it does not know what their original and updated values are,\r
251 so it is a poor place to do log old..new. The\r
252 <link linkend="post-receive"><emphasis>post-receive</emphasis></link> hook does get both original and\r
253 updated values of the refs. You might consider it instead if you need\r
254 them.</simpara>\r
255 <simpara>When enabled, the default <emphasis>post-update</emphasis> hook runs\r
256 <emphasis>git-update-server-info</emphasis> to keep the information used by dumb\r
257 transports (e.g., HTTP) up-to-date.  If you are publishing\r
258 a git repository that is accessible via HTTP, you should\r
259 probably enable this hook.</simpara>\r
260 <simpara>Both standard output and standard error output are forwarded to\r
261 <emphasis>git-send-pack</emphasis> on the other end, so you can simply <literal>echo</literal> messages\r
262 for the user.</simpara>\r
263 </simplesect>\r
264 <simplesect id="_pre_auto_gc">\r
265 <title>pre-auto-gc</title>\r
266 <simpara>This hook is invoked by <emphasis>git-gc --auto</emphasis>. It takes no parameter, and\r
267 exiting with non-zero status from this script causes the <emphasis>git-gc --auto</emphasis>\r
268 to abort.</simpara>\r
269 </simplesect>\r
270 <simplesect id="_git">\r
271 <title>GIT</title>\r
272 <simpara>Part of the <xref linkend="git(1)"/> suite</simpara>\r
273 </simplesect>\r
274 </article>\r