3 # An example hook script to validate a patch (and/or patch series) before
4 # sending it via email.
6 # The hook should exit with non-zero status after issuing an appropriate
7 # message if it wants to prevent the email(s) from being sent.
9 # To enable this hook, rename this file to "sendemail-validate".
11 # By default, it will only check that the patch(es) can be applied on top of
12 # the default upstream branch without conflicts in a secondary worktree. After
13 # validation (successful or not) of the last patch of a series, the worktree
16 # The following config variables can be set to change the default remote and
17 # remote ref that are used to apply the patches against:
19 # sendemail.validateRemote (default: origin)
20 # sendemail.validateRemoteRef (default: HEAD)
22 # Replace the TODO placeholders with appropriate checks according to your
25 validate_cover_letter
() {
27 # TODO: Replace with appropriate checks (e.g. spell checking).
33 # Ensure that the patch applies without conflicts.
34 git am
-3 "$file" ||
return
35 # TODO: Replace with appropriate checks for this patch
36 # (e.g. checkpatch.pl).
41 # TODO: Replace with appropriate checks for the whole series
42 # (e.g. quick build, coding style checks, etc.).
46 # main -------------------------------------------------------------------------
48 if test "$GIT_SENDEMAIL_FILE_COUNTER" = 1
50 remote
=$
(git config
--default origin
--get sendemail.validateRemote
) &&
51 ref
=$
(git config
--default HEAD
--get sendemail.validateRemoteRef
) &&
52 worktree
=$
(mktemp
--tmpdir -d sendemail-validate.XXXXXXX
) &&
53 git worktree add
-fd --checkout "$worktree" "refs/remotes/$remote/$ref" &&
54 git config
--replace-all sendemail.validateWorktree
"$worktree"
56 worktree
=$
(git config
--get sendemail.validateWorktree
)
58 echo "sendemail-validate: error: failed to prepare worktree" >&2
62 unset GIT_DIR GIT_WORK_TREE
65 if grep -q "^diff --git " "$1"
69 validate_cover_letter
"$1"
72 if test "$GIT_SENDEMAIL_FILE_COUNTER" = "$GIT_SENDEMAIL_FILE_TOTAL"
74 git config
--unset-all sendemail.validateWorktree
&&
75 trap 'git worktree remove -ff "$worktree"' EXIT
&&