Skip to content

Commit 6ecbc85

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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 12f0a5e commit 6ecbc85

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
@@ -166,7 +166,9 @@ sub format_2822_time {
166166

167167
my $repo = Git->repository();
168168
my $term = eval {
169-
new Term::ReadLine 'git-send-email';
169+
$ENV{"GIT_SEND_EMAIL_NOTTY"}
170+
? new Term::ReadLine 'git-send-email', \*STDIN, \*STDOUT
171+
: new Term::ReadLine 'git-send-email';
170172
};
171173
if ($@) {
172174
$term = new FakeTerm "$@: going non-interactive";
@@ -407,8 +409,9 @@ sub expand_aliases {
407409
$initial_reply_to = $_;
408410
}
409411
if (defined $initial_reply_to) {
410-
$initial_reply_to =~ s/^\s*<?/</;
411-
$initial_reply_to =~ s/>?\s*$/>/;
412+
$initial_reply_to =~ s/^\s*<?//;
413+
$initial_reply_to =~ s/>?\s*$//;
414+
$initial_reply_to = "<$initial_reply_to>" if $initial_reply_to ne '';
412415
}
413416

414417
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 <[email protected]>" \
114+
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 <[email protected]>"
124+
echo "To Example <[email protected]>"
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)