Documentation / hooks.txton commit Merge branch 'maint' of git://linux-nfs.org/~bfields/git into maint (154c7d0)
   1Hooks used by git
   2=================
   3
   4Hooks are little scripts you can place in `$GIT_DIR/hooks`
   5directory 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
   8all disabled.  To enable a hook, make it executable with `chmod +x`.
   9
  10This document describes the currently defined hooks.
  11
  12applypatch-msg
  13--------------
  14
  15This hook is invoked by `git-am` script.  It takes a single
  16parameter, the name of the file that holds the proposed commit
  17log message.  Exiting with non-zero status causes
  18`git-am` to abort before applying the patch.
  19
  20The hook is allowed to edit the message file in place, and can
  21be used to normalize the message into some project standard
  22format (if the project has one). It can also be used to refuse
  23the commit after inspecting the message file.
  24
  25The default 'applypatch-msg' hook, when enabled, runs the
  26'commit-msg' hook, if the latter is enabled.
  27
  28pre-applypatch
  29--------------
  30
  31This hook is invoked by `git-am`.  It takes no parameter,
  32and is invoked after the patch is applied, but before a commit
  33is made.  Exiting with non-zero status causes the working tree
  34after application of the patch not committed.
  35
  36It can be used to inspect the current working tree and refuse to
  37make a commit if it does not pass certain test.
  38
  39The default 'pre-applypatch' hook, when enabled, runs the
  40'pre-commit' hook, if the latter is enabled.
  41
  42post-applypatch
  43---------------
  44
  45This hook is invoked by `git-am`.  It takes no parameter,
  46and is invoked after the patch is applied and a commit is made.
  47
  48This hook is meant primarily for notification, and cannot affect
  49the outcome of `git-am`.
  50
  51pre-commit
  52----------
  53
  54This hook is invoked by `git-commit`, and can be bypassed
  55with `\--no-verify` option.  It takes no parameter, and is
  56invoked before obtaining the proposed commit log message and
  57making a commit.  Exiting with non-zero status from this script
  58causes the `git-commit` to abort.
  59
  60The default 'pre-commit' hook, when enabled, catches introduction
  61of lines with trailing whitespaces and aborts the commit when
  62such a line is found.
  63
  64commit-msg
  65----------
  66
  67This hook is invoked by `git-commit`, and can be bypassed
  68with `\--no-verify` option.  It takes a single parameter, the
  69name of the file that holds the proposed commit log message.
  70Exiting with non-zero status causes the `git-commit` to
  71abort.
  72
  73The hook is allowed to edit the message file in place, and can
  74be used to normalize the message into some project standard
  75format (if the project has one). It can also be used to refuse
  76the commit after inspecting the message file.
  77
  78The default 'commit-msg' hook, when enabled, detects duplicate
  79"Signed-off-by" lines, and aborts the commit if one is found.
  80
  81post-commit
  82-----------
  83
  84This hook is invoked by `git-commit`.  It takes no
  85parameter, and is invoked after a commit is made.
  86
  87This hook is meant primarily for notification, and cannot affect
  88the outcome of `git-commit`.
  89
  90[[pre-receive]]
  91pre-receive
  92-----------
  93
  94This hook is invoked by `git-receive-pack` on the remote repository,
  95which happens when a `git push` is done on a local repository.
  96Just before starting to update refs on the remote repository, the
  97pre-receive hook is invoked.  Its exit status determines the success
  98or failure of the update.
  99
 100This hook executes once for the receive operation. It takes no
 101arguments, but for each ref to be updated it receives on standard
 102input a line of the format:
 103
 104  <old-value> SP <new-value> SP <ref-name> LF
 105
 106where `<old-value>` is the old object name stored in the ref,
 107`<new-value>` is the new object name to be stored in the ref and
 108`<ref-name>` is the full name of the ref.
 109When creating a new ref, `<old-value>` is 40 `0`.
 110
 111If the hook exits with non-zero status, none of the refs will be
 112updated. If the hook exits with zero, updating of individual refs can
 113still be prevented by the <<update,'update'>> hook.
 114
 115Both standard output and standard error output are forwarded to
 116`git-send-pack` on the other end, so you can simply `echo` messages
 117for the user.
 118
 119[[update]]
 120update
 121------
 122
 123This hook is invoked by `git-receive-pack` on the remote repository,
 124which happens when a `git push` is done on a local repository.
 125Just before updating the ref on the remote repository, the update hook
 126is invoked.  Its exit status determines the success or failure of
 127the ref update.
 128
 129The hook executes once for each ref to be updated, and takes
 130three parameters:
 131
 132 - the name of the ref being updated,
 133 - the old object name stored in the ref,
 134 - and the new objectname to be stored in the ref.
 135
 136A zero exit from the update hook allows the ref to be updated.
 137Exiting with a non-zero status prevents `git-receive-pack`
 138from updating that ref.
 139
 140This hook can be used to prevent 'forced' update on certain refs by
 141making sure that the object name is a commit object that is a
 142descendant of the commit object named by the old object name.
 143That is, to enforce a "fast forward only" policy.
 144
 145It could also be used to log the old..new status.  However, it
 146does not know the entire set of branches, so it would end up
 147firing one e-mail per ref when used naively, though.  The
 148<<post-receive,'post-receive'>> hook is more suited to that.
 149
 150Another use suggested on the mailing list is to use this hook to
 151implement access control which is finer grained than the one
 152based on filesystem group.
 153
 154Both standard output and standard error output are forwarded to
 155`git-send-pack` on the other end, so you can simply `echo` messages
 156for the user.
 157
 158The default 'update' hook, when enabled--and with
 159`hooks.allowunannotated` config option turned on--prevents
 160unannotated tags to be pushed.
 161
 162[[post-receive]]
 163post-receive
 164------------
 165
 166This hook is invoked by `git-receive-pack` on the remote repository,
 167which happens when a `git push` is done on a local repository.
 168It executes on the remote repository once after all the refs have
 169been updated.
 170
 171This hook executes once for the receive operation.  It takes no
 172arguments, but gets the same information as the
 173<<pre-receive,'pre-receive'>>
 174hook does on its standard input.
 175
 176This hook does not affect the outcome of `git-receive-pack`, as it
 177is called after the real work is done.
 178
 179This supersedes the <<post-update,'post-update'>> hook in that it gets
 180both old and new values of all the refs in addition to their
 181names.
 182
 183Both standard output and standard error output are forwarded to
 184`git-send-pack` on the other end, so you can simply `echo` messages
 185for the user.
 186
 187The default 'post-receive' hook is empty, but there is
 188a sample script `post-receive-email` provided in the `contrib/hooks`
 189directory in git distribution, which implements sending commit
 190emails.
 191
 192[[post-update]]
 193post-update
 194-----------
 195
 196This hook is invoked by `git-receive-pack` on the remote repository,
 197which happens when a `git push` is done on a local repository.
 198It executes on the remote repository once after all the refs have
 199been updated.
 200
 201It takes a variable number of parameters, each of which is the
 202name of ref that was actually updated.
 203
 204This hook is meant primarily for notification, and cannot affect
 205the outcome of `git-receive-pack`.
 206
 207The 'post-update' hook can tell what are the heads that were pushed,
 208but it does not know what their original and updated values are,
 209so it is a poor place to do log old..new. The
 210<<post-receive,'post-receive'>> hook does get both original and
 211updated values of the refs. You might consider it instead if you need
 212them.
 213
 214When enabled, the default 'post-update' hook runs
 215`git-update-server-info` to keep the information used by dumb
 216transports (e.g., HTTP) up-to-date.  If you are publishing
 217a git repository that is accessible via HTTP, you should
 218probably enable this hook.
 219
 220Both standard output and standard error output are forwarded to
 221`git-send-pack` on the other end, so you can simply `echo` messages
 222for the user.