Home Explore Blog CI



git

9th chunk of `Documentation/githooks.adoc`
1cafa95f12b5440fbfb0ed427209bb87a965f9116d74bdf00000000100000b02
 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 does not follow the patch series counter scheme. It will always
	be equal to the number of files being sent, whether there is a cover
	letter or not.

These variables may for instance be used to validate patch series.

The sample `sendemail-validate` hook that comes with Git checks that all sent
patches (excluding the cover letter) can be applied on top of the upstream
repository default branch without conflicts. Some placeholders are left for
additional validation steps to be performed after all patches of a given series
have been applied.

fsmonitor-watchman
~~~~~~~~~~~~~~~~~~

This hook is invoked when the configuration option `core.fsmonitor` is
set to `.git/hooks/fsmonitor-watchman` or `.git/hooks/fsmonitor-watchmanv2`
depending on the version of the hook to use.

Version 1 takes two arguments, a version (1) and the time in elapsed
nanoseconds since midnight, January 1, 1970.

Version 2 takes two arguments, a version (2) and a token that is used
for identifying changes since the token. For watchman this would be
a clock id. This version must output to stdout the new token followed
by a NUL before the list of files.

The hook should output to stdout the list of all files in the working
directory that may have changed since the requested time.  The logic
should be inclusive so that it does not miss any potential changes.
The paths should be relative to the root of the working directory
and be separated by a single NUL.

It is OK to include files which have not actually changed.  All changes
including newly-created and deleted files should be included. When
files are renamed, both the old and the new name should be included.

Git will limit what files it checks for changes as well as which
directories are checked for untracked files based on the path names
given.

An optimized way to

Title: Git Hooks for Email Validation and File System Monitoring
Summary
This section describes two Git hooks: sendemail-validate and fsmonitor-watchman. The sendemail-validate hook is used to validate email contents and SMTP headers before sending, and can use environment variables such as GIT_SENDEMAIL_FILE_COUNTER and GIT_SENDEMAIL_FILE_TOTAL to track the number of files being sent. The fsmonitor-watchman hook is used to monitor the file system for changes and outputs a list of files that may have changed since a given time, with the goal of optimizing Git's file system checks.