Make git_dir a path relative to work_tree in setup_work_tree()
[git/dscho.git] / Documentation / githooks.txt
blob4f06ae0ed4bd625bf5a33fca215c90fb1b5810c9
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, make it executable with `chmod +x`.
22 This document describes the currently defined hooks.
24 applypatch-msg
25 --------------
27 This hook is invoked by `git-am` script.  It takes a single
28 parameter, the name of the file that holds the proposed commit
29 log message.  Exiting with non-zero status causes
30 `git-am` to abort before applying the patch.
32 The hook is allowed to edit the message file in place, and can
33 be used to normalize the message into some project standard
34 format (if the project has one). It can also be used to refuse
35 the commit after inspecting the message file.
37 The default 'applypatch-msg' hook, when enabled, runs the
38 'commit-msg' hook, if the latter is enabled.
40 pre-applypatch
41 --------------
43 This hook is invoked by `git-am`.  It takes no parameter, and is
44 invoked after the patch is applied, but before a commit is made.
46 If it exits with non-zero status, then the working tree will not be
47 committed after applying the patch.
49 It can be used to inspect the current working tree and refuse to
50 make a commit if it does not pass certain test.
52 The default 'pre-applypatch' hook, when enabled, runs the
53 'pre-commit' hook, if the latter is enabled.
55 post-applypatch
56 ---------------
58 This hook is invoked by `git-am`.  It takes no parameter,
59 and is invoked after the patch is applied and a commit is made.
61 This hook is meant primarily for notification, and cannot affect
62 the outcome of `git-am`.
64 pre-commit
65 ----------
67 This hook is invoked by `git-commit`, and can be bypassed
68 with `\--no-verify` option.  It takes no parameter, and is
69 invoked before obtaining the proposed commit log message and
70 making a commit.  Exiting with non-zero status from this script
71 causes the `git-commit` to abort.
73 The default 'pre-commit' hook, when enabled, catches introduction
74 of lines with trailing whitespaces and aborts the commit when
75 such a line is found.
77 All the `git-commit` hooks are invoked with the environment
78 variable `GIT_EDITOR=:` if the command will not bring up an editor
79 to modify the commit message.
81 prepare-commit-msg
82 ------------------
84 This hook is invoked by `git-commit` right after preparing the
85 default log message, and before the editor is started.
87 It takes one to three parameters.  The first is the name of the file
88 that the commit log message.  The second is the source of the commit
89 message, and can be: `message` (if a `\-m` or `\-F` option was
90 given); `template` (if a `\-t` option was given or the
91 configuration option `commit.template` is set); `merge` (if the
92 commit is a merge or a `.git/MERGE_MSG` file exists); `squash`
93 (if a `.git/SQUASH_MSG` file exists); or `commit`, followed by
94 a commit SHA1 (if a `\-c`, `\-C` or `\--amend` option was given).
96 If the exit status is non-zero, `git-commit` will abort.
98 The purpose of the hook is to edit the message file in place, and
99 it is not suppressed by the `\--no-verify` option.  A non-zero exit
100 means a failure of the hook and aborts the commit.  It should not
101 be used as replacement for pre-commit hook.
103 The sample `prepare-commit-msg` hook that comes with git comments
104 out the `Conflicts:` part of a merge's commit message.
106 commit-msg
107 ----------
109 This hook is invoked by `git-commit`, and can be bypassed
110 with `\--no-verify` option.  It takes a single parameter, the
111 name of the file that holds the proposed commit log message.
112 Exiting with non-zero status causes the `git-commit` to
113 abort.
115 The hook is allowed to edit the message file in place, and can
116 be used to normalize the message into some project standard
117 format (if the project has one). It can also be used to refuse
118 the commit after inspecting the message file.
120 The default 'commit-msg' hook, when enabled, detects duplicate
121 "Signed-off-by" lines, and aborts the commit if one is found.
123 post-commit
124 -----------
126 This hook is invoked by `git-commit`.  It takes no
127 parameter, and is invoked after a commit is made.
129 This hook is meant primarily for notification, and cannot affect
130 the outcome of `git-commit`.
132 post-checkout
133 -----------
135 This hook is invoked when a `git-checkout` is run after having updated the
136 worktree.  The hook is given three parameters: the ref of the previous HEAD,
137 the ref of the new HEAD (which may or may not have changed), and a flag
138 indicating whether the checkout was a branch checkout (changing branches,
139 flag=1) or a file checkout (retrieving a file from the index, flag=0).
140 This hook cannot affect the outcome of `git-checkout`.
142 This hook can be used to perform repository validity checks, auto-display
143 differences from the previous HEAD if different, or set working dir metadata
144 properties.
146 post-merge
147 -----------
149 This hook is invoked by `git-merge`, which happens when a `git pull`
150 is done on a local repository.  The hook takes a single parameter, a status
151 flag specifying whether or not the merge being done was a squash merge.
152 This hook cannot affect the outcome of `git-merge` and is not executed,
153 if the merge failed due to conflicts.
155 This hook can be used in conjunction with a corresponding pre-commit hook to
156 save and restore any form of metadata associated with the working tree
157 (eg: permissions/ownership, ACLS, etc).  See contrib/hooks/setgitperms.perl
158 for an example of how to do this.
160 [[pre-receive]]
161 pre-receive
162 -----------
164 This hook is invoked by `git-receive-pack` on the remote repository,
165 which happens when a `git push` is done on a local repository.
166 Just before starting to update refs on the remote repository, the
167 pre-receive hook is invoked.  Its exit status determines the success
168 or failure of the update.
170 This hook executes once for the receive operation. It takes no
171 arguments, but for each ref to be updated it receives on standard
172 input a line of the format:
174   <old-value> SP <new-value> SP <ref-name> LF
176 where `<old-value>` is the old object name stored in the ref,
177 `<new-value>` is the new object name to be stored in the ref and
178 `<ref-name>` is the full name of the ref.
179 When creating a new ref, `<old-value>` is 40 `0`.
181 If the hook exits with non-zero status, none of the refs will be
182 updated. If the hook exits with zero, updating of individual refs can
183 still be prevented by the <<update,'update'>> hook.
185 Both standard output and standard error output are forwarded to
186 `git-send-pack` on the other end, so you can simply `echo` messages
187 for the user.
189 [[update]]
190 update
191 ------
193 This hook is invoked by `git-receive-pack` on the remote repository,
194 which happens when a `git push` is done on a local repository.
195 Just before updating the ref on the remote repository, the update hook
196 is invoked.  Its exit status determines the success or failure of
197 the ref update.
199 The hook executes once for each ref to be updated, and takes
200 three parameters:
202  - the name of the ref being updated,
203  - the old object name stored in the ref,
204  - and the new objectname to be stored in the ref.
206 A zero exit from the update hook allows the ref to be updated.
207 Exiting with a non-zero status prevents `git-receive-pack`
208 from updating that ref.
210 This hook can be used to prevent 'forced' update on certain refs by
211 making sure that the object name is a commit object that is a
212 descendant of the commit object named by the old object name.
213 That is, to enforce a "fast forward only" policy.
215 It could also be used to log the old..new status.  However, it
216 does not know the entire set of branches, so it would end up
217 firing one e-mail per ref when used naively, though.  The
218 <<post-receive,'post-receive'>> hook is more suited to that.
220 Another use suggested on the mailing list is to use this hook to
221 implement access control which is finer grained than the one
222 based on filesystem group.
224 Both standard output and standard error output are forwarded to
225 `git-send-pack` on the other end, so you can simply `echo` messages
226 for the user.
228 The default 'update' hook, when enabled--and with
229 `hooks.allowunannotated` config option turned on--prevents
230 unannotated tags to be pushed.
232 [[post-receive]]
233 post-receive
234 ------------
236 This hook is invoked by `git-receive-pack` on the remote repository,
237 which happens when a `git push` is done on a local repository.
238 It executes on the remote repository once after all the refs have
239 been updated.
241 This hook executes once for the receive operation.  It takes no
242 arguments, but gets the same information as the
243 <<pre-receive,'pre-receive'>>
244 hook does on its standard input.
246 This hook does not affect the outcome of `git-receive-pack`, as it
247 is called after the real work is done.
249 This supersedes the <<post-update,'post-update'>> hook in that it gets
250 both old and new values of all the refs in addition to their
251 names.
253 Both standard output and standard error output are forwarded to
254 `git-send-pack` on the other end, so you can simply `echo` messages
255 for the user.
257 The default 'post-receive' hook is empty, but there is
258 a sample script `post-receive-email` provided in the `contrib/hooks`
259 directory in git distribution, which implements sending commit
260 emails.
262 [[post-update]]
263 post-update
264 -----------
266 This hook is invoked by `git-receive-pack` on the remote repository,
267 which happens when a `git push` is done on a local repository.
268 It executes on the remote repository once after all the refs have
269 been updated.
271 It takes a variable number of parameters, each of which is the
272 name of ref that was actually updated.
274 This hook is meant primarily for notification, and cannot affect
275 the outcome of `git-receive-pack`.
277 The 'post-update' hook can tell what are the heads that were pushed,
278 but it does not know what their original and updated values are,
279 so it is a poor place to do log old..new. The
280 <<post-receive,'post-receive'>> hook does get both original and
281 updated values of the refs. You might consider it instead if you need
282 them.
284 When enabled, the default 'post-update' hook runs
285 `git-update-server-info` to keep the information used by dumb
286 transports (e.g., HTTP) up-to-date.  If you are publishing
287 a git repository that is accessible via HTTP, you should
288 probably enable this hook.
290 Both standard output and standard error output are forwarded to
291 `git-send-pack` on the other end, so you can simply `echo` messages
292 for the user.
294 pre-auto-gc
295 -----------
297 This hook is invoked by `git-gc --auto`. It takes no parameter, and
298 exiting with non-zero status from this script causes the `git-gc --auto`
299 to abort.
303 Part of the linkgit:git[1] suite