send-email: recognize absolute path on Windows
On Windows, absolute paths might start with a DOS drive prefix, which these two checks failed to recognize. Unfortunately, we cannot simply use the file_name_is_absolute helper in File::Spec::Functions, because Git for Windows has an MSYS-based Perl, where this helper doesn't grok DOS drive-prefixes. So let's manually check for these in that case, and fall back to the File::Spec-helper on other platforms (e.g Win32 with native Perl) Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Erik Faye-Lund committed
Apr 16, 2014 at 10:08 UTC
cb005c1fdf814d3b65b5b43f5f4fa25aa1bcdf46
1 file changed
+14
-2
git-send-email.perl
+14
-2
@@ -1113,6 +1113,18 @@ sub ssl_verify_params {
1113
}
1114
}
1115
1116
+sub file_name_is_absolute {
1117
+ my ($path) = @_;
1118
+
1119
+ # msys does not grok DOS drive-prefixes
1120
+ if ($^O eq 'msys') {
1121
+ return ($path =~ m#^/# || $path =~ m#[a-zA-Z]\:#)
1122
+ }
1123
+
1124
+ require File::Spec::Functions;
1125
+ return File::Spec::Functions::file_name_is_absolute($path);
1126
+}
1127
+
1128
# Returns 1 if the message was sent, and 0 otherwise.
1129
# In actuality, the whole program dies when there
1130
# is an error sending a message.
@@ -1197,7 +1209,7 @@ X-Mailer: git-send-email $gitversion
1209
1210
if ($dry_run) {
1211
# We don't want to send the email.
1200
- } elsif ($smtp_server =~ m#^/#) {
1212
+ } elsif (file_name_is_absolute($smtp_server)) {
1213
my $pid = open my $sm, '|-';
1214
defined $pid or die $!;
1215
if (!$pid) {
@@ -1271,7 +1283,7 @@ X-Mailer: git-send-email $gitversion
1283
printf (($dry_run ? "Dry-" : "")."Sent %s\n", $subject);
1284
} else {
1285
print (($dry_run ? "Dry-" : "")."OK. Log says:\n");
1274
- if ($smtp_server !~ m#^/#) {
1286
+ if (!file_name_is_absolute($smtp_server)) {
1287
print "Server: $smtp_server\n";
1288
print "MAIL FROM:<$raw_from>\n";
1289
foreach my $entry (@recipients) {