Merge branch 'jt/send-email-validate-hook'
authorJunio C Hamano <gitster@pobox.com>
Fri, 2 Jun 2017 06:05:59 +0000 (15:05 +0900)
committerJunio C Hamano <gitster@pobox.com>
Fri, 2 Jun 2017 06:06:00 +0000 (15:06 +0900)
A hotfix for a topic already in 'master'.

* jt/send-email-validate-hook:
send-email: check for repo before invoking hook

1  2 
git-send-email.perl
diff --combined git-send-email.perl
index 0168a476497ad6107ff567377bb7cb97e29e4892,fa559cca3fe846eabe1853a38f0a82e5c8b7706e..7fd58744360a2bb14531ed3f73092b45449d5590
                        die __("The required SMTP server is not properly defined.")
                }
  
 +              require Net::SMTP;
 +              my $use_net_smtp_ssl = version->parse($Net::SMTP::VERSION) < version->parse("2.34");
 +              $smtp_domain ||= maildomain();
 +
                if ($smtp_encryption eq 'ssl') {
                        $smtp_server_port ||= 465; # ssmtp
 -                      require Net::SMTP::SSL;
 -                      $smtp_domain ||= maildomain();
                        require IO::Socket::SSL;
  
                        # Suppress "variable accessed once" warning.
                        # Net::SMTP::SSL->new() does not forward any SSL options
                        IO::Socket::SSL::set_client_defaults(
                                ssl_verify_params());
 -                      $smtp ||= Net::SMTP::SSL->new($smtp_server,
 -                                                    Hello => $smtp_domain,
 -                                                    Port => $smtp_server_port,
 -                                                    Debug => $debug_net_smtp);
 +
 +                      if ($use_net_smtp_ssl) {
 +                              require Net::SMTP::SSL;
 +                              $smtp ||= Net::SMTP::SSL->new($smtp_server,
 +                                                            Hello => $smtp_domain,
 +                                                            Port => $smtp_server_port,
 +                                                            Debug => $debug_net_smtp);
 +                      }
 +                      else {
 +                              $smtp ||= Net::SMTP->new($smtp_server,
 +                                                       Hello => $smtp_domain,
 +                                                       Port => $smtp_server_port,
 +                                                       Debug => $debug_net_smtp,
 +                                                       SSL => 1);
 +                      }
                }
                else {
 -                      require Net::SMTP;
 -                      $smtp_domain ||= maildomain();
                        $smtp_server_port ||= 25;
                        $smtp ||= Net::SMTP->new($smtp_server,
                                                 Hello => $smtp_domain,
                                                 Debug => $debug_net_smtp,
                                                 Port => $smtp_server_port);
                        if ($smtp_encryption eq 'tls' && $smtp) {
 -                              require Net::SMTP::SSL;
 -                              $smtp->command('STARTTLS');
 -                              $smtp->response();
 -                              if ($smtp->code == 220) {
 +                              if ($use_net_smtp_ssl) {
 +                                      $smtp->command('STARTTLS');
 +                                      $smtp->response();
 +                                      if ($smtp->code != 220) {
 +                                              die sprintf(__("Server does not support STARTTLS! %s"), $smtp->message);
 +                                      }
 +                                      require Net::SMTP::SSL;
                                        $smtp = Net::SMTP::SSL->start_SSL($smtp,
                                                                          ssl_verify_params())
 -                                              or die "STARTTLS failed! ".IO::Socket::SSL::errstr();
 -                                      $smtp_encryption = '';
 -                                      # Send EHLO again to receive fresh
 -                                      # supported commands
 -                                      $smtp->hello($smtp_domain);
 -                              } else {
 -                                      die sprintf(__("Server does not support STARTTLS! %s"), $smtp->message);
 +                                              or die sprintf(__("STARTTLS failed! %s"), IO::Socket::SSL::errstr());
 +                              }
 +                              else {
 +                                      $smtp->starttls(ssl_verify_params())
 +                                              or die sprintf(__("STARTTLS failed! %s"), IO::Socket::SSL::errstr());
                                }
 +                              $smtp_encryption = '';
 +                              # Send EHLO again to receive fresh
 +                              # supported commands
 +                              $smtp->hello($smtp_domain);
                        }
                }
  
@@@ -1755,21 -1739,23 +1755,23 @@@ sub unique_email_list 
  sub validate_patch {
        my $fn = shift;
  
-       my $validate_hook = catfile(catdir($repo->repo_path(), 'hooks'),
-                                   'sendemail-validate');
-       my $hook_error;
-       if (-x $validate_hook) {
-               my $target = abs_path($fn);
-               # The hook needs a correct cwd and GIT_DIR.
-               my $cwd_save = cwd();
-               chdir($repo->wc_path() or $repo->repo_path())
-                       or die("chdir: $!");
-               local $ENV{"GIT_DIR"} = $repo->repo_path();
-               $hook_error = "rejected by sendemail-validate hook"
-                       if system($validate_hook, $target);
-               chdir($cwd_save) or die("chdir: $!");
-       }
-       return $hook_error if $hook_error;
+       if ($repo) {
+               my $validate_hook = catfile(catdir($repo->repo_path(), 'hooks'),
+                                           'sendemail-validate');
+               my $hook_error;
+               if (-x $validate_hook) {
+                       my $target = abs_path($fn);
+                       # The hook needs a correct cwd and GIT_DIR.
+                       my $cwd_save = cwd();
+                       chdir($repo->wc_path() or $repo->repo_path())
+                               or die("chdir: $!");
+                       local $ENV{"GIT_DIR"} = $repo->repo_path();
+                       $hook_error = "rejected by sendemail-validate hook"
+                               if system($validate_hook, $target);
+                       chdir($cwd_save) or die("chdir: $!");
+               }
+               return $hook_error if $hook_error;
+       }
  
        open(my $fh, '<', $fn)
                or die sprintf(__("unable to open %s: %s\n"), $fn, $!);