diff options
author | Junio C Hamano <gitster@pobox.com> | 2012-09-03 15:53:54 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2012-09-03 15:53:54 -0700 |
commit | 200282f1c7eca23ad34b1c5f81bf4b9de334a7d1 (patch) | |
tree | abd69e56b2e41cf024ce9840f395d4864c7f59d6 /git-send-email.perl | |
parent | 831287d37c059d71a20c3c164bc743217114d94e (diff) | |
parent | 51bbccfd1b4a9e2807413022c56ab05c835164fb (diff) | |
download | git-200282f1c7eca23ad34b1c5f81bf4b9de334a7d1.tar.gz |
Merge branch 'jc/send-email-reconfirm'
Validate interactive input to "git send-email" to avoid common
mistakes such as saying "y<RETURN>" to sender mail address whose
prompt is given with a correctly guessed default.
* jc/send-email-reconfirm:
send-email: validate & reconfirm interactive responses
Diffstat (limited to 'git-send-email.perl')
-rwxr-xr-x | git-send-email.perl | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/git-send-email.perl b/git-send-email.perl index 664713709c..607137b9aa 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -681,6 +681,7 @@ sub ask { my ($prompt, %arg) = @_; my $valid_re = $arg{valid_re}; my $default = $arg{default}; + my $confirm_only = $arg{confirm_only}; my $resp; my $i = 0; return defined $default ? $default : undef @@ -698,6 +699,12 @@ sub ask { if (!defined $valid_re or $resp =~ /$valid_re/) { return $resp; } + if ($confirm_only) { + my $yesno = $term->readline("Are you sure you want to use <$resp> [y/N]? "); + if (defined $yesno && $yesno =~ /y/i) { + return $resp; + } + } } return undef; } @@ -745,13 +752,15 @@ my $prompting = 0; if (!defined $sender) { $sender = $repoauthor || $repocommitter || ''; $sender = ask("Who should the emails appear to be from? [$sender] ", - default => $sender); + default => $sender, + valid_re => qr/\@.*\./, confirm_only => 1); print "Emails will be sent from: ", $sender, "\n"; $prompting++; } if (!@initial_to && !defined $to_cmd) { - my $to = ask("Who should the emails be sent to? "); + my $to = ask("Who should the emails be sent to? ", + valid_re => qr/\@.*\./, confirm_only => 1); push @initial_to, parse_address_line($to) if defined $to; # sanitized/validated later $prompting++; } @@ -777,7 +786,8 @@ sub expand_one_alias { if ($thread && !defined $initial_reply_to && $prompting) { $initial_reply_to = ask( - "Message-ID to be used as In-Reply-To for the first email? "); + "Message-ID to be used as In-Reply-To for the first email? ", + valid_re => qr/\@.*\./, confirm_only => 1); } if (defined $initial_reply_to) { $initial_reply_to =~ s/^\s*<?//; |