index-pack: be careful after fixing up the header/footer
[git/dscho.git] / Documentation / githooks.txt
blob046a2a7fe7cf8ec301d3a20f7ebc587a09d210e3
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 example hooks are copied in 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 This document describes the currently defined hooks.
25 applypatch-msg
26 --------------
28 This hook is invoked by 'git-am' script.  It takes a single
29 parameter, the name of the file that holds the proposed commit
30 log message.  Exiting with non-zero status causes
31 'git-am' to abort before applying the patch.
33 The hook is allowed to edit the message file in place, and can
34 be used to normalize the message into some project standard
35 format (if the project has one). It can also be used to refuse
36 the commit after inspecting the message file.
38 The default 'applypatch-msg' hook, when enabled, runs the
39 'commit-msg' hook, if the latter is enabled.
41 pre-applypatch
42 --------------
44 This hook is invoked by 'git-am'.  It takes no parameter, and is
45 invoked after the patch is applied, but before a commit is made.
47 If it exits with non-zero status, then the working tree will not be
48 committed after applying the patch.
50 It can be used to inspect the current working tree and refuse to
51 make a commit if it does not pass certain test.
53 The default 'pre-applypatch' hook, when enabled, runs the
54 'pre-commit' hook, if the latter is enabled.
56 post-applypatch
57 ---------------
59 This hook is invoked by 'git-am'.  It takes no parameter,
60 and is invoked after the patch is applied and a commit is made.
62 This hook is meant primarily for notification, and cannot affect
63 the outcome of 'git-am'.
65 pre-commit
66 ----------
68 This hook is invoked by 'git-commit', and can be bypassed
69 with `\--no-verify` option.  It takes no parameter, and is
70 invoked before obtaining the proposed commit log message and
71 making a commit.  Exiting with non-zero status from this script
72 causes the 'git-commit' to abort.
74 The default 'pre-commit' hook, when enabled, catches introduction
75 of lines with trailing whitespaces and aborts the commit when
76 such a line is found.
78 All the 'git-commit' hooks are invoked with the environment
79 variable `GIT_EDITOR=:` if the command will not bring up an editor
80 to modify the commit message.
82 prepare-commit-msg
83 ------------------
85 This hook is invoked by 'git-commit' right after preparing the
86 default log message, and before the editor is started.
88 It takes one to three parameters.  The first is the name of the file
89 that the commit log message.  The second is the source of the commit
90 message, and can be: `message` (if a `\-m` or `\-F` option was
91 given); `template` (if a `\-t` option was given or the
92 configuration option `commit.template` is set); `merge` (if the
93 commit is a merge or a `.git/MERGE_MSG` file exists); `squash`
94 (if a `.git/SQUASH_MSG` file exists); or `commit`, followed by
95 a commit SHA1 (if a `\-c`, `\-C` or `\--amend` option was given).
97 If the exit status is non-zero, 'git-commit' will abort.
99 The purpose of the hook is to edit the message file in place, and
100 it is not suppressed by the `\--no-verify` option.  A non-zero exit
101 means a failure of the hook and aborts the commit.  It should not
102 be used as replacement for pre-commit hook.
104 The sample `prepare-commit-msg` hook that comes with git comments
105 out the `Conflicts:` part of a merge's commit message.
107 commit-msg
108 ----------
110 This hook is invoked by 'git-commit', and can be bypassed
111 with `\--no-verify` option.  It takes a single parameter, the
112 name of the file that holds the proposed commit log message.
113 Exiting with non-zero status causes the 'git-commit' to
114 abort.
116 The hook is allowed to edit the message file in place, and can
117 be used to normalize the message into some project standard
118 format (if the project has one). It can also be used to refuse
119 the commit after inspecting the message file.
121 The default 'commit-msg' hook, when enabled, detects duplicate
122 "Signed-off-by" lines, and aborts the commit if one is found.
124 post-commit
125 -----------
127 This hook is invoked by 'git-commit'.  It takes no
128 parameter, and is invoked after a commit is made.
130 This hook is meant primarily for notification, and cannot affect
131 the outcome of 'git-commit'.
133 post-checkout
134 -----------
136 This hook is invoked when a 'git-checkout' is run after having updated the
137 worktree.  The hook is given three parameters: the ref of the previous HEAD,
138 the ref of the new HEAD (which may or may not have changed), and a flag
139 indicating whether the checkout was a branch checkout (changing branches,
140 flag=1) or a file checkout (retrieving a file from the index, flag=0).
141 This hook cannot affect the outcome of 'git-checkout'.
143 This hook can be used to perform repository validity checks, auto-display
144 differences from the previous HEAD if different, or set working dir metadata
145 properties.
147 post-merge
148 -----------
150 This hook is invoked by 'git-merge', which happens when a 'git-pull'
151 is done on a local repository.  The hook takes a single parameter, a status
152 flag specifying whether or not the merge being done was a squash merge.
153 This hook cannot affect the outcome of 'git-merge' and is not executed,
154 if the merge failed due to conflicts.
156 This hook can be used in conjunction with a corresponding pre-commit hook to
157 save and restore any form of metadata associated with the working tree
158 (eg: permissions/ownership, ACLS, etc).  See contrib/hooks/setgitperms.perl
159 for an example of how to do this.
161 [[pre-receive]]
162 pre-receive
163 -----------
165 This hook is invoked by 'git-receive-pack' on the remote repository,
166 which happens when a 'git-push' is done on a local repository.
167 Just before starting to update refs on the remote repository, the
168 pre-receive hook is invoked.  Its exit status determines the success
169 or failure of the update.
171 This hook executes once for the receive operation. It takes no
172 arguments, but for each ref to be updated it receives on standard
173 input a line of the format:
175   <old-value> SP <new-value> SP <ref-name> LF
177 where `<old-value>` is the old object name stored in the ref,
178 `<new-value>` is the new object name to be stored in the ref and
179 `<ref-name>` is the full name of the ref.
180 When creating a new ref, `<old-value>` is 40 `0`.
182 If the hook exits with non-zero status, none of the refs will be
183 updated. If the hook exits with zero, updating of individual refs can
184 still be prevented by the <<update,'update'>> hook.
186 Both standard output and standard error output are forwarded to
187 'git-send-pack' on the other end, so you can simply `echo` messages
188 for the user.
190 [[update]]
191 update
192 ------
194 This hook is invoked by 'git-receive-pack' on the remote repository,
195 which happens when a 'git-push' is done on a local repository.
196 Just before updating the ref on the remote repository, the update hook
197 is invoked.  Its exit status determines the success or failure of
198 the ref update.
200 The hook executes once for each ref to be updated, and takes
201 three parameters:
203  - the name of the ref being updated,
204  - the old object name stored in the ref,
205  - and the new objectname to be stored in the ref.
207 A zero exit from the update hook allows the ref to be updated.
208 Exiting with a non-zero status prevents 'git-receive-pack'
209 from updating that ref.
211 This hook can be used to prevent 'forced' update on certain refs by
212 making sure that the object name is a commit object that is a
213 descendant of the commit object named by the old object name.
214 That is, to enforce a "fast forward only" policy.
216 It could also be used to log the old..new status.  However, it
217 does not know the entire set of branches, so it would end up
218 firing one e-mail per ref when used naively, though.  The
219 <<post-receive,'post-receive'>> hook is more suited to that.
221 Another use suggested on the mailing list is to use this hook to
222 implement access control which is finer grained than the one
223 based on filesystem group.
225 Both standard output and standard error output are forwarded to
226 'git-send-pack' on the other end, so you can simply `echo` messages
227 for the user.
229 The default 'update' hook, when enabled--and with
230 `hooks.allowunannotated` config option turned on--prevents
231 unannotated tags to be pushed.
233 [[post-receive]]
234 post-receive
235 ------------
237 This hook is invoked by 'git-receive-pack' on the remote repository,
238 which happens when a 'git-push' is done on a local repository.
239 It executes on the remote repository once after all the refs have
240 been updated.
242 This hook executes once for the receive operation.  It takes no
243 arguments, but gets the same information as the
244 <<pre-receive,'pre-receive'>>
245 hook does on its standard input.
247 This hook does not affect the outcome of 'git-receive-pack', as it
248 is called after the real work is done.
250 This supersedes the <<post-update,'post-update'>> hook in that it gets
251 both old and new values of all the refs in addition to their
252 names.
254 Both standard output and standard error output are forwarded to
255 'git-send-pack' on the other end, so you can simply `echo` messages
256 for the user.
258 The default 'post-receive' hook is empty, but there is
259 a sample script `post-receive-email` provided in the `contrib/hooks`
260 directory in git distribution, which implements sending commit
261 emails.
263 [[post-update]]
264 post-update
265 -----------
267 This hook is invoked by 'git-receive-pack' on the remote repository,
268 which happens when a 'git-push' is done on a local repository.
269 It executes on the remote repository once after all the refs have
270 been updated.
272 It takes a variable number of parameters, each of which is the
273 name of ref that was actually updated.
275 This hook is meant primarily for notification, and cannot affect
276 the outcome of 'git-receive-pack'.
278 The 'post-update' hook can tell what are the heads that were pushed,
279 but it does not know what their original and updated values are,
280 so it is a poor place to do log old..new. The
281 <<post-receive,'post-receive'>> hook does get both original and
282 updated values of the refs. You might consider it instead if you need
283 them.
285 When enabled, the default 'post-update' hook runs
286 'git-update-server-info' to keep the information used by dumb
287 transports (e.g., HTTP) up-to-date.  If you are publishing
288 a git repository that is accessible via HTTP, you should
289 probably enable this hook.
291 Both standard output and standard error output are forwarded to
292 'git-send-pack' on the other end, so you can simply `echo` messages
293 for the user.
295 pre-auto-gc
296 -----------
298 This hook is invoked by 'git-gc --auto'. It takes no parameter, and
299 exiting with non-zero status from this script causes the 'git-gc --auto'
300 to abort.
304 Part of the linkgit:git[1] suite