]>
Commit | Line | Data |
---|---|---|
72e9340c | 1 | Hooks used by git |
6d35cc76 | 2 | ================= |
6d35cc76 JH |
3 | |
4 | Hooks are little scripts you can place in `$GIT_DIR/hooks` | |
5 | directory to trigger action at certain points. When | |
5c94f87e | 6 | `git-init` is run, a handful example hooks are copied in the |
6d35cc76 | 7 | `hooks` directory of the new repository, but by default they are |
45ad9b50 | 8 | all disabled. To enable a hook, make it executable with `chmod +x`. |
6d35cc76 JH |
9 | |
10 | This document describes the currently defined hooks. | |
11 | ||
12 | applypatch-msg | |
13 | -------------- | |
14 | ||
15 | This hook is invoked by `git-applypatch` script, which is | |
16 | typically invoked by `git-applymbox`. It takes a single | |
17 | parameter, the name of the file that holds the proposed commit | |
45ad9b50 JF |
18 | log message. Exiting with non-zero status causes |
19 | `git-applypatch` to abort before applying the patch. | |
6d35cc76 JH |
20 | |
21 | The hook is allowed to edit the message file in place, and can | |
22 | be used to normalize the message into some project standard | |
23 | format (if the project has one). It can also be used to refuse | |
24 | the commit after inspecting the message file. | |
25 | ||
45ad9b50 JF |
26 | The default 'applypatch-msg' hook, when enabled, runs the |
27 | 'commit-msg' hook, if the latter is enabled. | |
6d35cc76 JH |
28 | |
29 | pre-applypatch | |
30 | -------------- | |
31 | ||
32 | This hook is invoked by `git-applypatch` script, which is | |
33 | typically invoked by `git-applymbox`. It takes no parameter, | |
34 | and is invoked after the patch is applied, but before a commit | |
35 | is made. Exiting with non-zero status causes the working tree | |
36 | after application of the patch not committed. | |
37 | ||
38 | It can be used to inspect the current working tree and refuse to | |
39 | make a commit if it does not pass certain test. | |
40 | ||
45ad9b50 JF |
41 | The default 'pre-applypatch' hook, when enabled, runs the |
42 | 'pre-commit' hook, if the latter is enabled. | |
6d35cc76 JH |
43 | |
44 | post-applypatch | |
45 | --------------- | |
46 | ||
47 | This hook is invoked by `git-applypatch` script, which is | |
48 | typically invoked by `git-applymbox`. It takes no parameter, | |
49 | and is invoked after the patch is applied and a commit is made. | |
50 | ||
51 | This hook is meant primarily for notification, and cannot affect | |
52 | the outcome of `git-applypatch`. | |
53 | ||
54 | pre-commit | |
55 | ---------- | |
56 | ||
215a7ad1 | 57 | This hook is invoked by `git-commit`, and can be bypassed |
e1ccf53a | 58 | with `\--no-verify` option. It takes no parameter, and is |
6d35cc76 JH |
59 | invoked before obtaining the proposed commit log message and |
60 | making a commit. Exiting with non-zero status from this script | |
215a7ad1 | 61 | causes the `git-commit` to abort. |
6d35cc76 | 62 | |
45ad9b50 | 63 | The default 'pre-commit' hook, when enabled, catches introduction |
6d35cc76 | 64 | of lines with trailing whitespaces and aborts the commit when |
45ad9b50 | 65 | such a line is found. |
6d35cc76 JH |
66 | |
67 | commit-msg | |
68 | ---------- | |
69 | ||
215a7ad1 | 70 | This hook is invoked by `git-commit`, and can be bypassed |
e1ccf53a | 71 | with `\--no-verify` option. It takes a single parameter, the |
6d35cc76 | 72 | name of the file that holds the proposed commit log message. |
215a7ad1 | 73 | Exiting with non-zero status causes the `git-commit` to |
6d35cc76 JH |
74 | abort. |
75 | ||
76 | The hook is allowed to edit the message file in place, and can | |
77 | be used to normalize the message into some project standard | |
78 | format (if the project has one). It can also be used to refuse | |
79 | the commit after inspecting the message file. | |
80 | ||
45ad9b50 JF |
81 | The default 'commit-msg' hook, when enabled, detects duplicate |
82 | "Signed-off-by" lines, and aborts the commit if one is found. | |
6d35cc76 JH |
83 | |
84 | post-commit | |
85 | ----------- | |
86 | ||
215a7ad1 | 87 | This hook is invoked by `git-commit`. It takes no |
6d35cc76 JH |
88 | parameter, and is invoked after a commit is made. |
89 | ||
90 | This hook is meant primarily for notification, and cannot affect | |
215a7ad1 | 91 | the outcome of `git-commit`. |
6d35cc76 | 92 | |
6d35cc76 JH |
93 | update |
94 | ------ | |
95 | ||
6250ad1e | 96 | This hook is invoked by `git-receive-pack` on the remote repository, |
45ad9b50 | 97 | which happens when a `git push` is done on a local repository. |
6250ad1e | 98 | Just before updating the ref on the remote repository, the update hook |
37425065 | 99 | is invoked. Its exit status determines the success or failure of |
6250ad1e JL |
100 | the ref update. |
101 | ||
102 | The hook executes once for each ref to be updated, and takes | |
103 | three parameters: | |
45ad9b50 JF |
104 | |
105 | - the name of the ref being updated, | |
106 | - the old object name stored in the ref, | |
107 | - and the new objectname to be stored in the ref. | |
6250ad1e JL |
108 | |
109 | A zero exit from the update hook allows the ref to be updated. | |
110 | Exiting with a non-zero status prevents `git-receive-pack` | |
111 | from updating the ref. | |
112 | ||
113 | This hook can be used to prevent 'forced' update on certain refs by | |
6d35cc76 JH |
114 | making sure that the object name is a commit object that is a |
115 | descendant of the commit object named by the old object name. | |
6250ad1e JL |
116 | That is, to enforce a "fast forward only" policy. |
117 | ||
118 | It could also be used to log the old..new status. However, it | |
119 | does not know the entire set of branches, so it would end up | |
120 | firing one e-mail per ref when used naively, though. | |
121 | ||
6d35cc76 JH |
122 | Another use suggested on the mailing list is to use this hook to |
123 | implement access control which is finer grained than the one | |
124 | based on filesystem group. | |
125 | ||
87a3d29f | 126 | The standard output of this hook is sent to `stderr`, so if you |
45ad9b50 | 127 | want to report something to the `git-send-pack` on the other end, |
87a3d29f | 128 | you can simply `echo` your messages. |
3aadad1b | 129 | |
0d18e41e AP |
130 | The default 'update' hook, when enabled, demonstrates how to |
131 | send out a notification e-mail. | |
6250ad1e | 132 | |
6d35cc76 JH |
133 | post-update |
134 | ----------- | |
135 | ||
6250ad1e | 136 | This hook is invoked by `git-receive-pack` on the remote repository, |
45ad9b50 | 137 | which happens when a `git push` is done on a local repository. |
6250ad1e JL |
138 | It executes on the remote repository once after all the refs have |
139 | been updated. | |
140 | ||
141 | It takes a variable number of parameters, each of which is the | |
142 | name of ref that was actually updated. | |
6d35cc76 JH |
143 | |
144 | This hook is meant primarily for notification, and cannot affect | |
145 | the outcome of `git-receive-pack`. | |
146 | ||
45ad9b50 | 147 | The 'post-update' hook can tell what are the heads that were pushed, |
6250ad1e JL |
148 | but it does not know what their original and updated values are, |
149 | so it is a poor place to do log old..new. | |
150 | ||
45ad9b50 | 151 | When enabled, the default 'post-update' hook runs |
6d35cc76 | 152 | `git-update-server-info` to keep the information used by dumb |
45ad9b50 JF |
153 | transports (e.g., HTTP) up-to-date. If you are publishing |
154 | a git repository that is accessible via HTTP, you should | |
6250ad1e | 155 | probably enable this hook. |
3aadad1b | 156 | |
45ad9b50 JF |
157 | The standard output of this hook is sent to `/dev/null`; if you |
158 | want to report something to the `git-send-pack` on the other end, | |
159 | you can redirect your output to your `stderr`. |