]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'ms/send-email-feed-header-to-validate-hook'
authorJunio C Hamano <gitster@pobox.com>
Wed, 10 May 2023 17:23:28 +0000 (10:23 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 10 May 2023 17:23:28 +0000 (10:23 -0700)
"git send-email" learned to give the e-mail headers to the validate
hook by passing an extra argument from the command line.

* ms/send-email-feed-header-to-validate-hook:
  send-email: expose header information to git-send-email's sendemail-validate hook
  send-email: refactor header generation functions

1  2 
Documentation/githooks.txt
git-send-email.perl
t/t9001-send-email.sh

index c8e55b2613f520a1ad7006f403611097257a850f,9896ffafaf684e30f548094cb16265ac911c0fcf..86f804720ae71fc3d0db94623663539bd05a06f2
@@@ -595,33 -595,30 +595,52 @@@ processed by rebase
  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
  ~~~~~~~~~~~~~~~~~~
  
index 66c91711092be7f8cc32a2b81945b48bbe657bd0,10c450ef68902c7dfcc2289acf72319f38f37346..26e18eebd93a3eeecd03faff92e2cb4124fdf16d
@@@ -792,31 -792,31 +792,46 @@@ if (@rev_list_opts) 
                                    @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);
Simple merge