git-archive: work in bare repos
[git/dscho.git] / Documentation / githooks.txt
blob5faaaa5fedcd0d61234d3927a89d77144f2a15ad
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 pre-rebase
134 ----------
136 This hook is called by 'git-rebase' and can be used to prevent a branch
137 from getting rebased.
140 post-checkout
141 -----------
143 This hook is invoked when a 'git-checkout' is run after having updated the
144 worktree.  The hook is given three parameters: the ref of the previous HEAD,
145 the ref of the new HEAD (which may or may not have changed), and a flag
146 indicating whether the checkout was a branch checkout (changing branches,
147 flag=1) or a file checkout (retrieving a file from the index, flag=0).
148 This hook cannot affect the outcome of 'git-checkout'.
150 This hook can be used to perform repository validity checks, auto-display
151 differences from the previous HEAD if different, or set working dir metadata
152 properties.
154 post-merge
155 -----------
157 This hook is invoked by 'git-merge', which happens when a 'git-pull'
158 is done on a local repository.  The hook takes a single parameter, a status
159 flag specifying whether or not the merge being done was a squash merge.
160 This hook cannot affect the outcome of 'git-merge' and is not executed,
161 if the merge failed due to conflicts.
163 This hook can be used in conjunction with a corresponding pre-commit hook to
164 save and restore any form of metadata associated with the working tree
165 (eg: permissions/ownership, ACLS, etc).  See contrib/hooks/setgitperms.perl
166 for an example of how to do this.
168 [[pre-receive]]
169 pre-receive
170 -----------
172 This hook is invoked by 'git-receive-pack' on the remote repository,
173 which happens when a 'git-push' is done on a local repository.
174 Just before starting to update refs on the remote repository, the
175 pre-receive hook is invoked.  Its exit status determines the success
176 or failure of the update.
178 This hook executes once for the receive operation. It takes no
179 arguments, but for each ref to be updated it receives on standard
180 input a line of the format:
182   <old-value> SP <new-value> SP <ref-name> LF
184 where `<old-value>` is the old object name stored in the ref,
185 `<new-value>` is the new object name to be stored in the ref and
186 `<ref-name>` is the full name of the ref.
187 When creating a new ref, `<old-value>` is 40 `0`.
189 If the hook exits with non-zero status, none of the refs will be
190 updated. If the hook exits with zero, updating of individual refs can
191 still be prevented by the <<update,'update'>> hook.
193 Both standard output and standard error output are forwarded to
194 'git-send-pack' on the other end, so you can simply `echo` messages
195 for the user.
197 [[update]]
198 update
199 ------
201 This hook is invoked by 'git-receive-pack' on the remote repository,
202 which happens when a 'git-push' is done on a local repository.
203 Just before updating the ref on the remote repository, the update hook
204 is invoked.  Its exit status determines the success or failure of
205 the ref update.
207 The hook executes once for each ref to be updated, and takes
208 three parameters:
210  - the name of the ref being updated,
211  - the old object name stored in the ref,
212  - and the new objectname to be stored in the ref.
214 A zero exit from the update hook allows the ref to be updated.
215 Exiting with a non-zero status prevents 'git-receive-pack'
216 from updating that ref.
218 This hook can be used to prevent 'forced' update on certain refs by
219 making sure that the object name is a commit object that is a
220 descendant of the commit object named by the old object name.
221 That is, to enforce a "fast forward only" policy.
223 It could also be used to log the old..new status.  However, it
224 does not know the entire set of branches, so it would end up
225 firing one e-mail per ref when used naively, though.  The
226 <<post-receive,'post-receive'>> hook is more suited to that.
228 Another use suggested on the mailing list is to use this hook to
229 implement access control which is finer grained than the one
230 based on filesystem group.
232 Both standard output and standard error output are forwarded to
233 'git-send-pack' on the other end, so you can simply `echo` messages
234 for the user.
236 The default 'update' hook, when enabled--and with
237 `hooks.allowunannotated` config option turned on--prevents
238 unannotated tags to be pushed.
240 [[post-receive]]
241 post-receive
242 ------------
244 This hook is invoked by 'git-receive-pack' on the remote repository,
245 which happens when a 'git-push' is done on a local repository.
246 It executes on the remote repository once after all the refs have
247 been updated.
249 This hook executes once for the receive operation.  It takes no
250 arguments, but gets the same information as the
251 <<pre-receive,'pre-receive'>>
252 hook does on its standard input.
254 This hook does not affect the outcome of 'git-receive-pack', as it
255 is called after the real work is done.
257 This supersedes the <<post-update,'post-update'>> hook in that it gets
258 both old and new values of all the refs in addition to their
259 names.
261 Both standard output and standard error output are forwarded to
262 'git-send-pack' on the other end, so you can simply `echo` messages
263 for the user.
265 The default 'post-receive' hook is empty, but there is
266 a sample script `post-receive-email` provided in the `contrib/hooks`
267 directory in git distribution, which implements sending commit
268 emails.
270 [[post-update]]
271 post-update
272 -----------
274 This hook is invoked by 'git-receive-pack' on the remote repository,
275 which happens when a 'git-push' is done on a local repository.
276 It executes on the remote repository once after all the refs have
277 been updated.
279 It takes a variable number of parameters, each of which is the
280 name of ref that was actually updated.
282 This hook is meant primarily for notification, and cannot affect
283 the outcome of 'git-receive-pack'.
285 The 'post-update' hook can tell what are the heads that were pushed,
286 but it does not know what their original and updated values are,
287 so it is a poor place to do log old..new. The
288 <<post-receive,'post-receive'>> hook does get both original and
289 updated values of the refs. You might consider it instead if you need
290 them.
292 When enabled, the default 'post-update' hook runs
293 'git-update-server-info' to keep the information used by dumb
294 transports (e.g., HTTP) up-to-date.  If you are publishing
295 a git repository that is accessible via HTTP, you should
296 probably enable this hook.
298 Both standard output and standard error output are forwarded to
299 'git-send-pack' on the other end, so you can simply `echo` messages
300 for the user.
302 pre-auto-gc
303 -----------
305 This hook is invoked by 'git-gc --auto'. It takes no parameter, and
306 exiting with non-zero status from this script causes the 'git-gc --auto'
307 to abort.
311 Part of the linkgit:git[1] suite