Code

Merge branch 'maint-1.6.6' into maint-1.7.0
[git.git] / t / t7006-pager.sh
1 #!/bin/sh
3 test_description='Test automatic use of a pager.'
5 . ./test-lib.sh
7 rm -f stdout_is_tty
8 test_expect_success 'set up terminal for tests' '
9         if test -t 1
10         then
11                 : > stdout_is_tty
12         elif
13                 test_have_prereq PERL &&
14                 "$PERL_PATH" "$TEST_DIRECTORY"/t7006/test-terminal.perl \
15                         sh -c "test -t 1"
16         then
17                 : > test_terminal_works
18         fi
19 '
21 if test -e stdout_is_tty
22 then
23         test_terminal() { "$@"; }
24         test_set_prereq TTY
25 elif test -e test_terminal_works
26 then
27         test_terminal() {
28                 "$PERL_PATH" "$TEST_DIRECTORY"/t7006/test-terminal.perl "$@"
29         }
30         test_set_prereq TTY
31 else
32         say no usable terminal, so skipping some tests
33 fi
35 unset GIT_PAGER GIT_PAGER_IN_USE
36 git config --unset core.pager
37 PAGER='cat > paginated.out'
38 export PAGER
40 test_expect_success 'setup' '
41         test_commit initial
42 '
44 rm -f paginated.out
45 test_expect_success TTY 'some commands use a pager' '
46         test_terminal git log &&
47         test -e paginated.out
48 '
50 rm -f paginated.out
51 test_expect_success TTY 'some commands do not use a pager' '
52         test_terminal git rev-list HEAD &&
53         ! test -e paginated.out
54 '
56 rm -f paginated.out
57 test_expect_success 'no pager when stdout is a pipe' '
58         git log | cat &&
59         ! test -e paginated.out
60 '
62 rm -f paginated.out
63 test_expect_success 'no pager when stdout is a regular file' '
64         git log > file &&
65         ! test -e paginated.out
66 '
68 rm -f paginated.out
69 test_expect_success TTY 'git --paginate rev-list uses a pager' '
70         test_terminal git --paginate rev-list HEAD &&
71         test -e paginated.out
72 '
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
78 '
80 rm -f paginated.out
81 test_expect_success TTY 'no pager with --no-pager' '
82         test_terminal git --no-pager log &&
83         ! test -e paginated.out
84 '
86 # A colored commit log will begin with an appropriate ANSI escape
87 # for the first color; the text "commit" comes later.
88 colorful() {
89         read firstline < $1
90         ! expr "$firstline" : "^[a-zA-Z]" >/dev/null
91 }
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 &&
98         colorful colorful.log
99 '
101 rm -f 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
108 rm -f paginated.out
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
115 rm -f colorful.log
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) &&
126         test -n "$less"
129 if expr "$less" : '^[a-z]*$' > /dev/null && test_have_prereq TTY
130 then
131         test_set_prereq SIMPLEPAGER
132 fi
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 &&
139         #!$SHELL_PATH
140         wc > default_pager_used
141         EOF
142         chmod +x $less &&
143         PATH=.:$PATH test_terminal git log &&
144         test -e default_pager_used
147 unset GIT_PAGER
148 git config --unset core.pager
149 rm -f PAGER_used
150 test_expect_success TTY 'PAGER overrides default pager' '
151         PAGER="wc > PAGER_used" &&
152         export PAGER &&
153         test_terminal git log &&
154         test -e PAGER_used
157 unset GIT_PAGER
158 rm -f core.pager_used
159 test_expect_success TTY 'core.pager overrides PAGER' '
160         PAGER=wc &&
161         export PAGER &&
162         git config core.pager "wc > core.pager_used" &&
163         test_terminal git log &&
164         test -e core.pager_used
167 rm -f GIT_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" &&
171         export GIT_PAGER &&
172         test_terminal git log &&
173         test -e GIT_PAGER_used
176 test_done