Add post-merge hook, related documentation, and tests.
[git.git] / Documentation / hooks.txt
blob50535a7983297e8ad1f3202bda13514dfc6b9e9d
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 commit-msg
65 ----------
67 This hook is invoked by `git-commit`, and can be bypassed
68 with `\--no-verify` option.  It takes a single parameter, the
69 name of the file that holds the proposed commit log message.
70 Exiting with non-zero status causes the `git-commit` to
71 abort.
73 The hook is allowed to edit the message file in place, and can
74 be used to normalize the message into some project standard
75 format (if the project has one). It can also be used to refuse
76 the commit after inspecting the message file.
78 The default 'commit-msg' hook, when enabled, detects duplicate
79 "Signed-off-by" lines, and aborts the commit if one is found.
81 post-commit
82 -----------
84 This hook is invoked by `git-commit`.  It takes no
85 parameter, and is invoked after a commit is made.
87 This hook is meant primarily for notification, and cannot affect
88 the outcome of `git-commit`.
90 post-merge
91 -----------
93 This hook is invoked by `git-merge`, which happens when a `git pull`
94 is done on a local repository.  The hook takes a single parameter, a status
95 flag specifying whether or not the merge being done was a squash merge.
96 This hook cannot affect the outcome of `git-merge`.
98 This hook can be used in conjunction with a corresponding pre-commit hook to
99 save and restore any form of metadata associated with the working tree
100 (eg: permissions/ownership, ACLS, etc).
102 [[pre-receive]]
103 pre-receive
104 -----------
106 This hook is invoked by `git-receive-pack` on the remote repository,
107 which happens when a `git push` is done on a local repository.
108 Just before starting to update refs on the remote repository, the
109 pre-receive hook is invoked.  Its exit status determines the success
110 or failure of the update.
112 This hook executes once for the receive operation. It takes no
113 arguments, but for each ref to be updated it receives on standard
114 input a line of the format:
116   <old-value> SP <new-value> SP <ref-name> LF
118 where `<old-value>` is the old object name stored in the ref,
119 `<new-value>` is the new object name to be stored in the ref and
120 `<ref-name>` is the full name of the ref.
121 When creating a new ref, `<old-value>` is 40 `0`.
123 If the hook exits with non-zero status, none of the refs will be
124 updated. If the hook exits with zero, updating of individual refs can
125 still be prevented by the <<update,'update'>> hook.
127 Both standard output and standard error output are forwarded to
128 `git-send-pack` on the other end, so you can simply `echo` messages
129 for the user.
131 [[update]]
132 update
133 ------
135 This hook is invoked by `git-receive-pack` on the remote repository,
136 which happens when a `git push` is done on a local repository.
137 Just before updating the ref on the remote repository, the update hook
138 is invoked.  Its exit status determines the success or failure of
139 the ref update.
141 The hook executes once for each ref to be updated, and takes
142 three parameters:
144  - the name of the ref being updated,
145  - the old object name stored in the ref,
146  - and the new objectname to be stored in the ref.
148 A zero exit from the update hook allows the ref to be updated.
149 Exiting with a non-zero status prevents `git-receive-pack`
150 from updating that ref.
152 This hook can be used to prevent 'forced' update on certain refs by
153 making sure that the object name is a commit object that is a
154 descendant of the commit object named by the old object name.
155 That is, to enforce a "fast forward only" policy.
157 It could also be used to log the old..new status.  However, it
158 does not know the entire set of branches, so it would end up
159 firing one e-mail per ref when used naively, though.  The
160 <<post-receive,'post-receive'>> hook is more suited to that.
162 Another use suggested on the mailing list is to use this hook to
163 implement access control which is finer grained than the one
164 based on filesystem group.
166 Both standard output and standard error output are forwarded to
167 `git-send-pack` on the other end, so you can simply `echo` messages
168 for the user.
170 The default 'update' hook, when enabled--and with
171 `hooks.allowunannotated` config option turned on--prevents
172 unannotated tags to be pushed.
174 [[post-receive]]
175 post-receive
176 ------------
178 This hook is invoked by `git-receive-pack` on the remote repository,
179 which happens when a `git push` is done on a local repository.
180 It executes on the remote repository once after all the refs have
181 been updated.
183 This hook executes once for the receive operation.  It takes no
184 arguments, but gets the same information as the
185 <<pre-receive,'pre-receive'>>
186 hook does on its standard input.
188 This hook does not affect the outcome of `git-receive-pack`, as it
189 is called after the real work is done.
191 This supersedes the <<post-update,'post-update'>> hook in that it gets
192 both old and new values of all the refs in addition to their
193 names.
195 Both standard output and standard error output are forwarded to
196 `git-send-pack` on the other end, so you can simply `echo` messages
197 for the user.
199 The default 'post-receive' hook is empty, but there is
200 a sample script `post-receive-email` provided in the `contrib/hooks`
201 directory in git distribution, which implements sending commit
202 emails.
204 [[post-update]]
205 post-update
206 -----------
208 This hook is invoked by `git-receive-pack` on the remote repository,
209 which happens when a `git push` is done on a local repository.
210 It executes on the remote repository once after all the refs have
211 been updated.
213 It takes a variable number of parameters, each of which is the
214 name of ref that was actually updated.
216 This hook is meant primarily for notification, and cannot affect
217 the outcome of `git-receive-pack`.
219 The 'post-update' hook can tell what are the heads that were pushed,
220 but it does not know what their original and updated values are,
221 so it is a poor place to do log old..new. The
222 <<post-receive,'post-receive'>> hook does get both original and
223 updated values of the refs. You might consider it instead if you need
224 them.
226 When enabled, the default 'post-update' hook runs
227 `git-update-server-info` to keep the information used by dumb
228 transports (e.g., HTTP) up-to-date.  If you are publishing
229 a git repository that is accessible via HTTP, you should
230 probably enable this hook.
232 Both standard output and standard error output are forwarded to
233 `git-send-pack` on the other end, so you can simply `echo` messages
234 for the user.