Skip to content

Commit 280242d

Browse files
author
Junio C Hamano
committed
send-email: do not barf when Term::ReadLine does not like your terminal
As long as we do not need to readline from the terminal, we should not barf when starting up the program. Without this patch, t9001 test on Cygwin occasionally died with the following error message: Unable to get Terminal Size. The TIOCGWINSZ ioctl didn't work. The COLUMNS and LINES environment variables didn't work. The resize program didn't work. at /usr/lib/perl5/vendor_perl/5.8/cygwin/Term/ReadKey.pm line 362. Compilation failed in require at /usr/lib/perl5/vendor_perl/5.8/Term/ReadLine/Perl.pm line 58. Acked-by: Ryan Anderson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 624314f commit 280242d

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

git-send-email.perl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@
2222
use Getopt::Long;
2323
use Data::Dumper;
2424

25+
package FakeTerm;
26+
sub new {
27+
my ($class, $reason) = @_;
28+
return bless \$reason, shift;
29+
}
30+
sub readline {
31+
my $self = shift;
32+
die "Cannot use readline on FakeTerm: $$self";
33+
}
34+
package main;
35+
2536
# most mail servers generate the Date: header, but not all...
2637
$ENV{LC_ALL} = 'C';
2738
use POSIX qw/strftime/;
@@ -46,7 +57,12 @@
4657
# Example reply to:
4758
#$initial_reply_to = ''; #<[email protected]>';
4859

49-
my $term = new Term::ReadLine 'git-send-email';
60+
my $term = eval {
61+
new Term::ReadLine 'git-send-email';
62+
};
63+
if ($@) {
64+
$term = new FakeTerm "$@: going non-interactive";
65+
}
5066

5167
# Begin by accumulating all the variables (defined above), that we will end up
5268
# needing, first, from the command line:

t/t9001-send-email.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ test_expect_success \
2525
git add fake.sendmail
2626
GIT_AUTHOR_NAME="A" git commit -a -m "Second."'
2727

28-
test_expect_success \
29-
'Extract patches and send' \
30-
'git format-patch -n HEAD^1
31-
git send-email -from="Example <[email protected]>" [email protected] --smtp-server="$(pwd)/fake.sendmail" ./0001*txt'
28+
test_expect_success 'Extract patches' '
29+
patches=`git format-patch -n HEAD^1`
30+
'
31+
32+
test_expect_success 'Send patches' '
33+
git send-email -from="Example <[email protected]>" [email protected] --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
34+
'
3235

3336
cat >expected <<\EOF
3437

0 commit comments

Comments
 (0)