Skip to content

Commit

Permalink
send-email: fix nasty bug in ask() function
Browse files Browse the repository at this point in the history
Commit 6e18251 (send-email: refactor and ensure prompting doesn't loop
forever) introduced an ask function, which unfortunately had a nasty
bug. This caused it not to accept anything but the default reply to the
"Who should the emails appear to be from?" prompt, and nothing but
ctrl-d to the "Who should the emails be sent to?" and "Message-ID to be
used as In-Reply-To for the first email?" prompts.

This commit corrects the issues and adds a test to confirm the fix.

Signed-off-by: Jay Soffian <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
jaysoffian authored and gitster committed Apr 5, 2009
1 parent e96f368 commit 0da43a6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions git-send-email.perl
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ ($)

sub ask {
my ($prompt, %arg) = @_;
my $valid_re = $arg{valid_re} || ""; # "" matches anything
my $valid_re = $arg{valid_re};
my $default = $arg{default};
my $resp;
my $i = 0;
Expand All @@ -624,7 +624,7 @@ sub ask {
if ($resp eq '' and defined $default) {
return $default;
}
if ($resp =~ /$valid_re/) {
if (!defined $valid_re or $resp =~ /$valid_re/) {
return $resp;
}
}
Expand Down
13 changes: 13 additions & 0 deletions t/t9001-send-email.sh
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,19 @@ test_expect_success 'Show all headers' '
test_cmp expected-show-all-headers actual-show-all-headers
'

test_expect_success 'Prompting works' '
clean_fake_sendmail &&
(echo "Example <[email protected]>"
echo "[email protected]"
echo ""
) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
--smtp-server="$(pwd)/fake.sendmail" \
$patches \
2>errors &&
grep "^From: Example <[email protected]>$" msgtxt1 &&
grep "^To: [email protected]$" msgtxt1
'

z8=zzzzzzzz
z64=$z8$z8$z8$z8$z8$z8$z8$z8
z512=$z64$z64$z64$z64$z64$z64$z64$z64
Expand Down

0 comments on commit 0da43a6

Please sign in to comment.