Home Explore Blog CI



git

8th chunk of `Documentation/githooks.adoc`
4a8e54da46f5208eeabd53d0ebe7ee0adca504cb75e64f440000000100000fa3
 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 the same as `git switch` or `git checkout`
that switches branches while
keeping the local changes in the working tree that do not interfere
with the difference between the branches.


pre-auto-gc
~~~~~~~~~~~

This hook is invoked by `git gc --auto` (see linkgit:git-gc[1]). It
takes no parameter, and exiting with non-zero status from this script
causes the `git gc --auto` to abort.

post-rewrite
~~~~~~~~~~~~

This hook is invoked by commands that rewrite commits
(linkgit:git-commit[1] when called with `--amend` and
linkgit:git-rebase[1]; however, full-history (re)writing tools like
linkgit:git-fast-import[1] or
https://github.com/newren/git-filter-repo[git-filter-repo] typically
do not call it!).  Its first argument denotes the command it was
invoked by: currently one of `amend` or `rebase`.  Further
command-dependent arguments may be passed in the future.

The hook receives a list of the rewritten commits on stdin, in the
format

  <old-object-name> SP <new-object-name> [ SP <extra-info> ] LF

The 'extra-info' is again command-dependent.  If it is empty, the
preceding SP is also omitted.  Currently, no commands pass any
'extra-info'.

The hook always runs after the automatic note copying (see
"notes.rewrite.<command>" in linkgit:git-config[1]) has happened, and
thus has access to these notes.

The following command-specific comments apply:

rebase::
	For the 'squash' and 'fixup' operation, all commits that were
	squashed are listed as being rewritten to the squashed commit.
	This means that there will be several lines sharing the same
	'new-object-name'.
+
The commits are guaranteed to be listed in the order that they were
processed by rebase.

sendemail-validate
~~~~~~~~~~~~~~~~~~

This hook is invoked by linkgit:git-send-email[1].

It takes these command line arguments. They are,
1. the name of the file which holds the contents of the email to be sent.
2. The name of the file which holds the SMTP headers of the email.

The SMTP headers are passed in the exact same way as they are passed to the
user's Mail Transport Agent (MTA). In effect, the email given to the user's
MTA, is the contents of $2 followed by the contents of $1.

An example of a few common headers is shown below. Take notice of the
capitalization and multi-line tab structure.

  From: Example <from@example.com>
  To: to@example.com
  Cc: cc@example.com,
	  A <author@example.com>,
	  One <one@example.com>,
	  two@example.com
  Subject: PATCH-STRING

Exiting with a non-zero status causes `git send-email` to abort
before sending any e-mails.

The following environment variables are set when executing the hook.

`GIT_SENDEMAIL_FILE_COUNTER`::
	A 1-based counter incremented by one for every file holding an e-mail
	to be sent (excluding any FIFOs). This counter does not follow the
	patch series counter scheme. It will always start at 1 and will end at
	GIT_SENDEMAIL_FILE_TOTAL.

`GIT_SENDEMAIL_FILE_TOTAL`::
	The total number of files that will be sent (excluding any FIFOs). This
	counter

Title: Git Hooks for Repository Management and Email Validation
Summary
This section describes various Git hooks, including pre-auto-gc, post-rewrite, and sendemail-validate, which are used to manage repository maintenance, commit rewriting, and email validation. The pre-auto-gc hook is invoked by git gc --auto and can abort the process if it exits with a non-zero status. The post-rewrite hook is invoked by commands that rewrite commits and receives a list of rewritten commits on stdin. The sendemail-validate hook is invoked by git send-email and validates the email contents and SMTP headers before sending.