]>
Commit | Line | Data |
---|---|---|
a5af0e2c CC |
1 | githooks(5) |
2 | =========== | |
3 | ||
4 | NAME | |
5 | ---- | |
2de9b711 | 6 | githooks - Hooks used by Git |
a5af0e2c CC |
7 | |
8 | SYNOPSIS | |
9 | -------- | |
867ad08a | 10 | $GIT_DIR/hooks/* (or \`git config core.hooksPath`/*) |
a5af0e2c CC |
11 | |
12 | ||
13 | DESCRIPTION | |
14 | ----------- | |
6d35cc76 | 15 | |
867ad08a ÆAB |
16 | Hooks are programs you can place in a hooks directory to trigger |
17 | actions at certain points in git's execution. Hooks that don't have | |
18 | the executable bit set are ignored. | |
19 | ||
20 | By default the hooks directory is `$GIT_DIR/hooks`, but that can be | |
21 | changed via the `core.hooksPath` configuration variable (see | |
22 | linkgit:git-config[1]). | |
49fa52fd ÆAB |
23 | |
24 | Before Git invokes a hook, it changes its working directory to either | |
501d3cd7 SR |
25 | $GIT_DIR in a bare repository or the root of the working tree in a non-bare |
26 | repository. An exception are hooks triggered during a push ('pre-receive', | |
27 | 'update', 'post-receive', 'post-update', 'push-to-checkout') which are always | |
28 | executed in $GIT_DIR. | |
49fa52fd ÆAB |
29 | |
30 | Hooks can get their arguments via the environment, command-line | |
31 | arguments, and stdin. See the documentation for each hook below for | |
32 | details. | |
33 | ||
9dba84d8 | 34 | `git init` may copy hooks to the new repository, depending on its |
49fa52fd ÆAB |
35 | configuration. See the "TEMPLATE DIRECTORY" section in |
36 | linkgit:git-init[1] for details. When the rest of this document refers | |
37 | to "default hooks" it's talking about the default template shipped | |
38 | with Git. | |
39 | ||
40 | The currently supported hooks are described below. | |
6d35cc76 | 41 | |
6d71c1dc BW |
42 | HOOKS |
43 | ----- | |
44 | ||
6d35cc76 | 45 | applypatch-msg |
6d71c1dc | 46 | ~~~~~~~~~~~~~~ |
6d35cc76 | 47 | |
9dba84d8 | 48 | This hook is invoked by linkgit:git-am[1]. It takes a single |
6d35cc76 | 49 | parameter, the name of the file that holds the proposed commit |
9dba84d8 | 50 | log message. Exiting with a non-zero status causes `git am` to abort |
de0824ed | 51 | before applying the patch. |
6d35cc76 JH |
52 | |
53 | The hook is allowed to edit the message file in place, and can | |
54 | be used to normalize the message into some project standard | |
de0824ed ÆAB |
55 | format. It can also be used to refuse the commit after inspecting |
56 | the message file. | |
6d35cc76 | 57 | |
45ad9b50 JF |
58 | The default 'applypatch-msg' hook, when enabled, runs the |
59 | 'commit-msg' hook, if the latter is enabled. | |
6d35cc76 JH |
60 | |
61 | pre-applypatch | |
6d71c1dc | 62 | ~~~~~~~~~~~~~~ |
6d35cc76 | 63 | |
9dba84d8 | 64 | This hook is invoked by linkgit:git-am[1]. It takes no parameter, and is |
47458bb9 CC |
65 | invoked after the patch is applied, but before a commit is made. |
66 | ||
67 | If it exits with non-zero status, then the working tree will not be | |
68 | committed after applying the patch. | |
6d35cc76 JH |
69 | |
70 | It can be used to inspect the current working tree and refuse to | |
71 | make a commit if it does not pass certain test. | |
72 | ||
45ad9b50 JF |
73 | The default 'pre-applypatch' hook, when enabled, runs the |
74 | 'pre-commit' hook, if the latter is enabled. | |
6d35cc76 JH |
75 | |
76 | post-applypatch | |
6d71c1dc | 77 | ~~~~~~~~~~~~~~~ |
6d35cc76 | 78 | |
9dba84d8 | 79 | This hook is invoked by linkgit:git-am[1]. It takes no parameter, |
6d35cc76 JH |
80 | and is invoked after the patch is applied and a commit is made. |
81 | ||
82 | This hook is meant primarily for notification, and cannot affect | |
9dba84d8 | 83 | the outcome of `git am`. |
6d35cc76 JH |
84 | |
85 | pre-commit | |
6d71c1dc | 86 | ~~~~~~~~~~ |
6d35cc76 | 87 | |
9dba84d8 | 88 | This hook is invoked by linkgit:git-commit[1], and can be bypassed |
de0824ed | 89 | with the `--no-verify` option. It takes no parameters, and is |
6d35cc76 | 90 | invoked before obtaining the proposed commit log message and |
de0824ed | 91 | making a commit. Exiting with a non-zero status from this script |
9dba84d8 | 92 | causes the `git commit` command to abort before creating a commit. |
6d35cc76 | 93 | |
45ad9b50 | 94 | The default 'pre-commit' hook, when enabled, catches introduction |
6d35cc76 | 95 | of lines with trailing whitespaces and aborts the commit when |
45ad9b50 | 96 | such a line is found. |
6d35cc76 | 97 | |
9dba84d8 | 98 | All the `git commit` hooks are invoked with the environment |
406400ce PB |
99 | variable `GIT_EDITOR=:` if the command will not bring up an editor |
100 | to modify the commit message. | |
101 | ||
3e14dd2c RD |
102 | The default 'pre-commit' hook, when enabled--and with the |
103 | `hooks.allownonascii` config option unset or set to false--prevents | |
104 | the use of non-ASCII filenames. | |
105 | ||
6098817f MG |
106 | pre-merge-commit |
107 | ~~~~~~~~~~~~~~~~ | |
108 | ||
bc40ce4d MG |
109 | This hook is invoked by linkgit:git-merge[1], and can be bypassed |
110 | with the `--no-verify` option. It takes no parameters, and is | |
6098817f MG |
111 | invoked after the merge has been carried out successfully and before |
112 | obtaining the proposed commit log message to | |
113 | make a commit. Exiting with a non-zero status from this script | |
114 | causes the `git merge` command to abort before creating a commit. | |
115 | ||
116 | The default 'pre-merge-commit' hook, when enabled, runs the | |
117 | 'pre-commit' hook, if the latter is enabled. | |
118 | ||
119 | This hook is invoked with the environment variable | |
120 | `GIT_EDITOR=:` if the command will not bring up an editor | |
121 | to modify the commit message. | |
122 | ||
123 | If the merge cannot be carried out automatically, the conflicts | |
124 | need to be resolved and the result committed separately (see | |
125 | linkgit:git-merge[1]). At that point, this hook will not be executed, | |
126 | but the 'pre-commit' hook will, if it is enabled. | |
127 | ||
8089c85b | 128 | prepare-commit-msg |
6d71c1dc | 129 | ~~~~~~~~~~~~~~~~~~ |
8089c85b | 130 | |
9dba84d8 | 131 | This hook is invoked by linkgit:git-commit[1] right after preparing the |
8089c85b PB |
132 | default log message, and before the editor is started. |
133 | ||
134 | It takes one to three parameters. The first is the name of the file | |
99686960 | 135 | that contains the commit log message. The second is the source of the commit |
5d6b3a9e SG |
136 | message, and can be: `message` (if a `-m` or `-F` option was |
137 | given); `template` (if a `-t` option was given or the | |
8089c85b PB |
138 | configuration option `commit.template` is set); `merge` (if the |
139 | commit is a merge or a `.git/MERGE_MSG` file exists); `squash` | |
140 | (if a `.git/SQUASH_MSG` file exists); or `commit`, followed by | |
5f308a89 | 141 | a commit object name (if a `-c`, `-C` or `--amend` option was given). |
8089c85b | 142 | |
9dba84d8 | 143 | If the exit status is non-zero, `git commit` will abort. |
8089c85b PB |
144 | |
145 | The purpose of the hook is to edit the message file in place, and | |
6cf378f0 | 146 | it is not suppressed by the `--no-verify` option. A non-zero exit |
8089c85b PB |
147 | means a failure of the hook and aborts the commit. It should not |
148 | be used as replacement for pre-commit hook. | |
149 | ||
0ef1a4e3 KS |
150 | The sample `prepare-commit-msg` hook that comes with Git removes the |
151 | help message found in the commented portion of the commit template. | |
152 | ||
6d35cc76 | 153 | commit-msg |
6d71c1dc | 154 | ~~~~~~~~~~ |
6d35cc76 | 155 | |
9dba84d8 | 156 | This hook is invoked by linkgit:git-commit[1] and linkgit:git-merge[1], and can be |
ce82eddf SB |
157 | bypassed with the `--no-verify` option. It takes a single parameter, |
158 | the name of the file that holds the proposed commit log message. | |
159 | Exiting with a non-zero status causes the command to abort. | |
6d35cc76 | 160 | |
de0824ed ÆAB |
161 | The hook is allowed to edit the message file in place, and can be used |
162 | to normalize the message into some project standard format. It | |
163 | can also be used to refuse the commit after inspecting the message | |
164 | file. | |
6d35cc76 | 165 | |
45ad9b50 | 166 | The default 'commit-msg' hook, when enabled, detects duplicate |
3abd4a67 | 167 | `Signed-off-by` trailers, and aborts the commit if one is found. |
6d35cc76 JH |
168 | |
169 | post-commit | |
6d71c1dc | 170 | ~~~~~~~~~~~ |
6d35cc76 | 171 | |
9dba84d8 | 172 | This hook is invoked by linkgit:git-commit[1]. It takes no parameters, and is |
de0824ed | 173 | invoked after a commit is made. |
6d35cc76 JH |
174 | |
175 | This hook is meant primarily for notification, and cannot affect | |
9dba84d8 | 176 | the outcome of `git commit`. |
6d35cc76 | 177 | |
00e5d48a | 178 | pre-rebase |
6d71c1dc | 179 | ~~~~~~~~~~ |
00e5d48a | 180 | |
9dba84d8 | 181 | This hook is called by linkgit:git-rebase[1] and can be used to prevent a |
0414acc3 TK |
182 | branch from getting rebased. The hook may be called with one or |
183 | two parameters. The first parameter is the upstream from which | |
184 | the series was forked. The second parameter is the branch being | |
185 | rebased, and is not set when rebasing the current branch. | |
00e5d48a | 186 | |
1abbe475 | 187 | post-checkout |
6d71c1dc | 188 | ~~~~~~~~~~~~~ |
1abbe475 | 189 | |
d787d311 NTND |
190 | This hook is invoked when a linkgit:git-checkout[1] or |
191 | linkgit:git-switch[1] is run after having updated the | |
1abbe475 JE |
192 | worktree. The hook is given three parameters: the ref of the previous HEAD, |
193 | the ref of the new HEAD (which may or may not have changed), and a flag | |
194 | indicating whether the checkout was a branch checkout (changing branches, | |
195 | flag=1) or a file checkout (retrieving a file from the index, flag=0). | |
3100fd55 JH |
196 | This hook cannot affect the outcome of `git switch` or `git checkout`, |
197 | other than that the hook's exit status becomes the exit status of | |
198 | these two commands. | |
1abbe475 | 199 | |
9dba84d8 | 200 | It is also run after linkgit:git-clone[1], unless the `--no-checkout` (`-n`) option is |
24c11552 | 201 | used. The first parameter given to the hook is the null-ref, the second the |
9dba84d8 AH |
202 | ref of the new HEAD and the flag is always 1. Likewise for `git worktree add` |
203 | unless `--no-checkout` is used. | |
24c11552 | 204 | |
1abbe475 JE |
205 | This hook can be used to perform repository validity checks, auto-display |
206 | differences from the previous HEAD if different, or set working dir metadata | |
207 | properties. | |
208 | ||
46232915 | 209 | post-merge |
6d71c1dc | 210 | ~~~~~~~~~~ |
46232915 | 211 | |
9dba84d8 | 212 | This hook is invoked by linkgit:git-merge[1], which happens when a `git pull` |
46232915 JE |
213 | is done on a local repository. The hook takes a single parameter, a status |
214 | flag specifying whether or not the merge being done was a squash merge. | |
9dba84d8 | 215 | This hook cannot affect the outcome of `git merge` and is not executed, |
2b3e60c2 | 216 | if the merge failed due to conflicts. |
46232915 JE |
217 | |
218 | This hook can be used in conjunction with a corresponding pre-commit hook to | |
219 | save and restore any form of metadata associated with the working tree | |
f745acb0 | 220 | (e.g.: permissions/ownership, ACLS, etc). See contrib/hooks/setgitperms.perl |
af6fb4c8 | 221 | for an example of how to do this. |
46232915 | 222 | |
ec55559f AS |
223 | pre-push |
224 | ~~~~~~~~ | |
225 | ||
9dba84d8 AH |
226 | This hook is called by linkgit:git-push[1] and can be used to prevent |
227 | a push from taking place. The hook is called with two parameters | |
228 | which provide the name and location of the destination remote, if a | |
229 | named remote is not being used both values will be the same. | |
ec55559f AS |
230 | |
231 | Information about what is to be pushed is provided on the hook's standard | |
232 | input with lines of the form: | |
233 | ||
5f308a89 | 234 | <local ref> SP <local object name> SP <remote ref> SP <remote object name> LF |
ec55559f AS |
235 | |
236 | For instance, if the command +git push origin master:foreign+ were run the | |
237 | hook would receive a line like the following: | |
238 | ||
239 | refs/heads/master 67890 refs/heads/foreign 12345 | |
240 | ||
5f308a89 PS |
241 | although the full object name would be supplied. If the foreign ref does not |
242 | yet exist the `<remote object name>` will be the all-zeroes object name. If a | |
243 | ref is to be deleted, the `<local ref>` will be supplied as `(delete)` and the | |
244 | `<local object name>` will be the all-zeroes object name. If the local commit | |
245 | was specified by something other than a name which could be expanded (such as | |
246 | `HEAD~`, or an object name) it will be supplied as it was originally given. | |
ec55559f | 247 | |
9dba84d8 | 248 | If this hook exits with a non-zero status, `git push` will abort without |
ec55559f AS |
249 | pushing anything. Information about why the push is rejected may be sent |
250 | to the user by writing to standard error. | |
251 | ||
cbb84e5d JH |
252 | [[pre-receive]] |
253 | pre-receive | |
6d71c1dc | 254 | ~~~~~~~~~~~ |
cbb84e5d | 255 | |
9dba84d8 AH |
256 | This hook is invoked by linkgit:git-receive-pack[1] when it reacts to |
257 | `git push` and updates reference(s) in its repository. | |
cbb84e5d JH |
258 | Just before starting to update refs on the remote repository, the |
259 | pre-receive hook is invoked. Its exit status determines the success | |
260 | or failure of the update. | |
261 | ||
262 | This hook executes once for the receive operation. It takes no | |
263 | arguments, but for each ref to be updated it receives on standard | |
264 | input a line of the format: | |
265 | ||
266 | <old-value> SP <new-value> SP <ref-name> LF | |
267 | ||
268 | where `<old-value>` is the old object name stored in the ref, | |
269 | `<new-value>` is the new object name to be stored in the ref and | |
270 | `<ref-name>` is the full name of the ref. | |
5f308a89 | 271 | When creating a new ref, `<old-value>` is the all-zeroes object name. |
cbb84e5d JH |
272 | |
273 | If the hook exits with non-zero status, none of the refs will be | |
274 | updated. If the hook exits with zero, updating of individual refs can | |
275 | still be prevented by the <<update,'update'>> hook. | |
276 | ||
24a0d61e | 277 | Both standard output and standard error output are forwarded to |
9dba84d8 | 278 | `git send-pack` on the other end, so you can simply `echo` messages |
24a0d61e | 279 | for the user. |
cbb84e5d | 280 | |
77a9745d SB |
281 | The number of push options given on the command line of |
282 | `git push --push-option=...` can be read from the environment | |
283 | variable `GIT_PUSH_OPTION_COUNT`, and the options themselves are | |
284 | found in `GIT_PUSH_OPTION_0`, `GIT_PUSH_OPTION_1`,... | |
285 | If it is negotiated to not use the push options phase, the | |
286 | environment variables will not be set. If the client selects | |
287 | to use push options, but doesn't transmit any, the count variable | |
288 | will be set to zero, `GIT_PUSH_OPTION_COUNT=0`. | |
289 | ||
eaeed077 JK |
290 | See the section on "Quarantine Environment" in |
291 | linkgit:git-receive-pack[1] for some caveats. | |
292 | ||
cbb84e5d | 293 | [[update]] |
6d35cc76 | 294 | update |
6d71c1dc | 295 | ~~~~~~ |
6d35cc76 | 296 | |
9dba84d8 AH |
297 | This hook is invoked by linkgit:git-receive-pack[1] when it reacts to |
298 | `git push` and updates reference(s) in its repository. | |
6250ad1e | 299 | Just before updating the ref on the remote repository, the update hook |
37425065 | 300 | is invoked. Its exit status determines the success or failure of |
6250ad1e JL |
301 | the ref update. |
302 | ||
303 | The hook executes once for each ref to be updated, and takes | |
304 | three parameters: | |
45ad9b50 JF |
305 | |
306 | - the name of the ref being updated, | |
307 | - the old object name stored in the ref, | |
5fe8f49b | 308 | - and the new object name to be stored in the ref. |
6250ad1e JL |
309 | |
310 | A zero exit from the update hook allows the ref to be updated. | |
9dba84d8 | 311 | Exiting with a non-zero status prevents `git receive-pack` |
cbb84e5d | 312 | from updating that ref. |
6250ad1e JL |
313 | |
314 | This hook can be used to prevent 'forced' update on certain refs by | |
6d35cc76 JH |
315 | making sure that the object name is a commit object that is a |
316 | descendant of the commit object named by the old object name. | |
a75d7b54 | 317 | That is, to enforce a "fast-forward only" policy. |
6250ad1e JL |
318 | |
319 | It could also be used to log the old..new status. However, it | |
320 | does not know the entire set of branches, so it would end up | |
cbb84e5d JH |
321 | firing one e-mail per ref when used naively, though. The |
322 | <<post-receive,'post-receive'>> hook is more suited to that. | |
6250ad1e | 323 | |
bf7d977f ÆAB |
324 | In an environment that restricts the users' access only to git |
325 | commands over the wire, this hook can be used to implement access | |
326 | control without relying on filesystem ownership and group | |
327 | membership. See linkgit:git-shell[1] for how you might use the login | |
328 | shell to restrict the user's access to only git commands. | |
6d35cc76 | 329 | |
24a0d61e | 330 | Both standard output and standard error output are forwarded to |
9dba84d8 | 331 | `git send-pack` on the other end, so you can simply `echo` messages |
24a0d61e | 332 | for the user. |
3aadad1b | 333 | |
cbb84e5d | 334 | The default 'update' hook, when enabled--and with |
39c448c1 | 335 | `hooks.allowunannotated` config option unset or set to false--prevents |
cbb84e5d JH |
336 | unannotated tags to be pushed. |
337 | ||
d6edc189 JX |
338 | [[proc-receive]] |
339 | proc-receive | |
340 | ~~~~~~~~~~~~ | |
341 | ||
342 | This hook is invoked by linkgit:git-receive-pack[1]. If the server has | |
343 | set the multi-valued config variable `receive.procReceiveRefs`, and the | |
344 | commands sent to 'receive-pack' have matching reference names, these | |
345 | commands will be executed by this hook, instead of by the internal | |
346 | `execute_commands()` function. This hook is responsible for updating | |
347 | the relevant references and reporting the results back to 'receive-pack'. | |
348 | ||
349 | This hook executes once for the receive operation. It takes no | |
350 | arguments, but uses a pkt-line format protocol to communicate with | |
351 | 'receive-pack' to read commands, push-options and send results. In the | |
352 | following example for the protocol, the letter 'S' stands for | |
353 | 'receive-pack' and the letter 'H' stands for this hook. | |
354 | ||
355 | # Version and features negotiation. | |
356 | S: PKT-LINE(version=1\0push-options atomic...) | |
357 | S: flush-pkt | |
358 | H: PKT-LINE(version=1\0push-options...) | |
359 | H: flush-pkt | |
360 | ||
361 | # Send commands from server to the hook. | |
362 | S: PKT-LINE(<old-oid> <new-oid> <ref>) | |
363 | S: ... ... | |
364 | S: flush-pkt | |
365 | # Send push-options only if the 'push-options' feature is enabled. | |
366 | S: PKT-LINE(push-option) | |
367 | S: ... ... | |
368 | S: flush-pkt | |
369 | ||
370 | # Receive result from the hook. | |
371 | # OK, run this command successfully. | |
372 | H: PKT-LINE(ok <ref>) | |
373 | # NO, I reject it. | |
374 | H: PKT-LINE(ng <ref> <reason>) | |
375 | # Fall through, let 'receive-pack' to execute it. | |
376 | H: PKT-LINE(ok <ref>) | |
377 | H: PKT-LINE(option fall-through) | |
378 | # OK, but has an alternate reference. The alternate reference name | |
379 | # and other status can be given in option directives. | |
380 | H: PKT-LINE(ok <ref>) | |
381 | H: PKT-LINE(option refname <refname>) | |
382 | H: PKT-LINE(option old-oid <old-oid>) | |
383 | H: PKT-LINE(option new-oid <new-oid>) | |
384 | H: PKT-LINE(option forced-update) | |
385 | H: ... ... | |
386 | H: flush-pkt | |
387 | ||
388 | Each command for the 'proc-receive' hook may point to a pseudo-reference | |
389 | and always has a zero-old as its old-oid, while the 'proc-receive' hook | |
390 | may update an alternate reference and the alternate reference may exist | |
391 | already with a non-zero old-oid. For this case, this hook will use | |
392 | "option" directives to report extended attributes for the reference given | |
393 | by the leading "ok" directive. | |
394 | ||
395 | The report of the commands of this hook should have the same order as | |
396 | the input. The exit status of the 'proc-receive' hook only determines | |
397 | the success or failure of the group of commands sent to it, unless | |
398 | atomic push is in use. | |
399 | ||
cbb84e5d JH |
400 | [[post-receive]] |
401 | post-receive | |
6d71c1dc | 402 | ~~~~~~~~~~~~ |
6250ad1e | 403 | |
9dba84d8 AH |
404 | This hook is invoked by linkgit:git-receive-pack[1] when it reacts to |
405 | `git push` and updates reference(s) in its repository. | |
cbb84e5d JH |
406 | It executes on the remote repository once after all the refs have |
407 | been updated. | |
408 | ||
409 | This hook executes once for the receive operation. It takes no | |
24a0d61e JH |
410 | arguments, but gets the same information as the |
411 | <<pre-receive,'pre-receive'>> | |
cbb84e5d JH |
412 | hook does on its standard input. |
413 | ||
9dba84d8 | 414 | This hook does not affect the outcome of `git receive-pack`, as it |
cbb84e5d JH |
415 | is called after the real work is done. |
416 | ||
02783075 | 417 | This supersedes the <<post-update,'post-update'>> hook in that it gets |
24a0d61e JH |
418 | both old and new values of all the refs in addition to their |
419 | names. | |
cbb84e5d | 420 | |
24a0d61e | 421 | Both standard output and standard error output are forwarded to |
9dba84d8 | 422 | `git send-pack` on the other end, so you can simply `echo` messages |
24a0d61e | 423 | for the user. |
cbb84e5d JH |
424 | |
425 | The default 'post-receive' hook is empty, but there is | |
426 | a sample script `post-receive-email` provided in the `contrib/hooks` | |
2de9b711 | 427 | directory in Git distribution, which implements sending commit |
cbb84e5d JH |
428 | emails. |
429 | ||
77a9745d SB |
430 | The number of push options given on the command line of |
431 | `git push --push-option=...` can be read from the environment | |
432 | variable `GIT_PUSH_OPTION_COUNT`, and the options themselves are | |
433 | found in `GIT_PUSH_OPTION_0`, `GIT_PUSH_OPTION_1`,... | |
434 | If it is negotiated to not use the push options phase, the | |
435 | environment variables will not be set. If the client selects | |
436 | to use push options, but doesn't transmit any, the count variable | |
437 | will be set to zero, `GIT_PUSH_OPTION_COUNT=0`. | |
438 | ||
cbb84e5d | 439 | [[post-update]] |
6d35cc76 | 440 | post-update |
6d71c1dc | 441 | ~~~~~~~~~~~ |
6d35cc76 | 442 | |
9dba84d8 AH |
443 | This hook is invoked by linkgit:git-receive-pack[1] when it reacts to |
444 | `git push` and updates reference(s) in its repository. | |
6250ad1e JL |
445 | It executes on the remote repository once after all the refs have |
446 | been updated. | |
447 | ||
448 | It takes a variable number of parameters, each of which is the | |
449 | name of ref that was actually updated. | |
6d35cc76 JH |
450 | |
451 | This hook is meant primarily for notification, and cannot affect | |
9dba84d8 | 452 | the outcome of `git receive-pack`. |
6d35cc76 | 453 | |
45ad9b50 | 454 | The 'post-update' hook can tell what are the heads that were pushed, |
6250ad1e | 455 | but it does not know what their original and updated values are, |
24a0d61e JH |
456 | so it is a poor place to do log old..new. The |
457 | <<post-receive,'post-receive'>> hook does get both original and | |
458 | updated values of the refs. You might consider it instead if you need | |
459 | them. | |
cbb84e5d | 460 | |
45ad9b50 | 461 | When enabled, the default 'post-update' hook runs |
9dba84d8 | 462 | `git update-server-info` to keep the information used by dumb |
7560f547 | 463 | transports (e.g., HTTP) up to date. If you are publishing |
2de9b711 | 464 | a Git repository that is accessible via HTTP, you should |
6250ad1e | 465 | probably enable this hook. |
3aadad1b | 466 | |
cbb84e5d | 467 | Both standard output and standard error output are forwarded to |
9dba84d8 | 468 | `git send-pack` on the other end, so you can simply `echo` messages |
24a0d61e | 469 | for the user. |
0b85d926 | 470 | |
6c18d03e BC |
471 | reference-transaction |
472 | ~~~~~~~~~~~~~~~~~~~~~ | |
67541597 PS |
473 | |
474 | This hook is invoked by any Git command that performs reference | |
475 | updates. It executes whenever a reference transaction is prepared, | |
23c781f1 PS |
476 | committed or aborted and may thus get called multiple times. The hook |
477 | does not cover symbolic references (but that may change in the future). | |
67541597 PS |
478 | |
479 | The hook takes exactly one argument, which is the current state the | |
480 | given reference transaction is in: | |
481 | ||
482 | - "prepared": All reference updates have been queued to the | |
483 | transaction and references were locked on disk. | |
484 | ||
485 | - "committed": The reference transaction was committed and all | |
486 | references now have their respective new value. | |
487 | ||
488 | - "aborted": The reference transaction was aborted, no changes | |
489 | were performed and the locks have been released. | |
490 | ||
491 | For each reference update that was added to the transaction, the hook | |
492 | receives on standard input a line of the format: | |
493 | ||
494 | <old-value> SP <new-value> SP <ref-name> LF | |
495 | ||
23c781f1 PS |
496 | where `<old-value>` is the old object name passed into the reference |
497 | transaction, `<new-value>` is the new object name to be stored in the | |
498 | ref and `<ref-name>` is the full name of the ref. When force updating | |
499 | the reference regardless of its current value or when the reference is | |
500 | to be created anew, `<old-value>` is the all-zeroes object name. To | |
501 | distinguish these cases, you can inspect the current value of | |
502 | `<ref-name>` via `git rev-parse`. | |
503 | ||
67541597 PS |
504 | The exit status of the hook is ignored for any state except for the |
505 | "prepared" state. In the "prepared" state, a non-zero exit status will | |
506 | cause the transaction to be aborted. The hook will not be called with | |
507 | "aborted" state in that case. | |
508 | ||
08553319 JH |
509 | push-to-checkout |
510 | ~~~~~~~~~~~~~~~~ | |
511 | ||
9dba84d8 AH |
512 | This hook is invoked by linkgit:git-receive-pack[1] when it reacts to |
513 | `git push` and updates reference(s) in its repository, and when | |
08553319 JH |
514 | the push tries to update the branch that is currently checked out |
515 | and the `receive.denyCurrentBranch` configuration variable is set to | |
516 | `updateInstead`. Such a push by default is refused if the working | |
517 | tree and the index of the remote repository has any difference from | |
518 | the currently checked out commit; when both the working tree and the | |
519 | index match the current commit, they are updated to match the newly | |
520 | pushed tip of the branch. This hook is to be used to override the | |
521 | default behaviour. | |
522 | ||
523 | The hook receives the commit with which the tip of the current | |
524 | branch is going to be updated. It can exit with a non-zero status | |
525 | to refuse the push (when it does so, it must not modify the index or | |
526 | the working tree). Or it can make any necessary changes to the | |
527 | working tree and to the index to bring them to the desired state | |
528 | when the tip of the current branch is updated to the new commit, and | |
529 | exit with a zero status. | |
530 | ||
531 | For example, the hook can simply run `git read-tree -u -m HEAD "$1"` | |
9dba84d8 AH |
532 | in order to emulate `git fetch` that is run in the reverse direction |
533 | with `git push`, as the two-tree form of `git read-tree -u -m` is | |
d787d311 NTND |
534 | essentially the same as `git switch` or `git checkout` |
535 | that switches branches while | |
08553319 JH |
536 | keeping the local changes in the working tree that do not interfere |
537 | with the difference between the branches. | |
538 | ||
539 | ||
0b85d926 | 540 | pre-auto-gc |
6d71c1dc | 541 | ~~~~~~~~~~~ |
0b85d926 | 542 | |
9dba84d8 AH |
543 | This hook is invoked by `git gc --auto` (see linkgit:git-gc[1]). It |
544 | takes no parameter, and exiting with non-zero status from this script | |
545 | causes the `git gc --auto` to abort. | |
a5af0e2c | 546 | |
c0fc6869 TR |
547 | post-rewrite |
548 | ~~~~~~~~~~~~ | |
549 | ||
9dba84d8 AH |
550 | This hook is invoked by commands that rewrite commits |
551 | (linkgit:git-commit[1] when called with `--amend` and | |
9df53c5d EN |
552 | linkgit:git-rebase[1]; however, full-history (re)writing tools like |
553 | linkgit:git-fast-import[1] or | |
554 | https://github.com/newren/git-filter-repo[git-filter-repo] typically | |
555 | do not call it!). Its first argument denotes the command it was | |
556 | invoked by: currently one of `amend` or `rebase`. Further | |
557 | command-dependent arguments may be passed in the future. | |
c0fc6869 TR |
558 | |
559 | The hook receives a list of the rewritten commits on stdin, in the | |
560 | format | |
561 | ||
5f308a89 | 562 | <old-object-name> SP <new-object-name> [ SP <extra-info> ] LF |
c0fc6869 TR |
563 | |
564 | The 'extra-info' is again command-dependent. If it is empty, the | |
565 | preceding SP is also omitted. Currently, no commands pass any | |
566 | 'extra-info'. | |
567 | ||
6956f858 | 568 | The hook always runs after the automatic note copying (see |
ad52148a | 569 | "notes.rewrite.<command>" in linkgit:git-config[1]) has happened, and |
6956f858 TR |
570 | thus has access to these notes. |
571 | ||
c0fc6869 TR |
572 | The following command-specific comments apply: |
573 | ||
574 | rebase:: | |
575 | For the 'squash' and 'fixup' operation, all commits that were | |
576 | squashed are listed as being rewritten to the squashed commit. | |
577 | This means that there will be several lines sharing the same | |
5f308a89 | 578 | 'new-object-name'. |
c0fc6869 TR |
579 | + |
580 | The commits are guaranteed to be listed in the order that they were | |
581 | processed by rebase. | |
582 | ||
6489660b JT |
583 | sendemail-validate |
584 | ~~~~~~~~~~~~~~~~~~ | |
585 | ||
9dba84d8 | 586 | This hook is invoked by linkgit:git-send-email[1]. It takes a single parameter, |
6489660b | 587 | the name of the file that holds the e-mail to be sent. Exiting with a |
9dba84d8 | 588 | non-zero status causes `git send-email` to abort before sending any |
6489660b JT |
589 | e-mails. |
590 | ||
780494b1 BP |
591 | fsmonitor-watchman |
592 | ~~~~~~~~~~~~~~~~~~ | |
593 | ||
9dba84d8 | 594 | This hook is invoked when the configuration option `core.fsmonitor` is |
dfaed028 KW |
595 | set to `.git/hooks/fsmonitor-watchman` or `.git/hooks/fsmonitor-watchmanv2` |
596 | depending on the version of the hook to use. | |
597 | ||
598 | Version 1 takes two arguments, a version (1) and the time in elapsed | |
599 | nanoseconds since midnight, January 1, 1970. | |
600 | ||
601 | Version 2 takes two arguments, a version (2) and a token that is used | |
602 | for identifying changes since the token. For watchman this would be | |
603 | a clock id. This version must output to stdout the new token followed | |
604 | by a NUL before the list of files. | |
780494b1 BP |
605 | |
606 | The hook should output to stdout the list of all files in the working | |
607 | directory that may have changed since the requested time. The logic | |
608 | should be inclusive so that it does not miss any potential changes. | |
609 | The paths should be relative to the root of the working directory | |
610 | and be separated by a single NUL. | |
611 | ||
612 | It is OK to include files which have not actually changed. All changes | |
613 | including newly-created and deleted files should be included. When | |
614 | files are renamed, both the old and the new name should be included. | |
615 | ||
616 | Git will limit what files it checks for changes as well as which | |
617 | directories are checked for untracked files based on the path names | |
618 | given. | |
619 | ||
620 | An optimized way to tell git "all files have changed" is to return | |
9dba84d8 | 621 | the filename `/`. |
780494b1 BP |
622 | |
623 | The exit status determines whether git will use the data from the | |
624 | hook to limit its search. On error, it will fall back to verifying | |
625 | all files and folders. | |
c0fc6869 | 626 | |
38ecf752 BK |
627 | p4-changelist |
628 | ~~~~~~~~~~~~~ | |
629 | ||
630 | This hook is invoked by `git-p4 submit`. | |
631 | ||
632 | The `p4-changelist` hook is executed after the changelist | |
633 | message has been edited by the user. It can be bypassed with the | |
634 | `--no-verify` option. It takes a single parameter, the name | |
635 | of the file that holds the proposed changelist text. Exiting | |
636 | with a non-zero status causes the command to abort. | |
637 | ||
638 | The hook is allowed to edit the changelist file and can be used | |
639 | to normalize the text into some project standard format. It can | |
640 | also be used to refuse the Submit after inspect the message file. | |
641 | ||
642 | Run `git-p4 submit --help` for details. | |
643 | ||
644 | p4-prepare-changelist | |
645 | ~~~~~~~~~~~~~~~~~~~~~ | |
646 | ||
647 | This hook is invoked by `git-p4 submit`. | |
648 | ||
649 | The `p4-prepare-changelist` hook is executed right after preparing | |
650 | the default changelist message and before the editor is started. | |
651 | It takes one parameter, the name of the file that contains the | |
652 | changelist text. Exiting with a non-zero status from the script | |
653 | will abort the process. | |
654 | ||
655 | The purpose of the hook is to edit the message file in place, | |
7efc3782 | 656 | and it is not suppressed by the `--no-verify` option. This hook |
38ecf752 BK |
657 | is called even if `--prepare-p4-only` is set. |
658 | ||
659 | Run `git-p4 submit --help` for details. | |
660 | ||
661 | p4-post-changelist | |
662 | ~~~~~~~~~~~~~~~~~~ | |
663 | ||
664 | This hook is invoked by `git-p4 submit`. | |
665 | ||
666 | The `p4-post-changelist` hook is invoked after the submit has | |
b7e20b43 | 667 | successfully occurred in P4. It takes no parameters and is meant |
38ecf752 BK |
668 | primarily for notification and cannot affect the outcome of the |
669 | git p4 submit action. | |
670 | ||
671 | Run `git-p4 submit --help` for details. | |
672 | ||
251c8c50 CB |
673 | p4-pre-submit |
674 | ~~~~~~~~~~~~~ | |
675 | ||
676 | This hook is invoked by `git-p4 submit`. It takes no parameters and nothing | |
677 | from standard input. Exiting with non-zero status from this script prevent | |
4935c458 BK |
678 | `git-p4 submit` from launching. It can be bypassed with the `--no-verify` |
679 | command line option. Run `git-p4 submit --help` for details. | |
680 | ||
681 | ||
251c8c50 | 682 | |
1956ecd0 BP |
683 | post-index-change |
684 | ~~~~~~~~~~~~~~~~~ | |
685 | ||
686 | This hook is invoked when the index is written in read-cache.c | |
687 | do_write_locked_index. | |
688 | ||
689 | The first parameter passed to the hook is the indicator for the | |
690 | working directory being updated. "1" meaning working directory | |
691 | was updated or "0" when the working directory was not updated. | |
692 | ||
693 | The second parameter passed to the hook is the indicator for whether | |
694 | or not the index was updated and the skip-worktree bit could have | |
695 | changed. "1" meaning skip-worktree bits could have been updated | |
696 | and "0" meaning they were not. | |
697 | ||
698 | Only one parameter should be set to "1" when the hook runs. The hook | |
699 | running passing "1", "1" should not be possible. | |
700 | ||
a5af0e2c CC |
701 | GIT |
702 | --- | |
9e1f0a85 | 703 | Part of the linkgit:git[1] suite |