@matheusbsbs / matheus-bagliano / commits / aa54892f5a
Fork 0

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>

Jeff King committed Jan 18, 2008 at 09:19 UTC aa54892f5ada8282643dc7387b33261c7135d784
1 file changed +27 -28
git-send-email.perl
+27 -28
@@ -314,6 +314,33 @@ if (@alias_files and $aliasfiletype and defined $parse_alias{$aliasfiletype}) {
314
315 ($sender) = expand_aliases($sender) if defined $sender;
316
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 +
344 my $prompting = 0;
345 if (!defined $sender) {
346 $sender = $repoauthor || $repocommitter;
@@ -427,34 +454,6 @@ EOT
454 @files = ($compose_filename . ".final");
455 }
456
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 -
457 # Variables we set as part of the loop over files
458 our ($message_id, %mail, $subject, $reply_to, $references, $message);
459