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