Skip to content

Commit 0fb7fc7

Browse files
jaysoffiangitster
authored andcommitted
send-email: fix In-Reply-To regression
Fix a regression introduced by 1ca3d6e (send-email: squelch warning due to comparing undefined $_ to "") where if the user was prompted for an initial In-Reply-To and didn't provide one, messages would be sent out with an invalid In-Reply-To of "<>" Also add test cases for the regression and the fix. A small modification was needed to allow send-email to take its replies from stdin if the environment variable GIT_SEND_EMAIL_NOTTY is set. Signed-off-by: Jay Soffian <jaysoffian@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent f5ed3b3 commit 0fb7fc7

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

git-send-email.perl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ sub format_2822_time {
170170

171171
my $repo = Git->repository();
172172
my $term = eval {
173-
new Term::ReadLine 'git-send-email';
173+
$ENV{"GIT_SEND_EMAIL_NOTTY"}
174+
? new Term::ReadLine 'git-send-email', \*STDIN, \*STDOUT
175+
: new Term::ReadLine 'git-send-email';
174176
};
175177
if ($@) {
176178
$term = new FakeTerm "$@: going non-interactive";
@@ -476,8 +478,9 @@ sub expand_aliases {
476478
$initial_reply_to = $_;
477479
}
478480
if (defined $initial_reply_to) {
479-
$initial_reply_to =~ s/^\s*<?/</;
480-
$initial_reply_to =~ s/>?\s*$/>/;
481+
$initial_reply_to =~ s/^\s*<?//;
482+
$initial_reply_to =~ s/>?\s*$//;
483+
$initial_reply_to = "<$initial_reply_to>" if $initial_reply_to ne '';
481484
}
482485

483486
if (!defined $smtp_server) {

t/t9001-send-email.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,25 @@ test_expect_success 'allow long lines with --no-validate' '
108108
2>errors
109109
'
110110

111+
test_expect_success 'Invalid In-Reply-To' '
112+
git send-email \
113+
--from="Example <nobody@example.com>" \
114+
--to=nobody@example.com \
115+
--in-reply-to=" " \
116+
--smtp-server="$(pwd)/fake.sendmail" \
117+
$patches
118+
2>errors
119+
! grep "^In-Reply-To: < *>" msgtxt
120+
'
121+
122+
test_expect_success 'Valid In-Reply-To when prompting' '
123+
(echo "From Example <from@example.com>"
124+
echo "To Example <to@example.com>"
125+
echo ""
126+
) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
127+
--smtp-server="$(pwd)/fake.sendmail" \
128+
$patches 2>errors &&
129+
! grep "^In-Reply-To: < *>" msgtxt
130+
'
131+
111132
test_done

0 commit comments

Comments
 (0)