3 test_description
='Test automatic use of a pager.'
8 test_expect_success
'is stdout a terminal?' '
15 if test -e stdout_is_tty
19 say stdout is not a terminal
, so skipping some tests.
22 unset GIT_PAGER GIT_PAGER_IN_USE
23 git config
--unset core.pager
24 PAGER
='cat > paginated.out'
27 test_expect_success
'setup' '
32 test_expect_success TTY
'some commands use a pager' '
38 test_expect_success TTY
'some commands do not use a pager' '
40 ! test -e paginated.out
44 test_expect_success
'no pager when stdout is a pipe' '
46 ! test -e paginated.out
50 test_expect_success
'no pager when stdout is a regular file' '
52 ! test -e paginated.out
56 test_expect_success TTY
'git --paginate rev-list uses a pager' '
57 git --paginate rev-list HEAD &&
61 rm -f file paginated.out
62 test_expect_success
'no pager even with --paginate when stdout is a pipe' '
63 git --paginate log | cat &&
64 ! test -e paginated.out
68 test_expect_success TTY
'no pager with --no-pager' '
70 ! test -e paginated.out
73 # A colored commit log will begin with an appropriate ANSI escape
74 # for the first color; the text "commit" comes later.
77 ! expr "$firstline" : "^[a-zA-Z]" >/dev
/null
80 rm -f colorful.log colorless.log
81 test_expect_success
'tests can detect color' '
82 git log --no-color > colorless.log &&
83 git log --color > colorful.log &&
84 ! colorful colorless.log &&
89 git config color.ui auto
90 test_expect_success
'no color when stdout is a regular file' '
91 git log > colorless.log &&
92 ! colorful colorless.log
96 git config color.ui auto
97 test_expect_success TTY
'color when writing to a pager' '
99 colorful paginated.out
103 git config color.ui auto
104 test_expect_success
'color when writing to a file intended for a pager' '
105 TERM=vt100 GIT_PAGER_IN_USE=true git log > colorful.log &&
106 colorful colorful.log
109 unset PAGER GIT_PAGER
110 git config
--unset core.pager
111 test_expect_success
'determine default pager' '
112 less=$(git var GIT_PAGER) &&
116 if expr "$less" : '^[a-z]*$' > /dev
/null
&& test_have_prereq TTY
118 test_set_prereq SIMPLEPAGER
121 unset PAGER GIT_PAGER
122 git config
--unset core.pager
123 rm -f default_pager_used
124 test_expect_success SIMPLEPAGER
'default pager is used by default' '
125 cat > $less <<-EOF &&
127 : > default_pager_used
130 PATH=.:$PATH git log &&
131 test -e default_pager_used
135 git config
--unset core.pager
137 test_expect_success TTY
'PAGER overrides default pager' '
138 PAGER=": > PAGER_used" &&
145 rm -f core.pager_used
146 test_expect_success TTY
'core.pager overrides PAGER' '
149 git config core.pager ": > core.pager_used" &&
151 test -e core.pager_used
155 test_expect_success TTY
'GIT_PAGER overrides core.pager' '
156 git config core.pager : &&
157 GIT_PAGER=": > GIT_PAGER_used" &&
160 test -e GIT_PAGER_used