| Junio C Hamano | 2fbcd21 | 2008-05-14 22:26:07 | [diff] [blame] | 1 | githooks(5) |
| 2 | =========== |
| 3 | |
| 4 | NAME |
| 5 | ---- |
| Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 6 | githooks - Hooks used by Git |
| Junio C Hamano | 2fbcd21 | 2008-05-14 22:26:07 | [diff] [blame] | 7 | |
| 8 | SYNOPSIS |
| 9 | -------- |
| Junio C Hamano | 198b1f1 | 2016-05-17 22:27:24 | [diff] [blame] | 10 | $GIT_DIR/hooks/* (or \`git config core.hooksPath`/*) |
| Junio C Hamano | 2fbcd21 | 2008-05-14 22:26:07 | [diff] [blame] | 11 | |
| 12 | |
| 13 | DESCRIPTION |
| 14 | ----------- |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 15 | |
| Junio C Hamano | 198b1f1 | 2016-05-17 22:27:24 | [diff] [blame] | 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. |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 19 | |
| Junio C Hamano | 198b1f1 | 2016-05-17 22:27:24 | [diff] [blame] | 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]). |
| Junio C Hamano | 8a48fa2 | 2008-12-18 08:44:30 | [diff] [blame] | 23 | |
| Junio C Hamano | 198b1f1 | 2016-05-17 22:27:24 | [diff] [blame] | 24 | Before Git invokes a hook, it changes its working directory to either |
| 25 | the root of the working tree in a non-bare repository, or to the |
| 26 | $GIT_DIR in a bare repository. |
| 27 | |
| 28 | Hooks can get their arguments via the environment, command-line |
| 29 | arguments, and stdin. See the documentation for each hook below for |
| 30 | details. |
| 31 | |
| 32 | 'git init' may copy hooks to the new repository, depending on its |
| 33 | configuration. See the "TEMPLATE DIRECTORY" section in |
| 34 | linkgit:git-init[1] for details. When the rest of this document refers |
| 35 | to "default hooks" it's talking about the default template shipped |
| 36 | with Git. |
| 37 | |
| 38 | The currently supported hooks are described below. |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 39 | |
| Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 40 | HOOKS |
| 41 | ----- |
| 42 | |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 43 | applypatch-msg |
| Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 44 | ~~~~~~~~~~~~~~ |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 45 | |
| Junio C Hamano | 198b1f1 | 2016-05-17 22:27:24 | [diff] [blame] | 46 | This hook is invoked by 'git am'. It takes a single |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 47 | parameter, the name of the file that holds the proposed commit |
| Junio C Hamano | 198b1f1 | 2016-05-17 22:27:24 | [diff] [blame] | 48 | log message. Exiting with a non-zero status causes 'git am' to abort |
| 49 | before applying the patch. |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 50 | |
| 51 | The hook is allowed to edit the message file in place, and can |
| 52 | be used to normalize the message into some project standard |
| Junio C Hamano | 198b1f1 | 2016-05-17 22:27:24 | [diff] [blame] | 53 | format. It can also be used to refuse the commit after inspecting |
| 54 | the message file. |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 55 | |
| Junio C Hamano | d578413 | 2006-09-20 21:29:27 | [diff] [blame] | 56 | The default 'applypatch-msg' hook, when enabled, runs the |
| 57 | 'commit-msg' hook, if the latter is enabled. |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 58 | |
| 59 | pre-applypatch |
| Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 60 | ~~~~~~~~~~~~~~ |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 61 | |
| Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 62 | This hook is invoked by 'git am'. It takes no parameter, and is |
| Junio C Hamano | a31092a | 2008-05-04 06:41:23 | [diff] [blame] | 63 | invoked after the patch is applied, but before a commit is made. |
| 64 | |
| 65 | If it exits with non-zero status, then the working tree will not be |
| 66 | committed after applying the patch. |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 67 | |
| 68 | It can be used to inspect the current working tree and refuse to |
| 69 | make a commit if it does not pass certain test. |
| 70 | |
| Junio C Hamano | d578413 | 2006-09-20 21:29:27 | [diff] [blame] | 71 | The default 'pre-applypatch' hook, when enabled, runs the |
| 72 | 'pre-commit' hook, if the latter is enabled. |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 73 | |
| 74 | post-applypatch |
| Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 75 | ~~~~~~~~~~~~~~~ |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 76 | |
| Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 77 | This hook is invoked by 'git am'. It takes no parameter, |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 78 | and is invoked after the patch is applied and a commit is made. |
| 79 | |
| 80 | This hook is meant primarily for notification, and cannot affect |
| Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 81 | the outcome of 'git am'. |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 82 | |
| 83 | pre-commit |
| Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 84 | ~~~~~~~~~~ |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 85 | |
| Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 86 | This hook is invoked by 'git commit', and can be bypassed |
| Junio C Hamano | 198b1f1 | 2016-05-17 22:27:24 | [diff] [blame] | 87 | with the `--no-verify` option. It takes no parameters, and is |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 88 | invoked before obtaining the proposed commit log message and |
| Junio C Hamano | 198b1f1 | 2016-05-17 22:27:24 | [diff] [blame] | 89 | making a commit. Exiting with a non-zero status from this script |
| 90 | causes the 'git commit' command to abort before creating a commit. |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 91 | |
| Junio C Hamano | d578413 | 2006-09-20 21:29:27 | [diff] [blame] | 92 | The default 'pre-commit' hook, when enabled, catches introduction |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 93 | of lines with trailing whitespaces and aborts the commit when |
| Junio C Hamano | d578413 | 2006-09-20 21:29:27 | [diff] [blame] | 94 | such a line is found. |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 95 | |
| Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 96 | All the 'git commit' hooks are invoked with the environment |
| Junio C Hamano | 26e590a | 2008-02-17 03:53:51 | [diff] [blame] | 97 | variable `GIT_EDITOR=:` if the command will not bring up an editor |
| 98 | to modify the commit message. |
| 99 | |
| 100 | prepare-commit-msg |
| Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 101 | ~~~~~~~~~~~~~~~~~~ |
| Junio C Hamano | 26e590a | 2008-02-17 03:53:51 | [diff] [blame] | 102 | |
| Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 103 | This hook is invoked by 'git commit' right after preparing the |
| Junio C Hamano | 26e590a | 2008-02-17 03:53:51 | [diff] [blame] | 104 | default log message, and before the editor is started. |
| 105 | |
| 106 | It takes one to three parameters. The first is the name of the file |
| Junio C Hamano | bd53dbf | 2009-01-18 18:26:37 | [diff] [blame] | 107 | that contains the commit log message. The second is the source of the commit |
| Junio C Hamano | a476efa | 2008-10-10 15:31:42 | [diff] [blame] | 108 | message, and can be: `message` (if a `-m` or `-F` option was |
| 109 | given); `template` (if a `-t` option was given or the |
| Junio C Hamano | 26e590a | 2008-02-17 03:53:51 | [diff] [blame] | 110 | configuration option `commit.template` is set); `merge` (if the |
| 111 | commit is a merge or a `.git/MERGE_MSG` file exists); `squash` |
| 112 | (if a `.git/SQUASH_MSG` file exists); or `commit`, followed by |
| Junio C Hamano | e3f080d | 2013-04-22 02:27:13 | [diff] [blame] | 113 | a commit SHA-1 (if a `-c`, `-C` or `--amend` option was given). |
| Junio C Hamano | 26e590a | 2008-02-17 03:53:51 | [diff] [blame] | 114 | |
| Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 115 | If the exit status is non-zero, 'git commit' will abort. |
| Junio C Hamano | 26e590a | 2008-02-17 03:53:51 | [diff] [blame] | 116 | |
| 117 | The purpose of the hook is to edit the message file in place, and |
| Junio C Hamano | b76a686 | 2012-05-02 22:02:46 | [diff] [blame] | 118 | it is not suppressed by the `--no-verify` option. A non-zero exit |
| Junio C Hamano | 26e590a | 2008-02-17 03:53:51 | [diff] [blame] | 119 | means a failure of the hook and aborts the commit. It should not |
| 120 | be used as replacement for pre-commit hook. |
| 121 | |
| Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 122 | The sample `prepare-commit-msg` hook that comes with Git comments |
| Junio C Hamano | 26e590a | 2008-02-17 03:53:51 | [diff] [blame] | 123 | out the `Conflicts:` part of a merge's commit message. |
| 124 | |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 125 | commit-msg |
| Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 126 | ~~~~~~~~~~ |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 127 | |
| Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 128 | This hook is invoked by 'git commit', and can be bypassed |
| Junio C Hamano | 198b1f1 | 2016-05-17 22:27:24 | [diff] [blame] | 129 | with the `--no-verify` option. It takes a single parameter, the |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 130 | name of the file that holds the proposed commit log message. |
| Junio C Hamano | 198b1f1 | 2016-05-17 22:27:24 | [diff] [blame] | 131 | Exiting with a non-zero status causes the 'git commit' to |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 132 | abort. |
| 133 | |
| Junio C Hamano | 198b1f1 | 2016-05-17 22:27:24 | [diff] [blame] | 134 | The hook is allowed to edit the message file in place, and can be used |
| 135 | to normalize the message into some project standard format. It |
| 136 | can also be used to refuse the commit after inspecting the message |
| 137 | file. |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 138 | |
| Junio C Hamano | d578413 | 2006-09-20 21:29:27 | [diff] [blame] | 139 | The default 'commit-msg' hook, when enabled, detects duplicate |
| 140 | "Signed-off-by" lines, and aborts the commit if one is found. |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 141 | |
| 142 | post-commit |
| Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 143 | ~~~~~~~~~~~ |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 144 | |
| Junio C Hamano | 198b1f1 | 2016-05-17 22:27:24 | [diff] [blame] | 145 | This hook is invoked by 'git commit'. It takes no parameters, and is |
| 146 | invoked after a commit is made. |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 147 | |
| 148 | This hook is meant primarily for notification, and cannot affect |
| Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 149 | the outcome of 'git commit'. |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 150 | |
| Junio C Hamano | a476efa | 2008-10-10 15:31:42 | [diff] [blame] | 151 | pre-rebase |
| Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 152 | ~~~~~~~~~~ |
| Junio C Hamano | a476efa | 2008-10-10 15:31:42 | [diff] [blame] | 153 | |
| Junio C Hamano | 947ab82 | 2013-03-19 23:07:29 | [diff] [blame] | 154 | This hook is called by 'git rebase' and can be used to prevent a |
| 155 | branch from getting rebased. The hook may be called with one or |
| 156 | two parameters. The first parameter is the upstream from which |
| 157 | the series was forked. The second parameter is the branch being |
| 158 | rebased, and is not set when rebasing the current branch. |
| Junio C Hamano | a476efa | 2008-10-10 15:31:42 | [diff] [blame] | 159 | |
| Junio C Hamano | 1b50ce9 | 2007-10-03 12:05:53 | [diff] [blame] | 160 | post-checkout |
| Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 161 | ~~~~~~~~~~~~~ |
| Junio C Hamano | 1b50ce9 | 2007-10-03 12:05:53 | [diff] [blame] | 162 | |
| Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 163 | This hook is invoked when a 'git checkout' is run after having updated the |
| Junio C Hamano | 1b50ce9 | 2007-10-03 12:05:53 | [diff] [blame] | 164 | worktree. The hook is given three parameters: the ref of the previous HEAD, |
| 165 | the ref of the new HEAD (which may or may not have changed), and a flag |
| 166 | indicating whether the checkout was a branch checkout (changing branches, |
| 167 | flag=1) or a file checkout (retrieving a file from the index, flag=0). |
| Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 168 | This hook cannot affect the outcome of 'git checkout'. |
| Junio C Hamano | 1b50ce9 | 2007-10-03 12:05:53 | [diff] [blame] | 169 | |
| Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 170 | It is also run after 'git clone', unless the --no-checkout (-n) option is |
| Junio C Hamano | 36a5672 | 2009-03-28 08:55:34 | [diff] [blame] | 171 | used. The first parameter given to the hook is the null-ref, the second the |
| 172 | ref of the new HEAD and the flag is always 1. |
| 173 | |
| Junio C Hamano | 1b50ce9 | 2007-10-03 12:05:53 | [diff] [blame] | 174 | This hook can be used to perform repository validity checks, auto-display |
| 175 | differences from the previous HEAD if different, or set working dir metadata |
| 176 | properties. |
| 177 | |
| Junio C Hamano | 01d8f83 | 2007-09-24 07:37:30 | [diff] [blame] | 178 | post-merge |
| Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 179 | ~~~~~~~~~~ |
| Junio C Hamano | 01d8f83 | 2007-09-24 07:37:30 | [diff] [blame] | 180 | |
| Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 181 | This hook is invoked by 'git merge', which happens when a 'git pull' |
| Junio C Hamano | 01d8f83 | 2007-09-24 07:37:30 | [diff] [blame] | 182 | is done on a local repository. The hook takes a single parameter, a status |
| 183 | flag specifying whether or not the merge being done was a squash merge. |
| Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 184 | This hook cannot affect the outcome of 'git merge' and is not executed, |
| Junio C Hamano | 47d68a5 | 2008-05-06 06:35:40 | [diff] [blame] | 185 | if the merge failed due to conflicts. |
| Junio C Hamano | 01d8f83 | 2007-09-24 07:37:30 | [diff] [blame] | 186 | |
| 187 | This hook can be used in conjunction with a corresponding pre-commit hook to |
| 188 | save and restore any form of metadata associated with the working tree |
| Junio C Hamano | fb5ffde | 2014-11-04 22:38:56 | [diff] [blame] | 189 | (e.g.: permissions/ownership, ACLS, etc). See contrib/hooks/setgitperms.perl |
| Junio C Hamano | 01d8f83 | 2007-09-24 07:37:30 | [diff] [blame] | 190 | for an example of how to do this. |
| 191 | |
| Junio C Hamano | 36d5229 | 2013-01-25 21:32:36 | [diff] [blame] | 192 | pre-push |
| 193 | ~~~~~~~~ |
| 194 | |
| 195 | This hook is called by 'git push' and can be used to prevent a push from taking |
| 196 | place. The hook is called with two parameters which provide the name and |
| 197 | location of the destination remote, if a named remote is not being used both |
| 198 | values will be the same. |
| 199 | |
| 200 | Information about what is to be pushed is provided on the hook's standard |
| 201 | input with lines of the form: |
| 202 | |
| 203 | <local ref> SP <local sha1> SP <remote ref> SP <remote sha1> LF |
| 204 | |
| 205 | For instance, if the command +git push origin master:foreign+ were run the |
| 206 | hook would receive a line like the following: |
| 207 | |
| 208 | refs/heads/master 67890 refs/heads/foreign 12345 |
| 209 | |
| Junio C Hamano | e3f080d | 2013-04-22 02:27:13 | [diff] [blame] | 210 | although the full, 40-character SHA-1s would be supplied. If the foreign ref |
| 211 | does not yet exist the `<remote SHA-1>` will be 40 `0`. If a ref is to be |
| Junio C Hamano | 36d5229 | 2013-01-25 21:32:36 | [diff] [blame] | 212 | deleted, the `<local ref>` will be supplied as `(delete)` and the `<local |
| Junio C Hamano | e3f080d | 2013-04-22 02:27:13 | [diff] [blame] | 213 | SHA-1>` will be 40 `0`. If the local commit was specified by something other |
| 214 | than a name which could be expanded (such as `HEAD~`, or a SHA-1) it will be |
| Junio C Hamano | 36d5229 | 2013-01-25 21:32:36 | [diff] [blame] | 215 | supplied as it was originally given. |
| 216 | |
| 217 | If this hook exits with a non-zero status, 'git push' will abort without |
| 218 | pushing anything. Information about why the push is rejected may be sent |
| 219 | to the user by writing to standard error. |
| 220 | |
| Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 221 | [[pre-receive]] |
| 222 | pre-receive |
| Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 223 | ~~~~~~~~~~~ |
| Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 224 | |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 225 | This hook is invoked by 'git-receive-pack' on the remote repository, |
| Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 226 | which happens when a 'git push' is done on a local repository. |
| Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 227 | Just before starting to update refs on the remote repository, the |
| 228 | pre-receive hook is invoked. Its exit status determines the success |
| 229 | or failure of the update. |
| 230 | |
| 231 | This hook executes once for the receive operation. It takes no |
| 232 | arguments, but for each ref to be updated it receives on standard |
| 233 | input a line of the format: |
| 234 | |
| 235 | <old-value> SP <new-value> SP <ref-name> LF |
| 236 | |
| 237 | where `<old-value>` is the old object name stored in the ref, |
| 238 | `<new-value>` is the new object name to be stored in the ref and |
| 239 | `<ref-name>` is the full name of the ref. |
| 240 | When creating a new ref, `<old-value>` is 40 `0`. |
| 241 | |
| 242 | If the hook exits with non-zero status, none of the refs will be |
| 243 | updated. If the hook exits with zero, updating of individual refs can |
| 244 | still be prevented by the <<update,'update'>> hook. |
| 245 | |
| Junio C Hamano | 323e52d | 2007-05-13 22:19:53 | [diff] [blame] | 246 | Both standard output and standard error output are forwarded to |
| Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 247 | 'git send-pack' on the other end, so you can simply `echo` messages |
| Junio C Hamano | 323e52d | 2007-05-13 22:19:53 | [diff] [blame] | 248 | for the user. |
| Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 249 | |
| Junio C Hamano | e48a113 | 2016-08-03 22:40:21 | [diff] [blame] | 250 | The number of push options given on the command line of |
| 251 | `git push --push-option=...` can be read from the environment |
| 252 | variable `GIT_PUSH_OPTION_COUNT`, and the options themselves are |
| 253 | found in `GIT_PUSH_OPTION_0`, `GIT_PUSH_OPTION_1`,... |
| 254 | If it is negotiated to not use the push options phase, the |
| 255 | environment variables will not be set. If the client selects |
| 256 | to use push options, but doesn't transmit any, the count variable |
| 257 | will be set to zero, `GIT_PUSH_OPTION_COUNT=0`. |
| 258 | |
| Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 259 | [[update]] |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 260 | update |
| Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 261 | ~~~~~~ |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 262 | |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 263 | This hook is invoked by 'git-receive-pack' on the remote repository, |
| Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 264 | which happens when a 'git push' is done on a local repository. |
| Junio C Hamano | 818f7d6 | 2006-03-26 01:49:30 | [diff] [blame] | 265 | Just before updating the ref on the remote repository, the update hook |
| Junio C Hamano | 33db437 | 2006-06-07 19:51:45 | [diff] [blame] | 266 | is invoked. Its exit status determines the success or failure of |
| Junio C Hamano | 818f7d6 | 2006-03-26 01:49:30 | [diff] [blame] | 267 | the ref update. |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 268 | |
| Junio C Hamano | 818f7d6 | 2006-03-26 01:49:30 | [diff] [blame] | 269 | The hook executes once for each ref to be updated, and takes |
| 270 | three parameters: |
| Junio C Hamano | d578413 | 2006-09-20 21:29:27 | [diff] [blame] | 271 | |
| 272 | - the name of the ref being updated, |
| 273 | - the old object name stored in the ref, |
| Junio C Hamano | 826f5c4 | 2014-02-07 20:33:30 | [diff] [blame] | 274 | - and the new object name to be stored in the ref. |
| Junio C Hamano | 818f7d6 | 2006-03-26 01:49:30 | [diff] [blame] | 275 | |
| 276 | A zero exit from the update hook allows the ref to be updated. |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 277 | Exiting with a non-zero status prevents 'git-receive-pack' |
| Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 278 | from updating that ref. |
| Junio C Hamano | 818f7d6 | 2006-03-26 01:49:30 | [diff] [blame] | 279 | |
| 280 | This hook can be used to prevent 'forced' update on certain refs by |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 281 | making sure that the object name is a commit object that is a |
| 282 | descendant of the commit object named by the old object name. |
| Junio C Hamano | 3f680f3 | 2009-11-16 02:10:54 | [diff] [blame] | 283 | That is, to enforce a "fast-forward only" policy. |
| Junio C Hamano | 818f7d6 | 2006-03-26 01:49:30 | [diff] [blame] | 284 | |
| 285 | It could also be used to log the old..new status. However, it |
| 286 | does not know the entire set of branches, so it would end up |
| Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 287 | firing one e-mail per ref when used naively, though. The |
| 288 | <<post-receive,'post-receive'>> hook is more suited to that. |
| Junio C Hamano | 818f7d6 | 2006-03-26 01:49:30 | [diff] [blame] | 289 | |
| Junio C Hamano | 198b1f1 | 2016-05-17 22:27:24 | [diff] [blame] | 290 | In an environment that restricts the users' access only to git |
| 291 | commands over the wire, this hook can be used to implement access |
| 292 | control without relying on filesystem ownership and group |
| 293 | membership. See linkgit:git-shell[1] for how you might use the login |
| 294 | shell to restrict the user's access to only git commands. |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 295 | |
| Junio C Hamano | 323e52d | 2007-05-13 22:19:53 | [diff] [blame] | 296 | Both standard output and standard error output are forwarded to |
| Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 297 | 'git send-pack' on the other end, so you can simply `echo` messages |
| Junio C Hamano | 323e52d | 2007-05-13 22:19:53 | [diff] [blame] | 298 | for the user. |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 299 | |
| Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 300 | The default 'update' hook, when enabled--and with |
| Junio C Hamano | d6fff40 | 2009-09-14 09:40:50 | [diff] [blame] | 301 | `hooks.allowunannotated` config option unset or set to false--prevents |
| Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 302 | unannotated tags to be pushed. |
| Junio C Hamano | 818f7d6 | 2006-03-26 01:49:30 | [diff] [blame] | 303 | |
| Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 304 | [[post-receive]] |
| 305 | post-receive |
| Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 306 | ~~~~~~~~~~~~ |
| Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 307 | |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 308 | This hook is invoked by 'git-receive-pack' on the remote repository, |
| Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 309 | which happens when a 'git push' is done on a local repository. |
| Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 310 | It executes on the remote repository once after all the refs have |
| 311 | been updated. |
| 312 | |
| 313 | This hook executes once for the receive operation. It takes no |
| Junio C Hamano | 323e52d | 2007-05-13 22:19:53 | [diff] [blame] | 314 | arguments, but gets the same information as the |
| 315 | <<pre-receive,'pre-receive'>> |
| Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 316 | hook does on its standard input. |
| 317 | |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 318 | This hook does not affect the outcome of 'git-receive-pack', as it |
| Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 319 | is called after the real work is done. |
| 320 | |
| Junio C Hamano | a638742 | 2007-08-25 03:54:27 | [diff] [blame] | 321 | This supersedes the <<post-update,'post-update'>> hook in that it gets |
| Junio C Hamano | 323e52d | 2007-05-13 22:19:53 | [diff] [blame] | 322 | both old and new values of all the refs in addition to their |
| 323 | names. |
| Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 324 | |
| Junio C Hamano | 323e52d | 2007-05-13 22:19:53 | [diff] [blame] | 325 | Both standard output and standard error output are forwarded to |
| Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 326 | 'git send-pack' on the other end, so you can simply `echo` messages |
| Junio C Hamano | 323e52d | 2007-05-13 22:19:53 | [diff] [blame] | 327 | for the user. |
| Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 328 | |
| 329 | The default 'post-receive' hook is empty, but there is |
| 330 | a sample script `post-receive-email` provided in the `contrib/hooks` |
| Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 331 | directory in Git distribution, which implements sending commit |
| Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 332 | emails. |
| 333 | |
| Junio C Hamano | e48a113 | 2016-08-03 22:40:21 | [diff] [blame] | 334 | The number of push options given on the command line of |
| 335 | `git push --push-option=...` can be read from the environment |
| 336 | variable `GIT_PUSH_OPTION_COUNT`, and the options themselves are |
| 337 | found in `GIT_PUSH_OPTION_0`, `GIT_PUSH_OPTION_1`,... |
| 338 | If it is negotiated to not use the push options phase, the |
| 339 | environment variables will not be set. If the client selects |
| 340 | to use push options, but doesn't transmit any, the count variable |
| 341 | will be set to zero, `GIT_PUSH_OPTION_COUNT=0`. |
| 342 | |
| Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 343 | [[post-update]] |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 344 | post-update |
| Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 345 | ~~~~~~~~~~~ |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 346 | |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 347 | This hook is invoked by 'git-receive-pack' on the remote repository, |
| Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 348 | which happens when a 'git push' is done on a local repository. |
| Junio C Hamano | 818f7d6 | 2006-03-26 01:49:30 | [diff] [blame] | 349 | It executes on the remote repository once after all the refs have |
| 350 | been updated. |
| 351 | |
| 352 | It takes a variable number of parameters, each of which is the |
| 353 | name of ref that was actually updated. |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 354 | |
| 355 | This hook is meant primarily for notification, and cannot affect |
| Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 356 | the outcome of 'git-receive-pack'. |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 357 | |
| Junio C Hamano | d578413 | 2006-09-20 21:29:27 | [diff] [blame] | 358 | The 'post-update' hook can tell what are the heads that were pushed, |
| Junio C Hamano | 818f7d6 | 2006-03-26 01:49:30 | [diff] [blame] | 359 | but it does not know what their original and updated values are, |
| Junio C Hamano | 323e52d | 2007-05-13 22:19:53 | [diff] [blame] | 360 | so it is a poor place to do log old..new. The |
| 361 | <<post-receive,'post-receive'>> hook does get both original and |
| 362 | updated values of the refs. You might consider it instead if you need |
| 363 | them. |
| Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 364 | |
| Junio C Hamano | d578413 | 2006-09-20 21:29:27 | [diff] [blame] | 365 | When enabled, the default 'post-update' hook runs |
| Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 366 | 'git update-server-info' to keep the information used by dumb |
| Junio C Hamano | d578413 | 2006-09-20 21:29:27 | [diff] [blame] | 367 | transports (e.g., HTTP) up-to-date. If you are publishing |
| Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 368 | a Git repository that is accessible via HTTP, you should |
| Junio C Hamano | 818f7d6 | 2006-03-26 01:49:30 | [diff] [blame] | 369 | probably enable this hook. |
| Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 370 | |
| Junio C Hamano | 8638c92 | 2007-05-12 20:50:08 | [diff] [blame] | 371 | Both standard output and standard error output are forwarded to |
| Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 372 | 'git send-pack' on the other end, so you can simply `echo` messages |
| Junio C Hamano | 323e52d | 2007-05-13 22:19:53 | [diff] [blame] | 373 | for the user. |
| Junio C Hamano | e3ddb5b | 2008-04-21 00:48:07 | [diff] [blame] | 374 | |
| Junio C Hamano | 6bb32e6 | 2015-02-17 22:11:26 | [diff] [blame] | 375 | push-to-checkout |
| 376 | ~~~~~~~~~~~~~~~~ |
| 377 | |
| 378 | This hook is invoked by 'git-receive-pack' on the remote repository, |
| 379 | which happens when a 'git push' is done on a local repository, when |
| 380 | the push tries to update the branch that is currently checked out |
| 381 | and the `receive.denyCurrentBranch` configuration variable is set to |
| 382 | `updateInstead`. Such a push by default is refused if the working |
| 383 | tree and the index of the remote repository has any difference from |
| 384 | the currently checked out commit; when both the working tree and the |
| 385 | index match the current commit, they are updated to match the newly |
| 386 | pushed tip of the branch. This hook is to be used to override the |
| 387 | default behaviour. |
| 388 | |
| 389 | The hook receives the commit with which the tip of the current |
| 390 | branch is going to be updated. It can exit with a non-zero status |
| 391 | to refuse the push (when it does so, it must not modify the index or |
| 392 | the working tree). Or it can make any necessary changes to the |
| 393 | working tree and to the index to bring them to the desired state |
| 394 | when the tip of the current branch is updated to the new commit, and |
| 395 | exit with a zero status. |
| 396 | |
| 397 | For example, the hook can simply run `git read-tree -u -m HEAD "$1"` |
| 398 | in order to emulate 'git fetch' that is run in the reverse direction |
| 399 | with `git push`, as the two-tree form of `read-tree -u -m` is |
| 400 | essentially the same as `git checkout` that switches branches while |
| 401 | keeping the local changes in the working tree that do not interfere |
| 402 | with the difference between the branches. |
| 403 | |
| 404 | |
| Junio C Hamano | e3ddb5b | 2008-04-21 00:48:07 | [diff] [blame] | 405 | pre-auto-gc |
| Junio C Hamano | c28068f | 2009-09-08 00:55:23 | [diff] [blame] | 406 | ~~~~~~~~~~~ |
| Junio C Hamano | e3ddb5b | 2008-04-21 00:48:07 | [diff] [blame] | 407 | |
| Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 408 | This hook is invoked by 'git gc --auto'. It takes no parameter, and |
| 409 | exiting with non-zero status from this script causes the 'git gc --auto' |
| Junio C Hamano | e3ddb5b | 2008-04-21 00:48:07 | [diff] [blame] | 410 | to abort. |
| Junio C Hamano | 2fbcd21 | 2008-05-14 22:26:07 | [diff] [blame] | 411 | |
| Junio C Hamano | 3166736 | 2010-03-25 00:38:53 | [diff] [blame] | 412 | post-rewrite |
| 413 | ~~~~~~~~~~~~ |
| 414 | |
| 415 | This hook is invoked by commands that rewrite commits (`git commit |
| 416 | --amend`, 'git-rebase'; currently 'git-filter-branch' does 'not' call |
| 417 | it!). Its first argument denotes the command it was invoked by: |
| 418 | currently one of `amend` or `rebase`. Further command-dependent |
| 419 | arguments may be passed in the future. |
| 420 | |
| 421 | The hook receives a list of the rewritten commits on stdin, in the |
| 422 | format |
| 423 | |
| 424 | <old-sha1> SP <new-sha1> [ SP <extra-info> ] LF |
| 425 | |
| 426 | The 'extra-info' is again command-dependent. If it is empty, the |
| 427 | preceding SP is also omitted. Currently, no commands pass any |
| 428 | 'extra-info'. |
| 429 | |
| 430 | The hook always runs after the automatic note copying (see |
| Junio C Hamano | 96fdfa1 | 2016-03-21 20:52:39 | [diff] [blame] | 431 | "notes.rewrite.<command>" in linkgit:git-config[1]) has happened, and |
| Junio C Hamano | 3166736 | 2010-03-25 00:38:53 | [diff] [blame] | 432 | thus has access to these notes. |
| 433 | |
| 434 | The following command-specific comments apply: |
| 435 | |
| 436 | rebase:: |
| 437 | For the 'squash' and 'fixup' operation, all commits that were |
| 438 | squashed are listed as being rewritten to the squashed commit. |
| 439 | This means that there will be several lines sharing the same |
| 440 | 'new-sha1'. |
| 441 | + |
| 442 | The commits are guaranteed to be listed in the order that they were |
| 443 | processed by rebase. |
| 444 | |
| Junio C Hamano | 3166736 | 2010-03-25 00:38:53 | [diff] [blame] | 445 | |
| Junio C Hamano | 2fbcd21 | 2008-05-14 22:26:07 | [diff] [blame] | 446 | GIT |
| 447 | --- |
| Junio C Hamano | f7c042d | 2008-06-06 22:50:53 | [diff] [blame] | 448 | Part of the linkgit:git[1] suite |