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 19, 2020, 06:07 UTC
Message-ID
<xmqqv9ik9gwa.fsf@gitster.c.googlers.com>
In-Reply-To
<xmqq8sfgbltq.fsf@gitster.c.googlers.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 13 quoted lines
> Drew DeVault <sir@cmpwn.com> writes:
>
>> 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(+)

One more thing. This should be fairly easy to protect from future breakages by adding three new tests in t/t9001-send-email.sh script. One would do something like

	test_config sendmail.program sendmail &&
	test_must_fail git send-email ... >err &&
	test_i18ngrep "found configuration options for .sendmail" err
as a positive test, the second would do
	test_config sendmail.program sendmail &&
	test_config sendemail.forbidsendmailvariables false &&
	git send-email ...

to make sure that escape hatch actually works and then the third would do something like

	test_config resendmail.program resendmail &&
	git send-email ...

to ensure that only variable whose name begins with "sendmail." triggers the error.

Show 9 quoted lines
>> +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?

I didn't know "git config --get-regexp $regexp" did not anchor the regular expression to the beginning or to the end. In this case, we do want to make sure the "sendmail." substring literally appears at the very beginning of the variable name, and because "--get-regexp" does not anchor the regular expression to the end, we do not need to add an explicit "anything goes", i.e. ".*" after it.

IOW, "^sendmail[.]" is the minimal regexp we want to use. We cannot afford to lose the "^" to reject "resendmail.program", and we do not have to add ".*" that would swallow the rest at the end.

Thanks.
Previous: Junio C HamanoNext: Jeff King
Message 3 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.