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
This commit is contained in:
Junio C Hamano 2010-11-17 15:01:00 -08:00
commit 0510480510
8 changed files with 112 additions and 51 deletions

View File

@ -48,6 +48,7 @@ static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *ext
NULL,
NULL,
NULL,
NULL,
};
struct child_process po;
int i;
@ -59,6 +60,8 @@ static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *ext
argv[i++] = "--delta-base-offset";
if (args->quiet)
argv[i++] = "-q";
if (args->progress)
argv[i++] = "--progress";
memset(&po, 0, sizeof(po));
po.argv = argv;
po.in = -1;

View File

@ -5,6 +5,7 @@ struct send_pack_args {
unsigned verbose:1,
quiet:1,
porcelain:1,
progress:1,
send_mirror:1,
force_update:1,
use_thin_pack:1,

19
t/lib-terminal.sh Normal file
View File

@ -0,0 +1,19 @@
#!/bin/sh
test_expect_success 'set up terminal for tests' '
if
test_have_prereq PERL &&
"$PERL_PATH" "$TEST_DIRECTORY"/test-terminal.perl \
sh -c "test -t 1 && test -t 2"
then
test_set_prereq TTY &&
test_terminal () {
if ! test_declared_prereq TTY
then
echo >&4 "test_terminal: need to declare TTY prerequisite"
return 127
fi
"$PERL_PATH" "$TEST_DIRECTORY"/test-terminal.perl "$@"
}
fi
'

View File

@ -2,9 +2,14 @@
test_description='push with --set-upstream'
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-terminal.sh
ensure_fresh_upstream() {
rm -rf parent && git init --bare parent
}
test_expect_success 'setup bare parent' '
git init --bare parent &&
ensure_fresh_upstream &&
git remote add upstream parent
'
@ -66,4 +71,41 @@ test_expect_success 'push -u HEAD' '
check_config headbranch upstream refs/heads/headbranch
'
test_expect_success TTY 'progress messages go to tty' '
ensure_fresh_upstream &&
test_terminal git push -u upstream master >out 2>err &&
grep "Writing objects" err
'
test_expect_success 'progress messages do not go to non-tty' '
ensure_fresh_upstream &&
# skip progress messages, since stderr is non-tty
git push -u upstream master >out 2>err &&
! grep "Writing objects" err
'
test_expect_success 'progress messages go to non-tty (forced)' '
ensure_fresh_upstream &&
# force progress messages to stderr, even though it is non-tty
git push -u --progress upstream master >out 2>err &&
grep "Writing objects" err
'
test_expect_success TTY 'push -q suppresses progress' '
ensure_fresh_upstream &&
test_terminal git push -u -q upstream master >out 2>err &&
! grep "Writing objects" err
'
test_expect_failure TTY 'push --no-progress suppresses progress' '
ensure_fresh_upstream &&
test_terminal git push -u --no-progress upstream master >out 2>err &&
! grep "Writing objects" err
'
test_done

View File

@ -4,42 +4,13 @@ test_description='Test automatic use of a pager.'
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-pager.sh
. "$TEST_DIRECTORY"/lib-terminal.sh
cleanup_fail() {
echo >&2 cleanup failed
(exit 1)
}
test_expect_success 'set up terminal for tests' '
rm -f stdout_is_tty ||
cleanup_fail &&
if test -t 1
then
>stdout_is_tty
elif
test_have_prereq PERL &&
"$PERL_PATH" "$TEST_DIRECTORY"/t7006/test-terminal.perl \
sh -c "test -t 1"
then
>test_terminal_works
fi
'
if test -e stdout_is_tty
then
test_terminal() { "$@"; }
test_set_prereq TTY
elif test -e test_terminal_works
then
test_terminal() {
"$PERL_PATH" "$TEST_DIRECTORY"/t7006/test-terminal.perl "$@"
}
test_set_prereq TTY
else
say "# no usable terminal, so skipping some tests"
fi
test_expect_success 'setup' '
unset GIT_PAGER GIT_PAGER_IN_USE;
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' '
colorful colorful.log
'
if test_have_prereq SIMPLEPAGER && test_have_prereq TTY
then
test_set_prereq SIMPLEPAGERTTY
fi
# Use this helper to make it easy for the caller of your
# terminal-using function to specify whether it should fail.
# If you write
@ -253,7 +219,7 @@ parse_args() {
test_default_pager() {
parse_args "$@"
$test_expectation SIMPLEPAGERTTY "$cmd - default pager is used by default" "
$test_expectation SIMPLEPAGER,TTY "$cmd - default pager is used by default" "
unset PAGER GIT_PAGER;
test_might_fail git config --unset core.pager &&
rm -f default_pager_used ||

View File

@ -366,6 +366,15 @@ test_have_prereq () {
test $total_prereq = $ok_prereq
}
test_declared_prereq () {
case ",$test_prereq," in
*,$1,*)
return 0
;;
esac
return 1
}
# You are not expected to call test_ok_ and test_failure_ directly, use
# the text_expect_* functions instead.
@ -418,17 +427,17 @@ test_skip () {
break
esac
done
if test -z "$to_skip" && test -n "$prereq" &&
! test_have_prereq "$prereq"
if test -z "$to_skip" && test -n "$test_prereq" &&
! test_have_prereq "$test_prereq"
then
to_skip=t
fi
case "$to_skip" in
t)
of_prereq=
if test "$missing_prereq" != "$prereq"
if test "$missing_prereq" != "$test_prereq"
then
of_prereq=" of $prereq"
of_prereq=" of $test_prereq"
fi
say_color skip >&3 "skipping test: $@"
@ -442,9 +451,10 @@ test_skip () {
}
test_expect_failure () {
test "$#" = 3 && { prereq=$1; shift; } || prereq=
test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
test "$#" = 2 ||
error "bug in the test script: not 2 or 3 parameters to test-expect-failure"
export test_prereq
if ! test_skip "$@"
then
say >&3 "checking known breakage: $2"
@ -460,9 +470,10 @@ test_expect_failure () {
}
test_expect_success () {
test "$#" = 3 && { prereq=$1; shift; } || prereq=
test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq=
test "$#" = 2 ||
error "bug in the test script: not 2 or 3 parameters to test-expect-success"
export test_prereq
if ! test_skip "$@"
then
say >&3 "expecting success: $2"
@ -504,11 +515,12 @@ test_expect_code () {
# Usage: test_external description command arguments...
# Example: test_external 'Perl API' perl ../path/to/test.pl
test_external () {
test "$#" = 4 && { prereq=$1; shift; } || prereq=
test "$#" = 4 && { test_prereq=$1; shift; } || test_prereq=
test "$#" = 3 ||
error >&5 "bug in the test script: not 3 or 4 parameters to test_external"
descr="$1"
shift
export test_prereq
if ! test_skip "$descr" "$@"
then
# Announce the script to reduce confusion about the

View File

@ -5,14 +5,15 @@ use warnings;
use IO::Pty;
use File::Copy;
# Run @$argv in the background with stdout redirected to $out.
# Run @$argv in the background with stdio redirected to $out and $err.
sub start_child {
my ($argv, $out) = @_;
my ($argv, $out, $err) = @_;
my $pid = fork;
if (not defined $pid) {
die "fork failed: $!"
} elsif ($pid == 0) {
open STDOUT, ">&", $out;
open STDERR, ">&", $err;
close $out;
exec(@$argv) or die "cannot exec '$argv->[0]': $!"
}
@ -48,12 +49,28 @@ sub xsendfile {
copy($in, $out, 4096) or $!{EIO} or die "cannot copy from child: $!";
}
sub copy_stdio {
my ($out, $err) = @_;
my $pid = fork;
defined $pid or die "fork failed: $!";
if (!$pid) {
close($out);
xsendfile(\*STDERR, $err);
exit 0;
}
close($err);
xsendfile(\*STDOUT, $out);
finish_child($pid) == 0
or exit 1;
}
if ($#ARGV < 1) {
die "usage: test-terminal program args";
}
my $master = new IO::Pty;
my $slave = $master->slave;
my $pid = start_child(\@ARGV, $slave);
close $slave;
xsendfile(\*STDOUT, $master);
my $master_out = new IO::Pty;
my $master_err = new IO::Pty;
my $pid = start_child(\@ARGV, $master_out->slave, $master_err->slave);
close $master_out->slave;
close $master_err->slave;
copy_stdio($master_out, $master_err);
exit(finish_child($pid));

View File

@ -789,6 +789,7 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re
args.use_thin_pack = data->options.thin;
args.verbose = (transport->verbose > 0);
args.quiet = (transport->verbose < 0);
args.progress = transport->progress;
args.dry_run = !!(flags & TRANSPORT_PUSH_DRY_RUN);
args.porcelain = !!(flags & TRANSPORT_PUSH_PORCELAIN);