Skip to content

Commit aa54892

Browse files
peffgitster
authored andcommitted
send-email: detect invocation errors earlier
We never even look at the command line arguments until after we have prompted the user for some information. So running "git send-email" without arguments would prompt for "from" and "to" headers, only to then die with "No patch files specified." Instead, let's try to do as much error checking as possible before getting user input. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 5a7b1b5 commit aa54892

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

git-send-email.perl

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,33 @@ sub read_config {
314314

315315
($sender) = expand_aliases($sender) if defined $sender;
316316

317+
# Now that all the defaults are set, process the rest of the command line
318+
# arguments and collect up the files that need to be processed.
319+
for my $f (@ARGV) {
320+
if (-d $f) {
321+
opendir(DH,$f)
322+
or die "Failed to opendir $f: $!";
323+
324+
push @files, grep { -f $_ } map { +$f . "/" . $_ }
325+
sort readdir(DH);
326+
327+
} elsif (-f $f) {
328+
push @files, $f;
329+
330+
} else {
331+
print STDERR "Skipping $f - not found.\n";
332+
}
333+
}
334+
335+
if (@files) {
336+
unless ($quiet) {
337+
print $_,"\n" for (@files);
338+
}
339+
} else {
340+
print STDERR "\nNo patch files specified!\n\n";
341+
usage();
342+
}
343+
317344
my $prompting = 0;
318345
if (!defined $sender) {
319346
$sender = $repoauthor || $repocommitter;
@@ -427,34 +454,6 @@ sub expand_aliases {
427454
@files = ($compose_filename . ".final");
428455
}
429456

430-
431-
# Now that all the defaults are set, process the rest of the command line
432-
# arguments and collect up the files that need to be processed.
433-
for my $f (@ARGV) {
434-
if (-d $f) {
435-
opendir(DH,$f)
436-
or die "Failed to opendir $f: $!";
437-
438-
push @files, grep { -f $_ } map { +$f . "/" . $_ }
439-
sort readdir(DH);
440-
441-
} elsif (-f $f) {
442-
push @files, $f;
443-
444-
} else {
445-
print STDERR "Skipping $f - not found.\n";
446-
}
447-
}
448-
449-
if (@files) {
450-
unless ($quiet) {
451-
print $_,"\n" for (@files);
452-
}
453-
} else {
454-
print STDERR "\nNo patch files specified!\n\n";
455-
usage();
456-
}
457-
458457
# Variables we set as part of the loop over files
459458
our ($message_id, %mail, $subject, $reply_to, $references, $message);
460459

0 commit comments

Comments
 (0)