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