Home Explore Blog CI



git

7th chunk of `Documentation/githooks.adoc`
d37ea537b4ce58025c974ee273fee495e86bcda6f57c56ac0000000100000fa6
 of parameters, each of which is the
name of ref that was actually updated.

This hook is meant primarily for notification, and cannot affect
the outcome of `git receive-pack`.

The 'post-update' hook can tell what are the heads that were pushed,
but it does not know what their original and updated values are,
so it is a poor place to do log old..new. The
<<post-receive,'post-receive'>> hook does get both original and
updated values of the refs. You might consider it instead if you need
them.

When enabled, the default 'post-update' hook runs
`git update-server-info` to keep the information used by dumb
transports (e.g., HTTP) up to date.  If you are publishing
a Git repository that is accessible via HTTP, you should
probably enable this hook.

Both standard output and standard error output are forwarded to
`git send-pack` on the other end, so you can simply `echo` messages
for the user.

reference-transaction
~~~~~~~~~~~~~~~~~~~~~

This hook is invoked by any Git command that performs reference
updates. It executes whenever a reference transaction is prepared,
committed or aborted and may thus get called multiple times. The hook
also supports symbolic reference updates.

The hook takes exactly one argument, which is the current state the
given reference transaction is in:

    - "prepared": All reference updates have been queued to the
      transaction and references were locked on disk.

    - "committed": The reference transaction was committed and all
      references now have their respective new value.

    - "aborted": The reference transaction was aborted, no changes
      were performed and the locks have been released.

For each reference update that was added to the transaction, the hook
receives on standard input a line of the format:

  <old-value> SP <new-value> SP <ref-name> LF

where `<old-value>` is the old object name passed into the reference
transaction, `<new-value>` is the new object name to be stored in the
ref and `<ref-name>` is the full name of the ref. When force updating
the reference regardless of its current value or when the reference is
to be created anew, `<old-value>` is the all-zeroes object name. To
distinguish these cases, you can inspect the current value of
`<ref-name>` via `git rev-parse`.

For symbolic reference updates the `<old_value>` and `<new-value>`
fields could denote references instead of objects. A reference will be
denoted with a 'ref:' prefix, like `ref:<ref-target>`.

The exit status of the hook is ignored for any state except for the
"prepared" state. In the "prepared" state, a non-zero exit status will
cause the transaction to be aborted. The hook will not be called with
"aborted" state in that case.

push-to-checkout
~~~~~~~~~~~~~~~~

This hook is invoked by linkgit:git-receive-pack[1] when it reacts to
`git push` and updates reference(s) in its repository, and when
the push tries to update the branch that is currently checked out
and the `receive.denyCurrentBranch` configuration variable is set to
`updateInstead`.  Such a push by default is refused if the working
tree and the index of the remote repository has any difference from
the currently checked out commit; when both the working tree and the
index match the current commit, they are updated to match the newly
pushed tip of the branch.  This hook is to be used to override the
default behaviour.

The hook receives the commit with which the tip of the current
branch is going to be updated.  It can exit with a non-zero status
to refuse the push (when it does so, it must not modify the index or
the working tree).  Or it can make any necessary changes to the
working tree and to the index to bring them to the desired state
when the tip of the current branch is updated to the new commit, and
exit with a zero status.

For example, the hook can simply run `git read-tree -u -m HEAD "$1"`
in order to emulate `git fetch` that is run in the reverse direction
with `git push`, as the two-tree form of `git read-tree -u -m` is
essentially

Title: Git Reference Transaction, Push-to-Checkout, and Other Hooks
Summary
The reference-transaction hook is invoked during reference updates and can be called multiple times during a transaction. It receives information about the updated references and their old and new values. The push-to-checkout hook is used when a push tries to update the currently checked out branch, and it can override the default behavior by making changes to the working tree and index. The hook can exit with a non-zero status to refuse the push or exit with a zero status after making necessary changes.