Don't try and percent-escape existing percent escapes in git-svn URIs
[git/dscho.git] / Documentation / hooks.txt
blob76b8d77460e961fda9a5505a4ce0cf20788de133
1 Hooks used by git
2 =================
4 Hooks are little scripts you can place in `$GIT_DIR/hooks`
5 directory to trigger action at certain points.  When
6 `git-init` is run, a handful example hooks are copied in the
7 `hooks` directory of the new repository, but by default they are
8 all disabled.  To enable a hook, make it executable with `chmod +x`.
10 This document describes the currently defined hooks.
12 applypatch-msg
13 --------------
15 This hook is invoked by `git-am` script.  It takes a single
16 parameter, the name of the file that holds the proposed commit
17 log message.  Exiting with non-zero status causes
18 `git-am` to abort before applying the patch.
20 The hook is allowed to edit the message file in place, and can
21 be used to normalize the message into some project standard
22 format (if the project has one). It can also be used to refuse
23 the commit after inspecting the message file.
25 The default 'applypatch-msg' hook, when enabled, runs the
26 'commit-msg' hook, if the latter is enabled.
28 pre-applypatch
29 --------------
31 This hook is invoked by `git-am`.  It takes no parameter,
32 and is invoked after the patch is applied, but before a commit
33 is made.  Exiting with non-zero status causes the working tree
34 after application of the patch not committed.
36 It can be used to inspect the current working tree and refuse to
37 make a commit if it does not pass certain test.
39 The default 'pre-applypatch' hook, when enabled, runs the
40 'pre-commit' hook, if the latter is enabled.
42 post-applypatch
43 ---------------
45 This hook is invoked by `git-am`.  It takes no parameter,
46 and is invoked after the patch is applied and a commit is made.
48 This hook is meant primarily for notification, and cannot affect
49 the outcome of `git-am`.
51 pre-commit
52 ----------
54 This hook is invoked by `git-commit`, and can be bypassed
55 with `\--no-verify` option.  It takes no parameter, and is
56 invoked before obtaining the proposed commit log message and
57 making a commit.  Exiting with non-zero status from this script
58 causes the `git-commit` to abort.
60 The default 'pre-commit' hook, when enabled, catches introduction
61 of lines with trailing whitespaces and aborts the commit when
62 such a line is found.
64 All the `git-commit` hooks are invoked with the environment
65 variable `GIT_EDITOR=:` if the command will not bring up an editor
66 to modify the commit message.
68 prepare-commit-msg
69 ------------------
71 This hook is invoked by `git-commit` right after preparing the
72 default log message, and before the editor is started.
74 It takes one to three parameters.  The first is the name of the file
75 that the commit log message.  The second is the source of the commit
76 message, and can be: `message` (if a `\-m` or `\-F` option was
77 given); `template` (if a `\-t` option was given or the
78 configuration option `commit.template` is set); `merge` (if the
79 commit is a merge or a `.git/MERGE_MSG` file exists); `squash`
80 (if a `.git/SQUASH_MSG` file exists); or `commit`, followed by
81 a commit SHA1 (if a `\-c`, `\-C` or `\--amend` option was given).
83 If the exit status is non-zero, `git-commit` will abort.
85 The purpose of the hook is to edit the message file in place, and
86 it is not suppressed by the `\--no-verify` option.  A non-zero exit
87 means a failure of the hook and aborts the commit.  It should not
88 be used as replacement for pre-commit hook.
90 The sample `prepare-commit-msg` hook that comes with git comments
91 out the `Conflicts:` part of a merge's commit message.
93 commit-msg
94 ----------
96 This hook is invoked by `git-commit`, and can be bypassed
97 with `\--no-verify` option.  It takes a single parameter, the
98 name of the file that holds the proposed commit log message.
99 Exiting with non-zero status causes the `git-commit` to
100 abort.
102 The hook is allowed to edit the message file in place, and can
103 be used to normalize the message into some project standard
104 format (if the project has one). It can also be used to refuse
105 the commit after inspecting the message file.
107 The default 'commit-msg' hook, when enabled, detects duplicate
108 "Signed-off-by" lines, and aborts the commit if one is found.
110 post-commit
111 -----------
113 This hook is invoked by `git-commit`.  It takes no
114 parameter, and is invoked after a commit is made.
116 This hook is meant primarily for notification, and cannot affect
117 the outcome of `git-commit`.
119 post-checkout
120 -----------
122 This hook is invoked when a `git-checkout` is run after having updated the
123 worktree.  The hook is given three parameters: the ref of the previous HEAD,
124 the ref of the new HEAD (which may or may not have changed), and a flag
125 indicating whether the checkout was a branch checkout (changing branches,
126 flag=1) or a file checkout (retrieving a file from the index, flag=0).
127 This hook cannot affect the outcome of `git-checkout`.
129 This hook can be used to perform repository validity checks, auto-display
130 differences from the previous HEAD if different, or set working dir metadata
131 properties.
133 post-merge
134 -----------
136 This hook is invoked by `git-merge`, which happens when a `git pull`
137 is done on a local repository.  The hook takes a single parameter, a status
138 flag specifying whether or not the merge being done was a squash merge.
139 This hook cannot affect the outcome of `git-merge`.
141 This hook can be used in conjunction with a corresponding pre-commit hook to
142 save and restore any form of metadata associated with the working tree
143 (eg: permissions/ownership, ACLS, etc).  See contrib/hooks/setgitperms.perl
144 for an example of how to do this.
146 [[pre-receive]]
147 pre-receive
148 -----------
150 This hook is invoked by `git-receive-pack` on the remote repository,
151 which happens when a `git push` is done on a local repository.
152 Just before starting to update refs on the remote repository, the
153 pre-receive hook is invoked.  Its exit status determines the success
154 or failure of the update.
156 This hook executes once for the receive operation. It takes no
157 arguments, but for each ref to be updated it receives on standard
158 input a line of the format:
160   <old-value> SP <new-value> SP <ref-name> LF
162 where `<old-value>` is the old object name stored in the ref,
163 `<new-value>` is the new object name to be stored in the ref and
164 `<ref-name>` is the full name of the ref.
165 When creating a new ref, `<old-value>` is 40 `0`.
167 If the hook exits with non-zero status, none of the refs will be
168 updated. If the hook exits with zero, updating of individual refs can
169 still be prevented by the <<update,'update'>> hook.
171 Both standard output and standard error output are forwarded to
172 `git-send-pack` on the other end, so you can simply `echo` messages
173 for the user.
175 [[update]]
176 update
177 ------
179 This hook is invoked by `git-receive-pack` on the remote repository,
180 which happens when a `git push` is done on a local repository.
181 Just before updating the ref on the remote repository, the update hook
182 is invoked.  Its exit status determines the success or failure of
183 the ref update.
185 The hook executes once for each ref to be updated, and takes
186 three parameters:
188  - the name of the ref being updated,
189  - the old object name stored in the ref,
190  - and the new objectname to be stored in the ref.
192 A zero exit from the update hook allows the ref to be updated.
193 Exiting with a non-zero status prevents `git-receive-pack`
194 from updating that ref.
196 This hook can be used to prevent 'forced' update on certain refs by
197 making sure that the object name is a commit object that is a
198 descendant of the commit object named by the old object name.
199 That is, to enforce a "fast forward only" policy.
201 It could also be used to log the old..new status.  However, it
202 does not know the entire set of branches, so it would end up
203 firing one e-mail per ref when used naively, though.  The
204 <<post-receive,'post-receive'>> hook is more suited to that.
206 Another use suggested on the mailing list is to use this hook to
207 implement access control which is finer grained than the one
208 based on filesystem group.
210 Both standard output and standard error output are forwarded to
211 `git-send-pack` on the other end, so you can simply `echo` messages
212 for the user.
214 The default 'update' hook, when enabled--and with
215 `hooks.allowunannotated` config option turned on--prevents
216 unannotated tags to be pushed.
218 [[post-receive]]
219 post-receive
220 ------------
222 This hook is invoked by `git-receive-pack` on the remote repository,
223 which happens when a `git push` is done on a local repository.
224 It executes on the remote repository once after all the refs have
225 been updated.
227 This hook executes once for the receive operation.  It takes no
228 arguments, but gets the same information as the
229 <<pre-receive,'pre-receive'>>
230 hook does on its standard input.
232 This hook does not affect the outcome of `git-receive-pack`, as it
233 is called after the real work is done.
235 This supersedes the <<post-update,'post-update'>> hook in that it gets
236 both old and new values of all the refs in addition to their
237 names.
239 Both standard output and standard error output are forwarded to
240 `git-send-pack` on the other end, so you can simply `echo` messages
241 for the user.
243 The default 'post-receive' hook is empty, but there is
244 a sample script `post-receive-email` provided in the `contrib/hooks`
245 directory in git distribution, which implements sending commit
246 emails.
248 [[post-update]]
249 post-update
250 -----------
252 This hook is invoked by `git-receive-pack` on the remote repository,
253 which happens when a `git push` is done on a local repository.
254 It executes on the remote repository once after all the refs have
255 been updated.
257 It takes a variable number of parameters, each of which is the
258 name of ref that was actually updated.
260 This hook is meant primarily for notification, and cannot affect
261 the outcome of `git-receive-pack`.
263 The 'post-update' hook can tell what are the heads that were pushed,
264 but it does not know what their original and updated values are,
265 so it is a poor place to do log old..new. The
266 <<post-receive,'post-receive'>> hook does get both original and
267 updated values of the refs. You might consider it instead if you need
268 them.
270 When enabled, the default 'post-update' hook runs
271 `git-update-server-info` to keep the information used by dumb
272 transports (e.g., HTTP) up-to-date.  If you are publishing
273 a git repository that is accessible via HTTP, you should
274 probably enable this hook.
276 Both standard output and standard error output are forwarded to
277 `git-send-pack` on the other end, so you can simply `echo` messages
278 for the user.