git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] git-send-email: die if sendmail.* config is set

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 18, 2020, 20:38 UTC
Message-ID
<xmqq8sfgbltq.fsf@gitster.c.googlers.com>
In-Reply-To
<20200718202142.111015-1-sir@cmpwn.com>
Drew DeVault <sir@cmpwn.com> writes:
Show 25 quoted lines
> 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>
> ---
>  Documentation/config/sendemail.txt |  5 +++++
>  git-send-email.perl                |  8 ++++++++
>  perl/Git.pm                        | 26 ++++++++++++++++++++++++++
>  3 files changed, 39 insertions(+)
>
> diff --git a/Documentation/config/sendemail.txt b/Documentation/config/sendemail.txt
> index 0006faf800..1726d5f85e 100644
> --- a/Documentation/config/sendemail.txt
> +++ b/Documentation/config/sendemail.txt
> @@ -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.forceSendmailVariables::
> +	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.

I am not sure if it is clear to readers what kind of forcing this refers to. At least it is not clear to me.

Show 9 quoted lines
> diff --git a/git-send-email.perl b/git-send-email.perl
> index 36c47bae1d..1b186bc058 100755
> --- a/git-send-email.perl
> +++ b/git-send-email.perl
> @@ -250,6 +250,7 @@ sub do_edit {
>  my $use_xmailer = 1;
>  my $validate = 1;
>  my $target_xfer_encoding = 'auto';
> +my $forbid_sendmail_variables = 1;

Ah, probably s/force/forbid/ in the documentation above? OK, then it makes sense.

Show 16 quoted lines
>  
>  my %config_bool_settings = (
>      "thread" => \$thread,
> @@ -263,6 +264,7 @@ sub do_edit {
>      "multiedit" => \$multiedit,
>      "annotate" => \$annotate,
>      "xmailer" => \$use_xmailer,
> +    "forbidsendmailvariables" => \$forbid_sendmail_variables,
>  );
>  
>  my %config_settings = (
> @@ -478,6 +480,12 @@ sub read_config {
>      usage();
>  }
>  
> +if ($forbid_sendmail_variables && (scalar Git::config_regexp("sendmail.*")) != 0) {

Judging from the way you wrote the "config_regexp" helper function, the above regexp matches "sendmailer.foo", "sendmailed.bar", etc., I would think, which probably is not what you intended.

I guess we can write "sendmail[.].*" or "sendmail\\..*" to ensure that we are talking about (literally) "sendmail." followed by anything?

> +	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");
> +}
OK.
Other than the two minor nits, looking quite good.
Thanks.
Show 40 quoted lines
>  die __("Cannot run git format-patch from outside a repository\n")
>  	if $format_patch and not $repo;
>  
> diff --git a/perl/Git.pm b/perl/Git.pm
> index 54c9ed0dde..10df990959 100644
> --- a/perl/Git.pm
> +++ b/perl/Git.pm
> @@ -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 {
Previous: Drew DeVaultNext: Junio C Hamano
Message 2 of 5 in “git-send-email: die if sendmail.* config is set”
  1. git-send-email: die if sendmail.* config is setDrew DeVault, Jul 18, 2020
  2. Junio C HamanoJul 18, 2020
  3. Junio C HamanoJul 19, 2020
  4. Jeff KingJul 20, 2020
  5. Drew DeVaultJul 20, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.