]> git.ipfire.org Git - thirdparty/git.git/commitdiff
git-send-email: die if sendmail.* config is set
authorDrew DeVault <sir@cmpwn.com>
Fri, 24 Jul 2020 00:44:32 +0000 (20:44 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 24 Jul 2020 01:00:34 +0000 (18:00 -0700)
I've seen several people mis-configure git send-email on their first
attempt because they set the sendmail.* config options - not
sendemail.*. This patch detects this mistake and bails out with a
friendly warning.

Signed-off-by: Drew DeVault <sir@cmpwn.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/config/sendemail.txt
git-send-email.perl
perl/Git.pm
t/t9001-send-email.sh

index 0006faf800ae69cd4ee3cde99b5e661e06ae6893..cbc5af42fdf05c1d9450c55a4342c58714e9a766 100644 (file)
@@ -61,3 +61,8 @@ sendemail.smtpBatchSize::
 sendemail.smtpReloginDelay::
        Seconds wait before reconnecting to smtp server.
        See also the `--relogin-delay` option of linkgit:git-send-email[1].
+
+sendemail.forbidSendmailVariables::
+       To avoid common misconfiguration mistakes, linkgit:git-send-email[1]
+       will abort with a warning if any configuration options for "sendmail"
+       exist. Set this variable to bypass the check.
index 36c47bae1d1f1a0d3558fe43dcdbd5eb49a3d27c..1f425c08091d400e1d2e94533411c1b778f561de 100755 (executable)
@@ -250,6 +250,7 @@ my $chain_reply_to = 0;
 my $use_xmailer = 1;
 my $validate = 1;
 my $target_xfer_encoding = 'auto';
+my $forbid_sendmail_variables = 1;
 
 my %config_bool_settings = (
     "thread" => \$thread,
@@ -263,6 +264,7 @@ my %config_bool_settings = (
     "multiedit" => \$multiedit,
     "annotate" => \$annotate,
     "xmailer" => \$use_xmailer,
+    "forbidsendmailvariables" => \$forbid_sendmail_variables,
 );
 
 my %config_settings = (
@@ -478,6 +480,12 @@ unless ($rc) {
     usage();
 }
 
+if ($forbid_sendmail_variables && (scalar Git::config_regexp("^sendmail[.]")) != 0) {
+       die __("fatal: found configuration options for 'sendmail'\n" .
+               "git-send-email is configured with the sendemail.* options - note the 'e'.\n" .
+               "Set sendemail.forbidSendmailVariables to false to disable this check.\n");
+}
+
 die __("Cannot run git format-patch from outside a repository\n")
        if $format_patch and not $repo;
 
index 54c9ed0ddee52e4d5b59b59b74e0dbc738ae3ac9..10df990959e63938e1742d1cdaf0d009b61bee96 100644 (file)
@@ -723,6 +723,32 @@ sub config_int {
        return scalar _config_common({'kind' => '--int'}, @_);
 }
 
+=item config_regexp ( RE )
+
+Retrieve the list of configuration key names matching the regular
+expression C<RE>. The return value is a list of strings matching
+this regex.
+
+=cut
+
+sub config_regexp {
+       my ($self, $regex) = _maybe_self(@_);
+       try {
+               my @cmd = ('config', '--name-only', '--get-regexp', $regex);
+               unshift @cmd, $self if $self;
+               my @matches = command(@cmd);
+               return @matches;
+       } catch Git::Error::Command with {
+               my $E = shift;
+               if ($E->value() == 1) {
+                       my @matches = ();
+                       return @matches;
+               } else {
+                       throw $E;
+               }
+       };
+}
+
 # Common subroutine to implement bulk of what the config* family of methods
 # do. This currently wraps command('config') so it is not so fast.
 sub _config_common {
index ec261085ec68fdb8c9e9b54a9973be880a5c7db5..897bc6a631878b1fced801a9eba4cbc8cfe7e30e 100755 (executable)
@@ -2142,4 +2142,33 @@ test_expect_success $PREREQ 'test that send-email works outside a repo' '
                "$(pwd)/0001-add-master.patch"
 '
 
+test_expect_success $PREREQ 'test that sendmail config is rejected' '
+       test_config sendmail.program sendmail &&
+       test_must_fail git send-email \
+               --from="Example <nobody@example.com>" \
+               --to=nobody@example.com \
+               --smtp-server="$(pwd)/fake.sendmail" \
+               HEAD^ 2>err &&
+       test_i18ngrep "found configuration options for '"'"sendmail"'"'" err
+'
+
+test_expect_success $PREREQ 'test that sendmail config rejection is specific' '
+       test_config resendmail.program sendmail &&
+       git send-email \
+               --from="Example <nobody@example.com>" \
+               --to=nobody@example.com \
+               --smtp-server="$(pwd)/fake.sendmail" \
+               HEAD^
+'
+
+test_expect_success $PREREQ 'test forbidSendmailVariables behavior override' '
+       test_config sendmail.program sendmail &&
+       test_config sendemail.forbidSendmailVariables false &&
+       git send-email \
+               --from="Example <nobody@example.com>" \
+               --to=nobody@example.com \
+               --smtp-server="$(pwd)/fake.sendmail" \
+               HEAD^
+'
+
 test_done