Skip to contentSkip to conversation

git-send-email: use ! to indicate relative path to command

PATCH Superseded Gregory Anders 1 participant 1 message May 11, 2021

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 git-send-email: use ! to indicate relative path to command

When the smtpServer config option is prefixed with a ! character, the value of the option should be interpreted as a command to look up on PATH.
---

Fix the implementation to correctly find the absolute path for the given command, and report an error if the command is not found on PATH.

 git-send-email.perl | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
git-send-email.perl +18 -1
index 175da07d94..6d10901595 100755
@@ -1492,7 +1492,24 @@ 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 =~ /^!/) {
+		if ($smtp_server =~ s/^!//) {
+			my $smtp_command;
+			my @progs = map {"$_/$smtp_server"} split /:/, $ENV{PATH};
+			foreach (@progs) {
+				if (-x $_) {
+					$smtp_command = $_;
+					last;
+				}
+			}
+
+			if (!defined $smtp_command) {
+				die __("The command $smtp_server was not found on PATH.")
+			}
+
+			$smtp_server = $smtp_command;
+		}
+
 		my $pid = open my $sm, '|-';
 		defined $pid or die $!;
 		if (!$pid) {
Signature · 1 line
2.31.1.576.g55f6e1c2f1