3 test_description
='Test automatic use of a pager.'
8 test_expect_success
'set up terminal for tests' '
13 test_have_prereq PERL &&
14 "$PERL_PATH" "$TEST_DIRECTORY"/t7006/test-terminal.perl \
17 : > test_terminal_works
21 if test -e stdout_is_tty
23 test_terminal
() { "$@"; }
25 elif test -e test_terminal_works
28 "$PERL_PATH" "$TEST_DIRECTORY"/t7006
/test-terminal.perl
"$@"
32 say no usable terminal
, so skipping some tests
35 unset GIT_PAGER GIT_PAGER_IN_USE
36 git config
--unset core.pager
37 PAGER
='cat > paginated.out'
40 test_expect_success
'setup' '
45 test_expect_success TTY
'some commands use a pager' '
46 test_terminal git log &&
51 test_expect_success TTY
'some commands do not use a pager' '
52 test_terminal git rev-list HEAD &&
53 ! test -e paginated.out
57 test_expect_success
'no pager when stdout is a pipe' '
59 ! test -e paginated.out
63 test_expect_success
'no pager when stdout is a regular file' '
65 ! test -e paginated.out
69 test_expect_success TTY
'git --paginate rev-list uses a pager' '
70 test_terminal git --paginate rev-list HEAD &&
74 rm -f file paginated.out
75 test_expect_success
'no pager even with --paginate when stdout is a pipe' '
76 git --paginate log | cat &&
77 ! test -e paginated.out
81 test_expect_success TTY
'no pager with --no-pager' '
82 test_terminal git --no-pager log &&
83 ! test -e paginated.out
86 # A colored commit log will begin with an appropriate ANSI escape
87 # for the first color; the text "commit" comes later.
90 ! expr "$firstline" : "^[a-zA-Z]" >/dev
/null
93 rm -f colorful.log colorless.log
94 test_expect_success
'tests can detect color' '
95 git log --no-color > colorless.log &&
96 git log --color > colorful.log &&
97 ! colorful colorless.log &&
102 git config color.ui auto
103 test_expect_success
'no color when stdout is a regular file' '
104 git log > colorless.log &&
105 ! colorful colorless.log
109 git config color.ui auto
110 test_expect_success TTY
'color when writing to a pager' '
111 TERM=vt100 test_terminal git log &&
112 colorful paginated.out
116 git config color.ui auto
117 test_expect_success
'color when writing to a file intended for a pager' '
118 TERM=vt100 GIT_PAGER_IN_USE=true git log > colorful.log &&
119 colorful colorful.log
122 unset PAGER GIT_PAGER
123 git config
--unset core.pager
124 test_expect_success
'determine default pager' '
125 less=$(git var GIT_PAGER) &&
129 if expr "$less" : '^[a-z]*$' > /dev
/null
&& test_have_prereq TTY
131 test_set_prereq SIMPLEPAGER
134 unset PAGER GIT_PAGER
135 git config
--unset core.pager
136 rm -f default_pager_used
137 test_expect_success SIMPLEPAGER
'default pager is used by default' '
138 cat > $less <<-EOF &&
140 wc > default_pager_used
143 PATH=.:$PATH test_terminal git log &&
144 test -e default_pager_used
148 git config
--unset core.pager
150 test_expect_success TTY
'PAGER overrides default pager' '
151 PAGER="wc > PAGER_used" &&
153 test_terminal git log &&
158 rm -f core.pager_used
159 test_expect_success TTY
'core.pager overrides PAGER' '
162 git config core.pager "wc > core.pager_used" &&
163 test_terminal git log &&
164 test -e core.pager_used
168 test_expect_success TTY
'GIT_PAGER overrides core.pager' '
169 git config core.pager wc &&
170 GIT_PAGER="wc > GIT_PAGER_used" &&
172 test_terminal git log &&
173 test -e GIT_PAGER_used