git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Gregory Anders <greg@gpanders.com>
To: git@vger.kernel.org
Cc: Jeff King <peff@peff.net>, Gregory Anders <greg@gpanders.com>
Subject: [PATCH v4] git-send-email: use ! to indicate relative path to command
Date: Tue, 11 May 2021 14:40:44 -0600	[thread overview]
Message-ID: <20210511204044.69047-1-greg@gpanders.com> (raw)
In-Reply-To: <YJrZ7Hho6jrVyM7f@coredump.intra.peff.net>

Presently, the smtpServer config option can use a sendmail-like program
by providing an absolute path to the program as the value for this
option. However, an absolute path is not always portable and it is often
preferable to simply specify a program name and have `git-send-email`
find that program on $PATH.

For example, if a user wishes to use msmtp to send emails, they might
be able to simply use

    [sendemail]
            smtpServer = !msmtp

instead of using the full path. This is particularly useful when a
common git config file is used across multiple systems where the
absolute path to a given program may differ.

To that end, this patch allows the smtpServer config option to be
prefixed with a ! character that implements the above behavior; namely,
the specified value (sans the ! character) is used as if the user had
entered it directly on the command line.

See also https://lore.kernel.org/git/YJrH8uqzapnpNEsb@gpanders.com/.

Signed-off-by: Gregory Anders <greg@gpanders.com>
---
 Documentation/git-send-email.txt | 13 +++++++------
 git-send-email.perl              |  7 +++++--
 t/t9001-send-email.sh            | 10 ++++++++++
 3 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt
index 93708aefea..418e66c703 100644
--- a/Documentation/git-send-email.txt
+++ b/Documentation/git-send-email.txt
@@ -212,12 +212,13 @@ a password is obtained using 'git-credential'.
 --smtp-server=<host>::
 	If set, specifies the outgoing SMTP server to use (e.g.
 	`smtp.example.com` or a raw IP address).  Alternatively it can
-	specify a full pathname of a sendmail-like program instead;
-	the program must support the `-i` option.  Default value can
-	be specified by the `sendemail.smtpServer` configuration
-	option; the built-in default is to search for `sendmail` in
-	`/usr/sbin`, `/usr/lib` and $PATH if such program is
-	available, falling back to `localhost` otherwise.
+	specify a sendmail-like program instead, either by a full
+	path-name or by prefixing the program name with `!`.  The
+	program must support the `-i` option.  Default value can be
+	specified by the `sendemail.smtpServer` configuration option;
+	the built-in default is to search for `sendmail` in `/usr/sbin`,
+	`/usr/lib` and $PATH if such program is available, falling back
+	to `localhost` otherwise.
 
 --smtp-server-port=<port>::
 	Specifies a port different from the default port (SMTP
diff --git a/git-send-email.perl b/git-send-email.perl
index 175da07d94..022dcf0999 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -1492,11 +1492,14 @@ sub send_message {
 
 	if ($dry_run) {
 		# We don't want to send the email.
-	} elsif (file_name_is_absolute($smtp_server)) {
+	} elsif (file_name_is_absolute($smtp_server) || $smtp_server =~ /^!/) {
+		my $prog = $smtp_server;
+		$prog =~ s/^!//;
+
 		my $pid = open my $sm, '|-';
 		defined $pid or die $!;
 		if (!$pid) {
-			exec($smtp_server, @sendmail_parameters) or die $!;
+			exec($prog, @sendmail_parameters) or die $!;
 		}
 		print $sm "$header\n$message";
 		close $sm or die $!;
diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
index 65b3035371..14cc61ace7 100755
--- a/t/t9001-send-email.sh
+++ b/t/t9001-send-email.sh
@@ -2225,4 +2225,14 @@ test_expect_success $PREREQ 'test forbidSendmailVariables behavior override' '
 		HEAD^
 '
 
+test_expect_success $PREREQ 'test using a command for smtpServer with !' '
+	clean_fake_sendmail &&
+	PATH="$(pwd):$PATH" \
+	git send-email \
+		--from="Example <nobody@example.com>" \
+		--to=nobody@example.com \
+		--smtp-server="!fake.sendmail" \
+		$patches 2>errors
+'
+
 test_done
-- 
2.31.1.576.g2f8a831619


  reply	other threads:[~2021-05-11 20:40 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-11 19:15 [PATCH v3] git-send-email: use ! to indicate relative path to command Gregory Anders
2021-05-11 19:24 ` Jeff King
2021-05-11 20:40   ` Gregory Anders [this message]
2021-05-11 21:39     ` [PATCH v4] " Jeff King
2021-05-11 22:18       ` Gregory Anders
2021-05-11 23:09     ` Junio C Hamano
2021-05-11 23:49     ` [PATCH v5] " Gregory Anders
2021-05-12  0:00       ` brian m. carlson
2021-05-12  0:35         ` Jeff King
2021-05-12  0:45           ` Gregory Anders
2021-05-12  0:49             ` Jeff King
2021-05-12  3:29             ` Junio C Hamano
2021-05-12  0:51           ` brian m. carlson
2021-05-11 20:03 ` [PATCH v3] " Felipe Contreras
2021-05-11 20:42   ` Gregory Anders
2021-05-11 22:07     ` Felipe Contreras
2021-05-11 22:19       ` Gregory Anders
2021-05-12  0:47         ` Jeff King
2021-05-12  1:08           ` Felipe Contreras
2021-05-12  1:24             ` Jeff King
2021-05-12  1:52               ` Felipe Contreras
2021-05-12  1:58                 ` Gregory Anders
2021-05-12  4:17                   ` Felipe Contreras

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210511204044.69047-1-greg@gpanders.com \
    --to=greg@gpanders.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).