Skip to content

Commit 0da43a6

Browse files
jaysoffiangitster
authored andcommitted
send-email: fix nasty bug in ask() function
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]>
1 parent e96f368 commit 0da43a6

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

git-send-email.perl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ ($)
608608

609609
sub ask {
610610
my ($prompt, %arg) = @_;
611-
my $valid_re = $arg{valid_re} || ""; # "" matches anything
611+
my $valid_re = $arg{valid_re};
612612
my $default = $arg{default};
613613
my $resp;
614614
my $i = 0;
@@ -624,7 +624,7 @@ sub ask {
624624
if ($resp eq '' and defined $default) {
625625
return $default;
626626
}
627-
if ($resp =~ /$valid_re/) {
627+
if (!defined $valid_re or $resp =~ /$valid_re/) {
628628
return $resp;
629629
}
630630
}

t/t9001-send-email.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,19 @@ test_expect_success 'Show all headers' '
130130
test_cmp expected-show-all-headers actual-show-all-headers
131131
'
132132

133+
test_expect_success 'Prompting works' '
134+
clean_fake_sendmail &&
135+
(echo "Example <[email protected]>"
136+
137+
echo ""
138+
) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
139+
--smtp-server="$(pwd)/fake.sendmail" \
140+
$patches \
141+
2>errors &&
142+
grep "^From: Example <[email protected]>$" msgtxt1 &&
143+
grep "^To: [email protected]$" msgtxt1
144+
'
145+
133146
z8=zzzzzzzz
134147
z64=$z8$z8$z8$z8$z8$z8$z8$z8
135148
z512=$z64$z64$z64$z64$z64$z64$z64$z64

0 commit comments

Comments
 (0)