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