Skip to content

Commit 75daa42

Browse files
Eric Wonggitster
authored andcommitted
t1006: ensure cat-file info isn't buffered by default
While working on buffering changes to `git cat-file' in a separate patch, I inadvertently made the output of --batch-check and the `info' command of --batch-command buffered as if opt->buffer_output is turned on by default. Buffering by default breaks some 3rd-party Perl scripts using cat-file, but this breakage was not detected anywhere in our test suite. Add a small Perl snippet to test this problem since (AFAIK) other equivalent ways to test this behavior from Bourne shell and/or awk would require racy sleeps, non-portable FIFOs or tedious C code. Signed-off-by: Eric Wong <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8270201 commit 75daa42

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

t/t1006-cat-file.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,4 +1294,34 @@ test_expect_success 'batch-command flush without --buffer' '
12941294
grep "^fatal:.*flush is only for --buffer mode.*" err
12951295
'
12961296

1297+
script='
1298+
use warnings;
1299+
use strict;
1300+
use IPC::Open2;
1301+
my ($opt, $oid, $expect, @pfx) = @ARGV;
1302+
my @cmd = (qw(git cat-file), $opt);
1303+
my $pid = open2(my $out, my $in, @cmd) or die "open2: @cmd";
1304+
print $in @pfx, $oid, "\n" or die "print $!";
1305+
my $rvec = "";
1306+
vec($rvec, fileno($out), 1) = 1;
1307+
select($rvec, undef, undef, 30) or die "no response to `@pfx $oid` from @cmd";
1308+
my $info = <$out>;
1309+
chop($info) eq "\n" or die "no LF";
1310+
$info eq $expect or die "`$info` != `$expect`";
1311+
close $in or die "close in $!";
1312+
close $out or die "close out $!";
1313+
waitpid $pid, 0;
1314+
$? == 0 or die "\$?=$?";
1315+
'
1316+
1317+
expect="$hello_oid blob $hello_size"
1318+
1319+
test_expect_success PERL '--batch-check is unbuffered by default' '
1320+
perl -e "$script" -- --batch-check $hello_oid "$expect"
1321+
'
1322+
1323+
test_expect_success PERL '--batch-command info is unbuffered by default' '
1324+
perl -e "$script" -- --batch-command $hello_oid "$expect" "info "
1325+
'
1326+
12971327
test_done

0 commit comments

Comments
 (0)