[PATCH] send-email: fix In-Reply-To regression

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---

An issue cropped up with testing the regression: it only occured if
initial_reply_to was "", and the only way to do that is to respond to
the Initial-Reply-To prompt with "\n". But send-email uses readline,
which insists on /dev/tty.

So, I initially simulated the breakage by using --initial-reply-to=" ",
but this isn't quite the same thing. However, it turns out this can also
cause an invalid In-Reply-To, which wasn't fixed by Junio's suggestion
of checking that initial_reply_to ne "". So I did a slightly different
fix that handles initial_reply_to eq  " ".

Anyway, back to testing the original problem. I didn't want to use
expect or Expect.pm, so I made a small change to send-email where if
GIT_SEND_EMAIL_NOTTY is set, it will read from stdin instead of
/dev/tty.

But, I wonder if in the future we'll want to enhance the testing
framework to be able to do expect-type stuff?

j.

 git-send-email.perl   |    9 ++++++---
 t/t9001-send-email.sh |   21 +++++++++++++++++++++
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/git-send-email.perl b/git-send-email.perl
index ccb87a2..29b1105 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -170,7 +170,9 @@ my $envelope_sender;
 
 my $repo = Git->repository();
 my $term = eval {
-	new Term::ReadLine 'git-send-email';
+	$ENV{"GIT_SEND_EMAIL_NOTTY"}
+		? new Term::ReadLine 'git-send-email', \*STDIN, \*STDOUT
+		: new Term::ReadLine 'git-send-email';
 };
 if ($@) {
 	$term = new FakeTerm "$@: going non-interactive";
@@ -476,8 +478,9 @@ if ($thread && !defined $initial_reply_to && $prompting) {
 	$initial_reply_to = $_;
 }
 if (defined $initial_reply_to) {
-	$initial_reply_to =~ s/^\s*<?/</;
-	$initial_reply_to =~ s/>?\s*$/>/;
+	$initial_reply_to =~ s/^\s*<?//;
+	$initial_reply_to =~ s/>?\s*$//;
+	$initial_reply_to = "<$initial_reply_to>" if $initial_reply_to ne '';
 }
 
 if (!defined $smtp_server) {
diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
index 08f7c3d..1422e9f 100755
--- a/t/t9001-send-email.sh
+++ b/t/t9001-send-email.sh
@@ -108,4 +108,25 @@ test_expect_success 'allow long lines with --no-validate' '
 		2>errors
 '
 
+test_expect_failure 'Invalid In-Reply-To' '
+	git send-email \
+		--from="Example <nobody@xxxxxxxxxxx>" \
+		--to=nobody@xxxxxxxxxxx \
+		--in-reply-to=" " \
+		--smtp-server="$(pwd)/fake.sendmail" \
+		$patches
+		2>errors
+	! grep "^In-Reply-To: < *>" msgtxt
+'
+
+test_expect_success 'Valid In-Reply-To when prompting' '
+	(echo "From Example <from@xxxxxxxxxxx>"
+	 echo "To Example <to@xxxxxxxxxxx>"
+	 echo ""
+	) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
+		--smtp-server="$(pwd)/fake.sendmail" \
+		$patches 2>errors &&
+	! grep "^In-Reply-To: < *>" msgtxt
+'
+
 test_done
-- 
1.5.4.2.236.g77b4.dirty

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux