2010-02-19 08:18:58 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='Test automatic use of a pager.'
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
rm -f stdout_is_tty
|
2010-02-20 09:50:25 +01:00
|
|
|
test_expect_success 'set up terminal for tests' '
|
2010-02-19 08:18:58 +01:00
|
|
|
if test -t 1
|
|
|
|
then
|
|
|
|
: > stdout_is_tty
|
2010-02-20 09:50:25 +01:00
|
|
|
elif
|
|
|
|
test_have_prereq PERL &&
|
|
|
|
"$PERL_PATH" "$TEST_DIRECTORY"/t7006/test-terminal.perl \
|
|
|
|
sh -c "test -t 1"
|
|
|
|
then
|
|
|
|
: > test_terminal_works
|
2010-02-19 08:18:58 +01:00
|
|
|
fi
|
|
|
|
'
|
|
|
|
|
|
|
|
if test -e stdout_is_tty
|
|
|
|
then
|
2010-02-20 09:50:25 +01:00
|
|
|
test_terminal() { "$@"; }
|
|
|
|
test_set_prereq TTY
|
|
|
|
elif test -e test_terminal_works
|
|
|
|
then
|
|
|
|
test_terminal() {
|
|
|
|
"$PERL_PATH" "$TEST_DIRECTORY"/t7006/test-terminal.perl "$@"
|
|
|
|
}
|
2010-02-19 08:18:58 +01:00
|
|
|
test_set_prereq TTY
|
|
|
|
else
|
2010-02-20 09:50:25 +01:00
|
|
|
say no usable terminal, so skipping some tests
|
2010-02-19 08:18:58 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
unset GIT_PAGER GIT_PAGER_IN_USE
|
|
|
|
git config --unset core.pager
|
|
|
|
PAGER='cat > paginated.out'
|
|
|
|
export PAGER
|
|
|
|
|
|
|
|
test_expect_success 'setup' '
|
|
|
|
test_commit initial
|
|
|
|
'
|
|
|
|
|
|
|
|
rm -f paginated.out
|
|
|
|
test_expect_success TTY 'some commands use a pager' '
|
2010-02-20 09:50:25 +01:00
|
|
|
test_terminal git log &&
|
2010-02-19 08:18:58 +01:00
|
|
|
test -e paginated.out
|
|
|
|
'
|
|
|
|
|
|
|
|
rm -f paginated.out
|
|
|
|
test_expect_success TTY 'some commands do not use a pager' '
|
2010-02-20 09:50:25 +01:00
|
|
|
test_terminal git rev-list HEAD &&
|
2010-02-19 08:18:58 +01:00
|
|
|
! test -e paginated.out
|
|
|
|
'
|
|
|
|
|
|
|
|
rm -f paginated.out
|
|
|
|
test_expect_success 'no pager when stdout is a pipe' '
|
|
|
|
git log | cat &&
|
|
|
|
! test -e paginated.out
|
|
|
|
'
|
|
|
|
|
|
|
|
rm -f paginated.out
|
|
|
|
test_expect_success 'no pager when stdout is a regular file' '
|
|
|
|
git log > file &&
|
|
|
|
! test -e paginated.out
|
|
|
|
'
|
|
|
|
|
|
|
|
rm -f paginated.out
|
|
|
|
test_expect_success TTY 'git --paginate rev-list uses a pager' '
|
2010-02-20 09:50:25 +01:00
|
|
|
test_terminal git --paginate rev-list HEAD &&
|
2010-02-19 08:18:58 +01:00
|
|
|
test -e paginated.out
|
|
|
|
'
|
|
|
|
|
|
|
|
rm -f file paginated.out
|
|
|
|
test_expect_success 'no pager even with --paginate when stdout is a pipe' '
|
|
|
|
git --paginate log | cat &&
|
|
|
|
! test -e paginated.out
|
|
|
|
'
|
|
|
|
|
|
|
|
rm -f paginated.out
|
|
|
|
test_expect_success TTY 'no pager with --no-pager' '
|
2010-02-20 09:50:25 +01:00
|
|
|
test_terminal git --no-pager log &&
|
2010-02-19 08:18:58 +01:00
|
|
|
! test -e paginated.out
|
|
|
|
'
|
|
|
|
|
|
|
|
# A colored commit log will begin with an appropriate ANSI escape
|
|
|
|
# for the first color; the text "commit" comes later.
|
|
|
|
colorful() {
|
|
|
|
read firstline < $1
|
|
|
|
! expr "$firstline" : "^[a-zA-Z]" >/dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
rm -f colorful.log colorless.log
|
|
|
|
test_expect_success 'tests can detect color' '
|
|
|
|
git log --no-color > colorless.log &&
|
|
|
|
git log --color > colorful.log &&
|
|
|
|
! colorful colorless.log &&
|
|
|
|
colorful colorful.log
|
|
|
|
'
|
|
|
|
|
|
|
|
rm -f colorless.log
|
|
|
|
git config color.ui auto
|
|
|
|
test_expect_success 'no color when stdout is a regular file' '
|
|
|
|
git log > colorless.log &&
|
|
|
|
! colorful colorless.log
|
|
|
|
'
|
|
|
|
|
|
|
|
rm -f paginated.out
|
|
|
|
git config color.ui auto
|
|
|
|
test_expect_success TTY 'color when writing to a pager' '
|
2010-02-20 09:50:25 +01:00
|
|
|
TERM=vt100 test_terminal git log &&
|
2010-02-19 08:18:58 +01:00
|
|
|
colorful paginated.out
|
|
|
|
'
|
|
|
|
|
|
|
|
rm -f colorful.log
|
|
|
|
git config color.ui auto
|
|
|
|
test_expect_success 'color when writing to a file intended for a pager' '
|
|
|
|
TERM=vt100 GIT_PAGER_IN_USE=true git log > colorful.log &&
|
|
|
|
colorful colorful.log
|
|
|
|
'
|
|
|
|
|
|
|
|
unset PAGER GIT_PAGER
|
|
|
|
git config --unset core.pager
|
|
|
|
test_expect_success 'determine default pager' '
|
|
|
|
less=$(git var GIT_PAGER) &&
|
|
|
|
test -n "$less"
|
|
|
|
'
|
|
|
|
|
|
|
|
if expr "$less" : '^[a-z]*$' > /dev/null && test_have_prereq TTY
|
|
|
|
then
|
|
|
|
test_set_prereq SIMPLEPAGER
|
|
|
|
fi
|
|
|
|
|
|
|
|
unset PAGER GIT_PAGER
|
|
|
|
git config --unset core.pager
|
|
|
|
rm -f default_pager_used
|
|
|
|
test_expect_success SIMPLEPAGER 'default pager is used by default' '
|
|
|
|
cat > $less <<-EOF &&
|
|
|
|
#!$SHELL_PATH
|
2010-02-22 09:46:33 +01:00
|
|
|
wc > default_pager_used
|
2010-02-19 08:18:58 +01:00
|
|
|
EOF
|
|
|
|
chmod +x $less &&
|
2010-02-20 09:50:25 +01:00
|
|
|
PATH=.:$PATH test_terminal git log &&
|
2010-02-19 08:18:58 +01:00
|
|
|
test -e default_pager_used
|
|
|
|
'
|
|
|
|
|
|
|
|
unset GIT_PAGER
|
|
|
|
git config --unset core.pager
|
|
|
|
rm -f PAGER_used
|
|
|
|
test_expect_success TTY 'PAGER overrides default pager' '
|
2010-02-22 09:46:33 +01:00
|
|
|
PAGER="wc > PAGER_used" &&
|
2010-02-19 08:18:58 +01:00
|
|
|
export PAGER &&
|
2010-02-20 09:50:25 +01:00
|
|
|
test_terminal git log &&
|
2010-02-19 08:18:58 +01:00
|
|
|
test -e PAGER_used
|
|
|
|
'
|
|
|
|
|
|
|
|
unset GIT_PAGER
|
|
|
|
rm -f core.pager_used
|
|
|
|
test_expect_success TTY 'core.pager overrides PAGER' '
|
2010-02-22 09:46:33 +01:00
|
|
|
PAGER=wc &&
|
2010-02-19 08:18:58 +01:00
|
|
|
export PAGER &&
|
2010-02-22 09:46:33 +01:00
|
|
|
git config core.pager "wc > core.pager_used" &&
|
2010-02-20 09:50:25 +01:00
|
|
|
test_terminal git log &&
|
2010-02-19 08:18:58 +01:00
|
|
|
test -e core.pager_used
|
|
|
|
'
|
|
|
|
|
|
|
|
rm -f GIT_PAGER_used
|
|
|
|
test_expect_success TTY 'GIT_PAGER overrides core.pager' '
|
2010-02-22 09:46:33 +01:00
|
|
|
git config core.pager wc &&
|
|
|
|
GIT_PAGER="wc > GIT_PAGER_used" &&
|
2010-02-19 08:18:58 +01:00
|
|
|
export GIT_PAGER &&
|
2010-02-20 09:50:25 +01:00
|
|
|
test_terminal git log &&
|
2010-02-19 08:18:58 +01:00
|
|
|
test -e GIT_PAGER_used
|
|
|
|
'
|
|
|
|
|
|
|
|
test_done
|