Skip to content

Commit 0510480

Browse files
committed
Merge branch 'jk/push-progress'
* jk/push-progress: push: pass --progress down to git-pack-objects t5523-push-upstream: test progress messages t5523-push-upstream: add function to ensure fresh upstream repo test_terminal: ensure redirections work reliably test_terminal: catch use without TTY prerequisite test-lib: allow test code to check the list of declared prerequisites tests: test terminal output to both stdout and stderr tests: factor out terminal handling from t7006
2 parents ba0254c + d7c411b commit 0510480

File tree

8 files changed

+112
-51
lines changed

8 files changed

+112
-51
lines changed

builtin/send-pack.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *ext
4848
NULL,
4949
NULL,
5050
NULL,
51+
NULL,
5152
};
5253
struct child_process po;
5354
int i;
@@ -59,6 +60,8 @@ static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *ext
5960
argv[i++] = "--delta-base-offset";
6061
if (args->quiet)
6162
argv[i++] = "-q";
63+
if (args->progress)
64+
argv[i++] = "--progress";
6265
memset(&po, 0, sizeof(po));
6366
po.argv = argv;
6467
po.in = -1;

send-pack.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ struct send_pack_args {
55
unsigned verbose:1,
66
quiet:1,
77
porcelain:1,
8+
progress:1,
89
send_mirror:1,
910
force_update:1,
1011
use_thin_pack:1,

t/lib-terminal.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/sh
2+
3+
test_expect_success 'set up terminal for tests' '
4+
if
5+
test_have_prereq PERL &&
6+
"$PERL_PATH" "$TEST_DIRECTORY"/test-terminal.perl \
7+
sh -c "test -t 1 && test -t 2"
8+
then
9+
test_set_prereq TTY &&
10+
test_terminal () {
11+
if ! test_declared_prereq TTY
12+
then
13+
echo >&4 "test_terminal: need to declare TTY prerequisite"
14+
return 127
15+
fi
16+
"$PERL_PATH" "$TEST_DIRECTORY"/test-terminal.perl "$@"
17+
}
18+
fi
19+
'

t/t5523-push-upstream.sh

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22

33
test_description='push with --set-upstream'
44
. ./test-lib.sh
5+
. "$TEST_DIRECTORY"/lib-terminal.sh
6+
7+
ensure_fresh_upstream() {
8+
rm -rf parent && git init --bare parent
9+
}
510

611
test_expect_success 'setup bare parent' '
7-
git init --bare parent &&
12+
ensure_fresh_upstream &&
813
git remote add upstream parent
914
'
1015

@@ -66,4 +71,41 @@ test_expect_success 'push -u HEAD' '
6671
check_config headbranch upstream refs/heads/headbranch
6772
'
6873

74+
test_expect_success TTY 'progress messages go to tty' '
75+
ensure_fresh_upstream &&
76+
77+
test_terminal git push -u upstream master >out 2>err &&
78+
grep "Writing objects" err
79+
'
80+
81+
test_expect_success 'progress messages do not go to non-tty' '
82+
ensure_fresh_upstream &&
83+
84+
# skip progress messages, since stderr is non-tty
85+
git push -u upstream master >out 2>err &&
86+
! grep "Writing objects" err
87+
'
88+
89+
test_expect_success 'progress messages go to non-tty (forced)' '
90+
ensure_fresh_upstream &&
91+
92+
# force progress messages to stderr, even though it is non-tty
93+
git push -u --progress upstream master >out 2>err &&
94+
grep "Writing objects" err
95+
'
96+
97+
test_expect_success TTY 'push -q suppresses progress' '
98+
ensure_fresh_upstream &&
99+
100+
test_terminal git push -u -q upstream master >out 2>err &&
101+
! grep "Writing objects" err
102+
'
103+
104+
test_expect_failure TTY 'push --no-progress suppresses progress' '
105+
ensure_fresh_upstream &&
106+
107+
test_terminal git push -u --no-progress upstream master >out 2>err &&
108+
! grep "Writing objects" err
109+
'
110+
69111
test_done

t/t7006-pager.sh

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,13 @@ test_description='Test automatic use of a pager.'
44

55
. ./test-lib.sh
66
. "$TEST_DIRECTORY"/lib-pager.sh
7+
. "$TEST_DIRECTORY"/lib-terminal.sh
78

89
cleanup_fail() {
910
echo >&2 cleanup failed
1011
(exit 1)
1112
}
1213

13-
test_expect_success 'set up terminal for tests' '
14-
rm -f stdout_is_tty ||
15-
cleanup_fail &&
16-
17-
if test -t 1
18-
then
19-
>stdout_is_tty
20-
elif
21-
test_have_prereq PERL &&
22-
"$PERL_PATH" "$TEST_DIRECTORY"/t7006/test-terminal.perl \
23-
sh -c "test -t 1"
24-
then
25-
>test_terminal_works
26-
fi
27-
'
28-
29-
if test -e stdout_is_tty
30-
then
31-
test_terminal() { "$@"; }
32-
test_set_prereq TTY
33-
elif test -e test_terminal_works
34-
then
35-
test_terminal() {
36-
"$PERL_PATH" "$TEST_DIRECTORY"/t7006/test-terminal.perl "$@"
37-
}
38-
test_set_prereq TTY
39-
else
40-
say "# no usable terminal, so skipping some tests"
41-
fi
42-
4314
test_expect_success 'setup' '
4415
unset GIT_PAGER GIT_PAGER_IN_USE;
4516
test_might_fail git config --unset core.pager &&
@@ -213,11 +184,6 @@ test_expect_success 'color when writing to a file intended for a pager' '
213184
colorful colorful.log
214185
'
215186

216-
if test_have_prereq SIMPLEPAGER && test_have_prereq TTY
217-
then
218-
test_set_prereq SIMPLEPAGERTTY
219-
fi
220-
221187
# Use this helper to make it easy for the caller of your
222188
# terminal-using function to specify whether it should fail.
223189
# If you write
@@ -253,7 +219,7 @@ parse_args() {
253219
test_default_pager() {
254220
parse_args "$@"
255221

256-
$test_expectation SIMPLEPAGERTTY "$cmd - default pager is used by default" "
222+
$test_expectation SIMPLEPAGER,TTY "$cmd - default pager is used by default" "
257223
unset PAGER GIT_PAGER;
258224
test_might_fail git config --unset core.pager &&
259225
rm -f default_pager_used ||

t/test-lib.sh

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,15 @@ test_have_prereq () {
366366
test $total_prereq = $ok_prereq
367367
}
368368

369+
test_declared_prereq () {
370+
case ",$test_prereq," in
371+
*,$1,*)
372+
return 0
373+
;;
374+
esac
375+
return 1
376+
}
377+
369378
# You are not expected to call test_ok_ and test_failure_ directly, use
370379
# the text_expect_* functions instead.
371380

@@ -418,17 +427,17 @@ test_skip () {
418427
break
419428
esac
420429
done
421-
if test -z "$to_skip" && test -n "$prereq" &&
422-
! test_have_prereq "$prereq"
430+
if test -z "$to_skip" && test -n "$test_prereq" &&
431+
! test_have_prereq "$test_prereq"
423432
then
424433
to_skip=t
425434
fi
426435
case "$to_skip" in
427436
t)
428437
of_prereq=
429-
if test "$missing_prereq" != "$prereq"
438+
if test "$missing_prereq" != "$test_prereq"
430439
then
431-
of_prereq=" of $prereq"
440+
of_prereq=" of $test_prereq"
432441
fi
433442

434443
say_color skip >&3 "skipping test: $@"
@@ -442,9 +451,10 @@ test_skip () {
442451
}
443452

444453
test_expect_failure () {
445-
test "$#" = 3 && { prereq=$1; shift; } || prereq=
454+
test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
446455
test "$#" = 2 ||
447456
error "bug in the test script: not 2 or 3 parameters to test-expect-failure"
457+
export test_prereq
448458
if ! test_skip "$@"
449459
then
450460
say >&3 "checking known breakage: $2"
@@ -460,9 +470,10 @@ test_expect_failure () {
460470
}
461471

462472
test_expect_success () {
463-
test "$#" = 3 && { prereq=$1; shift; } || prereq=
473+
test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
464474
test "$#" = 2 ||
465475
error "bug in the test script: not 2 or 3 parameters to test-expect-success"
476+
export test_prereq
466477
if ! test_skip "$@"
467478
then
468479
say >&3 "expecting success: $2"
@@ -504,11 +515,12 @@ test_expect_code () {
504515
# Usage: test_external description command arguments...
505516
# Example: test_external 'Perl API' perl ../path/to/test.pl
506517
test_external () {
507-
test "$#" = 4 && { prereq=$1; shift; } || prereq=
518+
test "$#" = 4 && { test_prereq=$1; shift; } || test_prereq=
508519
test "$#" = 3 ||
509520
error >&5 "bug in the test script: not 3 or 4 parameters to test_external"
510521
descr="$1"
511522
shift
523+
export test_prereq
512524
if ! test_skip "$descr" "$@"
513525
then
514526
# Announce the script to reduce confusion about the

t/t7006/test-terminal.perl renamed to t/test-terminal.perl

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
use IO::Pty;
66
use File::Copy;
77

8-
# Run @$argv in the background with stdout redirected to $out.
8+
# Run @$argv in the background with stdio redirected to $out and $err.
99
sub start_child {
10-
my ($argv, $out) = @_;
10+
my ($argv, $out, $err) = @_;
1111
my $pid = fork;
1212
if (not defined $pid) {
1313
die "fork failed: $!"
1414
} elsif ($pid == 0) {
1515
open STDOUT, ">&", $out;
16+
open STDERR, ">&", $err;
1617
close $out;
1718
exec(@$argv) or die "cannot exec '$argv->[0]': $!"
1819
}
@@ -48,12 +49,28 @@ sub xsendfile {
4849
copy($in, $out, 4096) or $!{EIO} or die "cannot copy from child: $!";
4950
}
5051

52+
sub copy_stdio {
53+
my ($out, $err) = @_;
54+
my $pid = fork;
55+
defined $pid or die "fork failed: $!";
56+
if (!$pid) {
57+
close($out);
58+
xsendfile(\*STDERR, $err);
59+
exit 0;
60+
}
61+
close($err);
62+
xsendfile(\*STDOUT, $out);
63+
finish_child($pid) == 0
64+
or exit 1;
65+
}
66+
5167
if ($#ARGV < 1) {
5268
die "usage: test-terminal program args";
5369
}
54-
my $master = new IO::Pty;
55-
my $slave = $master->slave;
56-
my $pid = start_child(\@ARGV, $slave);
57-
close $slave;
58-
xsendfile(\*STDOUT, $master);
70+
my $master_out = new IO::Pty;
71+
my $master_err = new IO::Pty;
72+
my $pid = start_child(\@ARGV, $master_out->slave, $master_err->slave);
73+
close $master_out->slave;
74+
close $master_err->slave;
75+
copy_stdio($master_out, $master_err);
5976
exit(finish_child($pid));

transport.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,7 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re
789789
args.use_thin_pack = data->options.thin;
790790
args.verbose = (transport->verbose > 0);
791791
args.quiet = (transport->verbose < 0);
792+
args.progress = transport->progress;
792793
args.dry_run = !!(flags & TRANSPORT_PUSH_DRY_RUN);
793794
args.porcelain = !!(flags & TRANSPORT_PUSH_PORCELAIN);
794795

0 commit comments

Comments
 (0)