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