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