Merge branch 'nd/index-pack-l10n-buf-overflow' into maint-1.8.1
[git/jnareb-git.git] / Documentation / githooks.txt
blob4eed86b2a44f0cac8d963ec6c9ed88e4a069bc4c
1 githooks(5)
2 ===========
4 NAME
5 ----
6 githooks - Hooks used by git
8 SYNOPSIS
9 --------
10 $GIT_DIR/hooks/*
13 DESCRIPTION
14 -----------
16 Hooks are little scripts you can place in `$GIT_DIR/hooks`
17 directory to trigger action at certain points.  When
18 'git init' is run, a handful of example hooks are copied into the
19 `hooks` directory of the new repository, but by default they are
20 all disabled.  To enable a hook, rename it by removing its `.sample`
21 suffix.
23 NOTE: It is also a requirement for a given hook to be executable.
24 However - in a freshly initialized repository - the `.sample` files are
25 executable by default.
27 This document describes the currently defined hooks.
29 HOOKS
30 -----
32 applypatch-msg
33 ~~~~~~~~~~~~~~
35 This hook is invoked by 'git am' script.  It takes a single
36 parameter, the name of the file that holds the proposed commit
37 log message.  Exiting with non-zero status causes
38 'git am' to abort before applying the patch.
40 The hook is allowed to edit the message file in place, and can
41 be used to normalize the message into some project standard
42 format (if the project has one). It can also be used to refuse
43 the commit after inspecting the message file.
45 The default 'applypatch-msg' hook, when enabled, runs the
46 'commit-msg' hook, if the latter is enabled.
48 pre-applypatch
49 ~~~~~~~~~~~~~~
51 This hook is invoked by 'git am'.  It takes no parameter, and is
52 invoked after the patch is applied, but before a commit is made.
54 If it exits with non-zero status, then the working tree will not be
55 committed after applying the patch.
57 It can be used to inspect the current working tree and refuse to
58 make a commit if it does not pass certain test.
60 The default 'pre-applypatch' hook, when enabled, runs the
61 'pre-commit' hook, if the latter is enabled.
63 post-applypatch
64 ~~~~~~~~~~~~~~~
66 This hook is invoked by 'git am'.  It takes no parameter,
67 and is invoked after the patch is applied and a commit is made.
69 This hook is meant primarily for notification, and cannot affect
70 the outcome of 'git am'.
72 pre-commit
73 ~~~~~~~~~~
75 This hook is invoked by 'git commit', and can be bypassed
76 with `--no-verify` option.  It takes no parameter, and is
77 invoked before obtaining the proposed commit log message and
78 making a commit.  Exiting with non-zero status from this script
79 causes the 'git commit' to abort.
81 The default 'pre-commit' hook, when enabled, catches introduction
82 of lines with trailing whitespaces and aborts the commit when
83 such a line is found.
85 All the 'git commit' hooks are invoked with the environment
86 variable `GIT_EDITOR=:` if the command will not bring up an editor
87 to modify the commit message.
89 prepare-commit-msg
90 ~~~~~~~~~~~~~~~~~~
92 This hook is invoked by 'git commit' right after preparing the
93 default log message, and before the editor is started.
95 It takes one to three parameters.  The first is the name of the file
96 that contains the commit log message.  The second is the source of the commit
97 message, and can be: `message` (if a `-m` or `-F` option was
98 given); `template` (if a `-t` option was given or the
99 configuration option `commit.template` is set); `merge` (if the
100 commit is a merge or a `.git/MERGE_MSG` file exists); `squash`
101 (if a `.git/SQUASH_MSG` file exists); or `commit`, followed by
102 a commit SHA1 (if a `-c`, `-C` or `--amend` option was given).
104 If the exit status is non-zero, 'git commit' will abort.
106 The purpose of the hook is to edit the message file in place, and
107 it is not suppressed by the `--no-verify` option.  A non-zero exit
108 means a failure of the hook and aborts the commit.  It should not
109 be used as replacement for pre-commit hook.
111 The sample `prepare-commit-msg` hook that comes with git comments
112 out the `Conflicts:` part of a merge's commit message.
114 commit-msg
115 ~~~~~~~~~~
117 This hook is invoked by 'git commit', and can be bypassed
118 with `--no-verify` option.  It takes a single parameter, the
119 name of the file that holds the proposed commit log message.
120 Exiting with non-zero status causes the 'git commit' to
121 abort.
123 The hook is allowed to edit the message file in place, and can
124 be used to normalize the message into some project standard
125 format (if the project has one). It can also be used to refuse
126 the commit after inspecting the message file.
128 The default 'commit-msg' hook, when enabled, detects duplicate
129 "Signed-off-by" lines, and aborts the commit if one is found.
131 post-commit
132 ~~~~~~~~~~~
134 This hook is invoked by 'git commit'.  It takes no
135 parameter, and is invoked after a commit is made.
137 This hook is meant primarily for notification, and cannot affect
138 the outcome of 'git commit'.
140 pre-rebase
141 ~~~~~~~~~~
143 This hook is called by 'git rebase' and can be used to prevent a
144 branch from getting rebased.  The hook may be called with one or
145 two parameters.  The first parameter is the upstream from which
146 the series was forked.  The second parameter is the branch being
147 rebased, and is not set when rebasing the current branch.
149 post-checkout
150 ~~~~~~~~~~~~~
152 This hook is invoked when a 'git checkout' is run after having updated the
153 worktree.  The hook is given three parameters: the ref of the previous HEAD,
154 the ref of the new HEAD (which may or may not have changed), and a flag
155 indicating whether the checkout was a branch checkout (changing branches,
156 flag=1) or a file checkout (retrieving a file from the index, flag=0).
157 This hook cannot affect the outcome of 'git checkout'.
159 It is also run after 'git clone', unless the --no-checkout (-n) option is
160 used. The first parameter given to the hook is the null-ref, the second the
161 ref of the new HEAD and the flag is always 1.
163 This hook can be used to perform repository validity checks, auto-display
164 differences from the previous HEAD if different, or set working dir metadata
165 properties.
167 post-merge
168 ~~~~~~~~~~
170 This hook is invoked by 'git merge', which happens when a 'git pull'
171 is done on a local repository.  The hook takes a single parameter, a status
172 flag specifying whether or not the merge being done was a squash merge.
173 This hook cannot affect the outcome of 'git merge' and is not executed,
174 if the merge failed due to conflicts.
176 This hook can be used in conjunction with a corresponding pre-commit hook to
177 save and restore any form of metadata associated with the working tree
178 (eg: permissions/ownership, ACLS, etc).  See contrib/hooks/setgitperms.perl
179 for an example of how to do this.
181 [[pre-receive]]
182 pre-receive
183 ~~~~~~~~~~~
185 This hook is invoked by 'git-receive-pack' on the remote repository,
186 which happens when a 'git push' is done on a local repository.
187 Just before starting to update refs on the remote repository, the
188 pre-receive hook is invoked.  Its exit status determines the success
189 or failure of the update.
191 This hook executes once for the receive operation. It takes no
192 arguments, but for each ref to be updated it receives on standard
193 input a line of the format:
195   <old-value> SP <new-value> SP <ref-name> LF
197 where `<old-value>` is the old object name stored in the ref,
198 `<new-value>` is the new object name to be stored in the ref and
199 `<ref-name>` is the full name of the ref.
200 When creating a new ref, `<old-value>` is 40 `0`.
202 If the hook exits with non-zero status, none of the refs will be
203 updated. If the hook exits with zero, updating of individual refs can
204 still be prevented by the <<update,'update'>> hook.
206 Both standard output and standard error output are forwarded to
207 'git send-pack' on the other end, so you can simply `echo` messages
208 for the user.
210 [[update]]
211 update
212 ~~~~~~
214 This hook is invoked by 'git-receive-pack' on the remote repository,
215 which happens when a 'git push' is done on a local repository.
216 Just before updating the ref on the remote repository, the update hook
217 is invoked.  Its exit status determines the success or failure of
218 the ref update.
220 The hook executes once for each ref to be updated, and takes
221 three parameters:
223  - the name of the ref being updated,
224  - the old object name stored in the ref,
225  - and the new objectname to be stored in the ref.
227 A zero exit from the update hook allows the ref to be updated.
228 Exiting with a non-zero status prevents 'git-receive-pack'
229 from updating that ref.
231 This hook can be used to prevent 'forced' update on certain refs by
232 making sure that the object name is a commit object that is a
233 descendant of the commit object named by the old object name.
234 That is, to enforce a "fast-forward only" policy.
236 It could also be used to log the old..new status.  However, it
237 does not know the entire set of branches, so it would end up
238 firing one e-mail per ref when used naively, though.  The
239 <<post-receive,'post-receive'>> hook is more suited to that.
241 Another use suggested on the mailing list is to use this hook to
242 implement access control which is finer grained than the one
243 based on filesystem group.
245 Both standard output and standard error output are forwarded to
246 'git send-pack' on the other end, so you can simply `echo` messages
247 for the user.
249 The default 'update' hook, when enabled--and with
250 `hooks.allowunannotated` config option unset or set to false--prevents
251 unannotated tags to be pushed.
253 [[post-receive]]
254 post-receive
255 ~~~~~~~~~~~~
257 This hook is invoked by 'git-receive-pack' on the remote repository,
258 which happens when a 'git push' is done on a local repository.
259 It executes on the remote repository once after all the refs have
260 been updated.
262 This hook executes once for the receive operation.  It takes no
263 arguments, but gets the same information as the
264 <<pre-receive,'pre-receive'>>
265 hook does on its standard input.
267 This hook does not affect the outcome of 'git-receive-pack', as it
268 is called after the real work is done.
270 This supersedes the <<post-update,'post-update'>> hook in that it gets
271 both old and new values of all the refs in addition to their
272 names.
274 Both standard output and standard error output are forwarded to
275 'git send-pack' on the other end, so you can simply `echo` messages
276 for the user.
278 The default 'post-receive' hook is empty, but there is
279 a sample script `post-receive-email` provided in the `contrib/hooks`
280 directory in git distribution, which implements sending commit
281 emails.
283 [[post-update]]
284 post-update
285 ~~~~~~~~~~~
287 This hook is invoked by 'git-receive-pack' on the remote repository,
288 which happens when a 'git push' is done on a local repository.
289 It executes on the remote repository once after all the refs have
290 been updated.
292 It takes a variable number of parameters, each of which is the
293 name of ref that was actually updated.
295 This hook is meant primarily for notification, and cannot affect
296 the outcome of 'git-receive-pack'.
298 The 'post-update' hook can tell what are the heads that were pushed,
299 but it does not know what their original and updated values are,
300 so it is a poor place to do log old..new. The
301 <<post-receive,'post-receive'>> hook does get both original and
302 updated values of the refs. You might consider it instead if you need
303 them.
305 When enabled, the default 'post-update' hook runs
306 'git update-server-info' to keep the information used by dumb
307 transports (e.g., HTTP) up-to-date.  If you are publishing
308 a git repository that is accessible via HTTP, you should
309 probably enable this hook.
311 Both standard output and standard error output are forwarded to
312 'git send-pack' on the other end, so you can simply `echo` messages
313 for the user.
315 pre-auto-gc
316 ~~~~~~~~~~~
318 This hook is invoked by 'git gc --auto'. It takes no parameter, and
319 exiting with non-zero status from this script causes the 'git gc --auto'
320 to abort.
322 post-rewrite
323 ~~~~~~~~~~~~
325 This hook is invoked by commands that rewrite commits (`git commit
326 --amend`, 'git-rebase'; currently 'git-filter-branch' does 'not' call
327 it!).  Its first argument denotes the command it was invoked by:
328 currently one of `amend` or `rebase`.  Further command-dependent
329 arguments may be passed in the future.
331 The hook receives a list of the rewritten commits on stdin, in the
332 format
334   <old-sha1> SP <new-sha1> [ SP <extra-info> ] LF
336 The 'extra-info' is again command-dependent.  If it is empty, the
337 preceding SP is also omitted.  Currently, no commands pass any
338 'extra-info'.
340 The hook always runs after the automatic note copying (see
341 "notes.rewrite.<command>" in linkgit:git-config.txt[1]) has happened, and
342 thus has access to these notes.
344 The following command-specific comments apply:
346 rebase::
347         For the 'squash' and 'fixup' operation, all commits that were
348         squashed are listed as being rewritten to the squashed commit.
349         This means that there will be several lines sharing the same
350         'new-sha1'.
352 The commits are guaranteed to be listed in the order that they were
353 processed by rebase.
358 Part of the linkgit:git[1] suite