sendemail-validate
~~~~~~~~~~~~~~~~~~
- This hook is invoked by linkgit:git-send-email[1]. It takes a single parameter,
- the name of the file that holds the e-mail to be sent. Exiting with a
- non-zero status causes `git send-email` to abort before sending any
- e-mails.
+ 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 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
~~~~~~~~~~~~~~~~~~
@rev_list_opts);
}
- @files = handle_backup_files(@files);
+ if (defined $sender) {
+ $sender =~ s/^\s+|\s+$//g;
+ ($sender) = expand_aliases($sender);
+ } else {
+ $sender = $repoauthor->() || $repocommitter->() || '';
+ }
+
+ # $sender could be an already sanitized address
+ # (e.g. sendemail.from could be manually sanitized by user).
+ # But it's a no-op to run sanitize_address on an already sanitized address.
+ $sender = sanitize_address($sender);
+
+ $time = time - scalar $#files;
if ($validate) {
+ # FIFOs can only be read once, exclude them from validation.
+ my @real_files = ();
foreach my $f (@files) {
unless (-p $f) {
- pre_process_file($f, 1);
- validate_patch($f, $target_xfer_encoding);
+ push(@real_files, $f);
}
}
+
+ # Run the loop once again to avoid gaps in the counter due to FIFO
+ # arguments provided by the user.
+ my $num = 1;
+ my $num_files = scalar @real_files;
+ $ENV{GIT_SENDEMAIL_FILE_TOTAL} = "$num_files";
+ foreach my $r (@real_files) {
+ $ENV{GIT_SENDEMAIL_FILE_COUNTER} = "$num";
++ pre_process_file($r, 1);
+ validate_patch($r, $target_xfer_encoding);
+ $num += 1;
+ }
+ delete $ENV{GIT_SENDEMAIL_FILE_COUNTER};
+ delete $ENV{GIT_SENDEMAIL_FILE_TOTAL};
}
+ @files = handle_backup_files(@files);
+
if (@files) {
unless ($quiet) {
print $_,"\n" for (@files);