Merge branch 'seq-builtin-dev' into mymaster
[git/sbeyer.git] / Documentation / githooks.txt
blobc47d36e6be17e7d6404f9a072b9db0fe59a4962e
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 applypatch-msg
30 --------------
32 This hook is invoked by 'git-am' script.  It takes a single
33 parameter, the name of the file that holds the proposed commit
34 log message.  Exiting with non-zero status causes
35 'git-am' to abort before applying the patch.
37 The hook is allowed to edit the message file in place, and can
38 be used to normalize the message into some project standard
39 format (if the project has one). It can also be used to refuse
40 the commit after inspecting the message file.
42 The default 'applypatch-msg' hook, when enabled, runs the
43 'commit-msg' hook, if the latter is enabled.
45 pre-applypatch
46 --------------
48 This hook is invoked by 'git-am'.  It takes no parameter, and is
49 invoked after the patch is applied, but before a commit is made.
51 If it exits with non-zero status, then the working tree will not be
52 committed after applying the patch.
54 It can be used to inspect the current working tree and refuse to
55 make a commit if it does not pass certain test.
57 The default 'pre-applypatch' hook, when enabled, runs the
58 'pre-commit' hook, if the latter is enabled.
60 post-applypatch
61 ---------------
63 This hook is invoked by 'git-am'.  It takes no parameter,
64 and is invoked after the patch is applied and a commit is made.
66 This hook is meant primarily for notification, and cannot affect
67 the outcome of 'git-am'.
69 pre-commit
70 ----------
72 This hook is invoked by 'git-commit', and can be bypassed
73 with `\--no-verify` option.  It takes no parameter, and is
74 invoked before obtaining the proposed commit log message and
75 making a commit.  Exiting with non-zero status from this script
76 causes the 'git-commit' to abort.
78 The default 'pre-commit' hook, when enabled, catches introduction
79 of lines with trailing whitespaces and aborts the commit when
80 such a line is found.
82 All the 'git-commit' hooks are invoked with the environment
83 variable `GIT_EDITOR=:` if the command will not bring up an editor
84 to modify the commit message.
86 prepare-commit-msg
87 ------------------
89 This hook is invoked by 'git-commit'
90 and 'git-sequencer' right after preparing the
91 default log message, and before the editor is started.
93 It takes one to three parameters.  The first is the name of the file
94 that contains the commit log message.  The second is the source of the commit
95 message, and can be: `message` (if a `-m` or `-F` option was
96 given to 'git-commit'); `template` (if a `-t` option was given or the
97 configuration option `commit.template` is set); `merge` (if the
98 commit is a merge or a `.git/MERGE_MSG` file exists); `squash`
99 (if a `.git/SQUASH_MSG` file exists); or `commit`, followed by
100 a commit SHA1 (if a `-c`, `-C` or `\--amend` option was given).
102 If the exit status is non-zero, 'git-commit' will abort.
104 The purpose of the hook is to edit the message file in place, and
105 it is not suppressed by the `\--no-verify` option.  A non-zero exit
106 means a failure of the hook and aborts the commit.  It should not
107 be used as replacement for pre-commit hook.
109 The sample `prepare-commit-msg` hook that comes with git comments
110 out the `Conflicts:` part of a merge's commit message.
112 commit-msg
113 ----------
115 This hook is invoked by 'git-commit', and can be bypassed
116 with `\--no-verify` option.  It takes a single parameter, the
117 name of the file that holds the proposed commit log message.
118 Exiting with non-zero status causes the 'git-commit' to
119 abort.
121 The hook is allowed to edit the message file in place, and can
122 be used to normalize the message into some project standard
123 format (if the project has one). It can also be used to refuse
124 the commit after inspecting the message file.
126 The default 'commit-msg' hook, when enabled, detects duplicate
127 "Signed-off-by" lines, and aborts the commit if one is found.
129 post-commit
130 -----------
132 This hook is invoked by 'git-commit'.  It takes no
133 parameter, and is invoked after a commit is made.
135 This hook is meant primarily for notification, and cannot affect
136 the outcome of 'git-commit'.
138 pre-rebase
139 ----------
141 This hook is called by 'git-rebase' and can be used to prevent a branch
142 from getting rebased.
145 post-checkout
146 -----------
148 This hook is invoked when a 'git-checkout' is run after having updated the
149 worktree.  The hook is given three parameters: the ref of the previous HEAD,
150 the ref of the new HEAD (which may or may not have changed), and a flag
151 indicating whether the checkout was a branch checkout (changing branches,
152 flag=1) or a file checkout (retrieving a file from the index, flag=0).
153 This hook cannot affect the outcome of 'git-checkout'.
155 It is also run after 'git-clone', unless the --no-checkout (-n) option is
156 used. The first parameter given to the hook is the null-ref, the second the
157 ref of the new HEAD and the flag is always 1.
159 This hook can be used to perform repository validity checks, auto-display
160 differences from the previous HEAD if different, or set working dir metadata
161 properties.
163 post-merge
164 -----------
166 This hook is invoked by 'git-merge', which happens when a 'git-pull'
167 is done on a local repository.  The hook takes a single parameter, a status
168 flag specifying whether or not the merge being done was a squash merge.
169 This hook cannot affect the outcome of 'git-merge' and is not executed,
170 if the merge failed due to conflicts.
172 This hook can be used in conjunction with a corresponding pre-commit hook to
173 save and restore any form of metadata associated with the working tree
174 (eg: permissions/ownership, ACLS, etc).  See contrib/hooks/setgitperms.perl
175 for an example of how to do this.
177 [[pre-receive]]
178 pre-receive
179 -----------
181 This hook is invoked by 'git-receive-pack' on the remote repository,
182 which happens when a 'git-push' is done on a local repository.
183 Just before starting to update refs on the remote repository, the
184 pre-receive hook is invoked.  Its exit status determines the success
185 or failure of the update.
187 This hook executes once for the receive operation. It takes no
188 arguments, but for each ref to be updated it receives on standard
189 input a line of the format:
191   <old-value> SP <new-value> SP <ref-name> LF
193 where `<old-value>` is the old object name stored in the ref,
194 `<new-value>` is the new object name to be stored in the ref and
195 `<ref-name>` is the full name of the ref.
196 When creating a new ref, `<old-value>` is 40 `0`.
198 If the hook exits with non-zero status, none of the refs will be
199 updated. If the hook exits with zero, updating of individual refs can
200 still be prevented by the <<update,'update'>> hook.
202 Both standard output and standard error output are forwarded to
203 'git-send-pack' on the other end, so you can simply `echo` messages
204 for the user.
206 [[update]]
207 update
208 ------
210 This hook is invoked by 'git-receive-pack' on the remote repository,
211 which happens when a 'git-push' is done on a local repository.
212 Just before updating the ref on the remote repository, the update hook
213 is invoked.  Its exit status determines the success or failure of
214 the ref update.
216 The hook executes once for each ref to be updated, and takes
217 three parameters:
219  - the name of the ref being updated,
220  - the old object name stored in the ref,
221  - and the new objectname to be stored in the ref.
223 A zero exit from the update hook allows the ref to be updated.
224 Exiting with a non-zero status prevents 'git-receive-pack'
225 from updating that ref.
227 This hook can be used to prevent 'forced' update on certain refs by
228 making sure that the object name is a commit object that is a
229 descendant of the commit object named by the old object name.
230 That is, to enforce a "fast forward only" policy.
232 It could also be used to log the old..new status.  However, it
233 does not know the entire set of branches, so it would end up
234 firing one e-mail per ref when used naively, though.  The
235 <<post-receive,'post-receive'>> hook is more suited to that.
237 Another use suggested on the mailing list is to use this hook to
238 implement access control which is finer grained than the one
239 based on filesystem group.
241 Both standard output and standard error output are forwarded to
242 'git-send-pack' on the other end, so you can simply `echo` messages
243 for the user.
245 The default 'update' hook, when enabled--and with
246 `hooks.allowunannotated` config option turned on--prevents
247 unannotated tags to be pushed.
249 [[post-receive]]
250 post-receive
251 ------------
253 This hook is invoked by 'git-receive-pack' on the remote repository,
254 which happens when a 'git-push' is done on a local repository.
255 It executes on the remote repository once after all the refs have
256 been updated.
258 This hook executes once for the receive operation.  It takes no
259 arguments, but gets the same information as the
260 <<pre-receive,'pre-receive'>>
261 hook does on its standard input.
263 This hook does not affect the outcome of 'git-receive-pack', as it
264 is called after the real work is done.
266 This supersedes the <<post-update,'post-update'>> hook in that it gets
267 both old and new values of all the refs in addition to their
268 names.
270 Both standard output and standard error output are forwarded to
271 'git-send-pack' on the other end, so you can simply `echo` messages
272 for the user.
274 The default 'post-receive' hook is empty, but there is
275 a sample script `post-receive-email` provided in the `contrib/hooks`
276 directory in git distribution, which implements sending commit
277 emails.
279 [[post-update]]
280 post-update
281 -----------
283 This hook is invoked by 'git-receive-pack' on the remote repository,
284 which happens when a 'git-push' is done on a local repository.
285 It executes on the remote repository once after all the refs have
286 been updated.
288 It takes a variable number of parameters, each of which is the
289 name of ref that was actually updated.
291 This hook is meant primarily for notification, and cannot affect
292 the outcome of 'git-receive-pack'.
294 The 'post-update' hook can tell what are the heads that were pushed,
295 but it does not know what their original and updated values are,
296 so it is a poor place to do log old..new. The
297 <<post-receive,'post-receive'>> hook does get both original and
298 updated values of the refs. You might consider it instead if you need
299 them.
301 When enabled, the default 'post-update' hook runs
302 'git-update-server-info' to keep the information used by dumb
303 transports (e.g., HTTP) up-to-date.  If you are publishing
304 a git repository that is accessible via HTTP, you should
305 probably enable this hook.
307 Both standard output and standard error output are forwarded to
308 'git-send-pack' on the other end, so you can simply `echo` messages
309 for the user.
311 pre-auto-gc
312 -----------
314 This hook is invoked by 'git-gc --auto'. It takes no parameter, and
315 exiting with non-zero status from this script causes the 'git-gc --auto'
316 to abort.
320 Part of the linkgit:git[1] suite