]>
Commit | Line | Data |
---|---|---|
60b6e220 JN |
1 | #!/bin/sh |
2 | ||
3 | test_description='Test automatic use of a pager.' | |
4 | ||
5 | . ./test-lib.sh | |
678e484b | 6 | . "$TEST_DIRECTORY"/lib-pager.sh |
cc4e48fc | 7 | . "$TEST_DIRECTORY"/lib-terminal.sh |
60b6e220 | 8 | |
60b6e220 | 9 | test_expect_success 'setup' ' |
00648ba0 | 10 | sane_unset GIT_PAGER GIT_PAGER_IN_USE && |
8d68a6d5 | 11 | test_unconfig core.pager && |
fdf1bc48 JN |
12 | |
13 | PAGER="cat >paginated.out" && | |
14 | export PAGER && | |
15 | ||
60b6e220 JN |
16 | test_commit initial |
17 | ' | |
18 | ||
60b6e220 | 19 | test_expect_success TTY 'some commands use a pager' ' |
0d164519 | 20 | rm -f paginated.out && |
2d3ca216 | 21 | test_terminal git log && |
60b6e220 JN |
22 | test -e paginated.out |
23 | ' | |
24 | ||
2cb60093 NTND |
25 | test_expect_failure TTY 'pager runs from subdir' ' |
26 | echo subdir/paginated.out >expected && | |
27 | mkdir -p subdir && | |
28 | rm -f paginated.out subdir/paginated.out && | |
29 | ( | |
30 | cd subdir && | |
31 | test_terminal git log | |
32 | ) && | |
33 | { | |
34 | ls paginated.out subdir/paginated.out || | |
35 | : | |
36 | } >actual && | |
37 | test_cmp expected actual | |
38 | ' | |
39 | ||
e54c1f2d JN |
40 | test_expect_success TTY 'LESS and LV envvars are set for pagination' ' |
41 | ( | |
42 | sane_unset LESS LV && | |
52c02f65 | 43 | PAGER="env >pager-env.out; wc" && |
e54c1f2d JN |
44 | export PAGER && |
45 | ||
46 | test_terminal git log | |
47 | ) && | |
48 | grep ^LESS= pager-env.out && | |
49 | grep ^LV= pager-env.out | |
50 | ' | |
51 | ||
995bc22d EW |
52 | test_expect_success !MINGW,TTY 'LESS and LV envvars set by git-sh-setup' ' |
53 | ( | |
54 | sane_unset LESS LV && | |
55 | PAGER="env >pager-env.out; wc" && | |
56 | export PAGER && | |
57 | PATH="$(git --exec-path):$PATH" && | |
58 | export PATH && | |
59 | test_terminal sh -c ". git-sh-setup && git_pager" | |
60 | ) && | |
61 | grep ^LESS= pager-env.out && | |
62 | grep ^LV= pager-env.out | |
63 | ' | |
64 | ||
60b6e220 | 65 | test_expect_success TTY 'some commands do not use a pager' ' |
0d164519 | 66 | rm -f paginated.out && |
2d3ca216 | 67 | test_terminal git rev-list HEAD && |
60b6e220 JN |
68 | ! test -e paginated.out |
69 | ' | |
70 | ||
60b6e220 | 71 | test_expect_success 'no pager when stdout is a pipe' ' |
0d164519 | 72 | rm -f paginated.out && |
60b6e220 JN |
73 | git log | cat && |
74 | ! test -e paginated.out | |
75 | ' | |
76 | ||
60b6e220 | 77 | test_expect_success 'no pager when stdout is a regular file' ' |
0d164519 | 78 | rm -f paginated.out && |
fdf1bc48 | 79 | git log >file && |
60b6e220 JN |
80 | ! test -e paginated.out |
81 | ' | |
82 | ||
60b6e220 | 83 | test_expect_success TTY 'git --paginate rev-list uses a pager' ' |
0d164519 | 84 | rm -f paginated.out && |
2d3ca216 | 85 | test_terminal git --paginate rev-list HEAD && |
60b6e220 JN |
86 | test -e paginated.out |
87 | ' | |
88 | ||
60b6e220 | 89 | test_expect_success 'no pager even with --paginate when stdout is a pipe' ' |
0d164519 | 90 | rm -f file paginated.out && |
60b6e220 JN |
91 | git --paginate log | cat && |
92 | ! test -e paginated.out | |
93 | ' | |
94 | ||
60b6e220 | 95 | test_expect_success TTY 'no pager with --no-pager' ' |
0d164519 | 96 | rm -f paginated.out && |
2d3ca216 | 97 | test_terminal git --no-pager log && |
60b6e220 JN |
98 | ! test -e paginated.out |
99 | ' | |
100 | ||
ff38d1a9 NTND |
101 | test_expect_success TTY 'configuration can disable pager' ' |
102 | rm -f paginated.out && | |
8d68a6d5 | 103 | test_unconfig pager.grep && |
ff38d1a9 NTND |
104 | test_terminal git grep initial && |
105 | test -e paginated.out && | |
106 | ||
107 | rm -f paginated.out && | |
8d68a6d5 | 108 | test_config pager.grep false && |
ff38d1a9 NTND |
109 | test_terminal git grep initial && |
110 | ! test -e paginated.out | |
111 | ' | |
112 | ||
41bf3bc2 | 113 | test_expect_success TTY 'configuration can enable pager (from subdir)' ' |
2cb60093 NTND |
114 | rm -f paginated.out && |
115 | mkdir -p subdir && | |
8d68a6d5 | 116 | test_config pager.bundle true && |
2cb60093 NTND |
117 | |
118 | git bundle create test.bundle --all && | |
119 | rm -f paginated.out subdir/paginated.out && | |
120 | ( | |
121 | cd subdir && | |
122 | test_terminal git bundle unbundle ../test.bundle | |
123 | ) && | |
124 | { | |
125 | test -e paginated.out || | |
126 | test -e subdir/paginated.out | |
127 | } | |
128 | ' | |
129 | ||
ff1e7248 | 130 | test_expect_success TTY 'git tag -l defaults to paging' ' |
b3ee740c MÅ |
131 | rm -f paginated.out && |
132 | test_terminal git tag -l && | |
ff1e7248 | 133 | test -e paginated.out |
b3ee740c MÅ |
134 | ' |
135 | ||
136 | test_expect_success TTY 'git tag -l respects pager.tag' ' | |
137 | rm -f paginated.out && | |
ff1e7248 MÅ |
138 | test_terminal git -c pager.tag=false tag -l && |
139 | ! test -e paginated.out | |
b3ee740c MÅ |
140 | ' |
141 | ||
142 | test_expect_success TTY 'git tag -l respects --no-pager' ' | |
143 | rm -f paginated.out && | |
144 | test_terminal git -c pager.tag --no-pager tag -l && | |
145 | ! test -e paginated.out | |
146 | ' | |
147 | ||
ff1e7248 | 148 | test_expect_success TTY 'git tag with no args defaults to paging' ' |
b3ee740c MÅ |
149 | # no args implies -l so this should page like -l |
150 | rm -f paginated.out && | |
151 | test_terminal git tag && | |
ff1e7248 | 152 | test -e paginated.out |
b3ee740c MÅ |
153 | ' |
154 | ||
155 | test_expect_success TTY 'git tag with no args respects pager.tag' ' | |
156 | # no args implies -l so this should page like -l | |
157 | rm -f paginated.out && | |
ff1e7248 MÅ |
158 | test_terminal git -c pager.tag=false tag && |
159 | ! test -e paginated.out | |
b3ee740c MÅ |
160 | ' |
161 | ||
ff1e7248 | 162 | test_expect_success TTY 'git tag --contains defaults to paging' ' |
b3ee740c MÅ |
163 | # --contains implies -l so this should page like -l |
164 | rm -f paginated.out && | |
165 | test_terminal git tag --contains && | |
ff1e7248 | 166 | test -e paginated.out |
b3ee740c MÅ |
167 | ' |
168 | ||
169 | test_expect_success TTY 'git tag --contains respects pager.tag' ' | |
170 | # --contains implies -l so this should page like -l | |
171 | rm -f paginated.out && | |
ff1e7248 MÅ |
172 | test_terminal git -c pager.tag=false tag --contains && |
173 | ! test -e paginated.out | |
b3ee740c MÅ |
174 | ' |
175 | ||
176 | test_expect_success TTY 'git tag -a defaults to not paging' ' | |
177 | test_when_finished "git tag -d newtag" && | |
178 | rm -f paginated.out && | |
179 | test_terminal git tag -am message newtag && | |
180 | ! test -e paginated.out | |
181 | ' | |
182 | ||
de121ffe | 183 | test_expect_success TTY 'git tag -a ignores pager.tag' ' |
b3ee740c MÅ |
184 | test_when_finished "git tag -d newtag" && |
185 | rm -f paginated.out && | |
186 | test_terminal git -c pager.tag tag -am message newtag && | |
187 | ! test -e paginated.out | |
188 | ' | |
189 | ||
190 | test_expect_success TTY 'git tag -a respects --paginate' ' | |
191 | test_when_finished "git tag -d newtag" && | |
192 | rm -f paginated.out && | |
193 | test_terminal git --paginate tag -am message newtag && | |
194 | test -e paginated.out | |
195 | ' | |
196 | ||
595d59e2 | 197 | test_expect_success TTY 'git tag as alias ignores pager.tag with -a' ' |
de121ffe MÅ |
198 | test_when_finished "git tag -d newtag" && |
199 | rm -f paginated.out && | |
200 | test_terminal git -c pager.tag -c alias.t=tag t -am message newtag && | |
201 | ! test -e paginated.out | |
202 | ' | |
203 | ||
204 | test_expect_success TTY 'git tag as alias respects pager.tag with -l' ' | |
205 | rm -f paginated.out && | |
ff1e7248 MÅ |
206 | test_terminal git -c pager.tag=false -c alias.t=tag t -l && |
207 | ! test -e paginated.out | |
de121ffe MÅ |
208 | ' |
209 | ||
0ae19de7 | 210 | test_expect_success TTY 'git branch defaults to paging' ' |
ed104fa9 MÅ |
211 | rm -f paginated.out && |
212 | test_terminal git branch && | |
0ae19de7 | 213 | test -e paginated.out |
ed104fa9 MÅ |
214 | ' |
215 | ||
216 | test_expect_success TTY 'git branch respects pager.branch' ' | |
217 | rm -f paginated.out && | |
0ae19de7 MÅ |
218 | test_terminal git -c pager.branch=false branch && |
219 | ! test -e paginated.out | |
ed104fa9 MÅ |
220 | ' |
221 | ||
222 | test_expect_success TTY 'git branch respects --no-pager' ' | |
223 | rm -f paginated.out && | |
0ae19de7 | 224 | test_terminal git --no-pager branch && |
ed104fa9 MÅ |
225 | ! test -e paginated.out |
226 | ' | |
227 | ||
d74b541e | 228 | test_expect_success TTY 'git branch --edit-description ignores pager.branch' ' |
ed104fa9 MÅ |
229 | rm -f paginated.out editor.used && |
230 | write_script editor <<-\EOF && | |
231 | echo "New description" >"$1" | |
232 | touch editor.used | |
233 | EOF | |
234 | EDITOR=./editor test_terminal git -c pager.branch branch --edit-description && | |
235 | ! test -e paginated.out && | |
236 | test -e editor.used | |
237 | ' | |
238 | ||
d74b541e | 239 | test_expect_success TTY 'git branch --set-upstream-to ignores pager.branch' ' |
ed104fa9 MÅ |
240 | rm -f paginated.out && |
241 | git branch other && | |
242 | test_when_finished "git branch -D other" && | |
243 | test_terminal git -c pager.branch branch --set-upstream-to=other && | |
244 | test_when_finished "git branch --unset-upstream" && | |
d74b541e | 245 | ! test -e paginated.out |
ed104fa9 MÅ |
246 | ' |
247 | ||
32888b8f | 248 | test_expect_success TTY 'git config ignores pager.config when setting' ' |
cd878a20 MÅ |
249 | rm -f paginated.out && |
250 | test_terminal git -c pager.config config foo.bar bar && | |
32888b8f | 251 | ! test -e paginated.out |
cd878a20 MÅ |
252 | ' |
253 | ||
32888b8f | 254 | test_expect_success TTY 'git config --edit ignores pager.config' ' |
cd878a20 MÅ |
255 | rm -f paginated.out editor.used && |
256 | write_script editor <<-\EOF && | |
257 | touch editor.used | |
258 | EOF | |
259 | EDITOR=./editor test_terminal git -c pager.config config --edit && | |
260 | ! test -e paginated.out && | |
261 | test -e editor.used | |
262 | ' | |
263 | ||
32888b8f | 264 | test_expect_success TTY 'git config --get ignores pager.config' ' |
cd878a20 MÅ |
265 | rm -f paginated.out && |
266 | test_terminal git -c pager.config config --get foo.bar && | |
32888b8f | 267 | ! test -e paginated.out |
cd878a20 MÅ |
268 | ' |
269 | ||
c0e9f5be | 270 | test_expect_success TTY 'git config --get-urlmatch defaults to paging' ' |
cd878a20 MÅ |
271 | rm -f paginated.out && |
272 | test_terminal git -c http."https://foo.com/".bar=foo \ | |
273 | config --get-urlmatch http https://foo.com && | |
c0e9f5be | 274 | test -e paginated.out |
cd878a20 MÅ |
275 | ' |
276 | ||
277 | test_expect_success TTY 'git config --get-all respects pager.config' ' | |
278 | rm -f paginated.out && | |
c0e9f5be MÅ |
279 | test_terminal git -c pager.config=false config --get-all foo.bar && |
280 | ! test -e paginated.out | |
cd878a20 MÅ |
281 | ' |
282 | ||
c0e9f5be | 283 | test_expect_success TTY 'git config --list defaults to paging' ' |
cd878a20 MÅ |
284 | rm -f paginated.out && |
285 | test_terminal git config --list && | |
c0e9f5be | 286 | test -e paginated.out |
cd878a20 MÅ |
287 | ' |
288 | ||
289 | ||
60b6e220 JN |
290 | # A colored commit log will begin with an appropriate ANSI escape |
291 | # for the first color; the text "commit" comes later. | |
292 | colorful() { | |
fdf1bc48 | 293 | read firstline <$1 |
e0ae1e6f | 294 | ! expr "$firstline" : "[a-zA-Z]" >/dev/null |
60b6e220 JN |
295 | } |
296 | ||
60b6e220 | 297 | test_expect_success 'tests can detect color' ' |
0d164519 | 298 | rm -f colorful.log colorless.log && |
fdf1bc48 JN |
299 | git log --no-color >colorless.log && |
300 | git log --color >colorful.log && | |
60b6e220 JN |
301 | ! colorful colorless.log && |
302 | colorful colorful.log | |
303 | ' | |
304 | ||
60b6e220 | 305 | test_expect_success 'no color when stdout is a regular file' ' |
fdf1bc48 | 306 | rm -f colorless.log && |
0d164519 | 307 | test_config color.ui auto && |
fdf1bc48 | 308 | git log >colorless.log && |
60b6e220 JN |
309 | ! colorful colorless.log |
310 | ' | |
311 | ||
60b6e220 | 312 | test_expect_success TTY 'color when writing to a pager' ' |
fdf1bc48 | 313 | rm -f paginated.out && |
0d164519 | 314 | test_config color.ui auto && |
e433749d | 315 | test_terminal git log && |
60b6e220 JN |
316 | colorful paginated.out |
317 | ' | |
318 | ||
daa0c3d9 JK |
319 | test_expect_success TTY 'colors are suppressed by color.pager' ' |
320 | rm -f paginated.out && | |
321 | test_config color.ui auto && | |
322 | test_config color.pager false && | |
e433749d | 323 | test_terminal git log && |
daa0c3d9 JK |
324 | ! colorful paginated.out |
325 | ' | |
326 | ||
60b6e220 | 327 | test_expect_success 'color when writing to a file intended for a pager' ' |
fdf1bc48 | 328 | rm -f colorful.log && |
0d164519 | 329 | test_config color.ui auto && |
fdf1bc48 JN |
330 | ( |
331 | TERM=vt100 && | |
332 | GIT_PAGER_IN_USE=true && | |
333 | export TERM GIT_PAGER_IN_USE && | |
334 | git log >colorful.log | |
335 | ) && | |
60b6e220 JN |
336 | colorful colorful.log |
337 | ' | |
338 | ||
2e6c012e JK |
339 | test_expect_success TTY 'colors are sent to pager for external commands' ' |
340 | test_config alias.externallog "!git log" && | |
341 | test_config color.ui auto && | |
e433749d | 342 | test_terminal git -p externallog && |
2e6c012e JK |
343 | colorful paginated.out |
344 | ' | |
345 | ||
3c7406d4 JN |
346 | # Use this helper to make it easy for the caller of your |
347 | # terminal-using function to specify whether it should fail. | |
348 | # If you write | |
349 | # | |
350 | # your_test() { | |
351 | # parse_args "$@" | |
352 | # | |
353 | # $test_expectation "$cmd - behaves well" " | |
354 | # ... | |
355 | # $full_command && | |
356 | # ... | |
357 | # " | |
358 | # } | |
359 | # | |
360 | # then your test can be used like this: | |
361 | # | |
362 | # your_test expect_(success|failure) [test_must_fail] 'git foo' | |
363 | # | |
364 | parse_args() { | |
365 | test_expectation="test_$1" | |
366 | shift | |
367 | if test "$1" = test_must_fail | |
368 | then | |
369 | full_command="test_must_fail test_terminal " | |
370 | shift | |
371 | else | |
372 | full_command="test_terminal " | |
373 | fi | |
374 | cmd=$1 | |
375 | full_command="$full_command $1" | |
376 | } | |
fdf1bc48 | 377 | |
8f81449e JN |
378 | test_default_pager() { |
379 | parse_args "$@" | |
380 | ||
996621eb | 381 | $test_expectation SIMPLEPAGER,TTY "$cmd - default pager is used by default" " |
00648ba0 | 382 | sane_unset PAGER GIT_PAGER && |
8d68a6d5 | 383 | test_unconfig core.pager && |
0d164519 | 384 | rm -f default_pager_used && |
8f81449e JN |
385 | cat >\$less <<-\EOF && |
386 | #!/bin/sh | |
387 | wc >default_pager_used | |
388 | EOF | |
389 | chmod +x \$less && | |
390 | ( | |
391 | PATH=.:\$PATH && | |
392 | export PATH && | |
393 | $full_command | |
394 | ) && | |
395 | test -e default_pager_used | |
396 | " | |
397 | } | |
60b6e220 | 398 | |
8f81449e JN |
399 | test_PAGER_overrides() { |
400 | parse_args "$@" | |
fdf1bc48 | 401 | |
8f81449e | 402 | $test_expectation TTY "$cmd - PAGER overrides default pager" " |
00648ba0 | 403 | sane_unset GIT_PAGER && |
8d68a6d5 | 404 | test_unconfig core.pager && |
0d164519 | 405 | rm -f PAGER_used && |
8f81449e JN |
406 | PAGER='wc >PAGER_used' && |
407 | export PAGER && | |
408 | $full_command && | |
409 | test -e PAGER_used | |
410 | " | |
411 | } | |
fdf1bc48 | 412 | |
8f81449e | 413 | test_core_pager_overrides() { |
73e25e7c NTND |
414 | if_local_config= |
415 | used_if_wanted='overrides PAGER' | |
416 | test_core_pager "$@" | |
417 | } | |
60b6e220 | 418 | |
73e25e7c NTND |
419 | test_local_config_ignored() { |
420 | if_local_config='! ' | |
421 | used_if_wanted='is not used' | |
422 | test_core_pager "$@" | |
423 | } | |
fdf1bc48 | 424 | |
73e25e7c | 425 | test_core_pager() { |
8f81449e JN |
426 | parse_args "$@" |
427 | ||
73e25e7c | 428 | $test_expectation TTY "$cmd - repository-local core.pager setting $used_if_wanted" " |
00648ba0 | 429 | sane_unset GIT_PAGER && |
0d164519 | 430 | rm -f core.pager_used && |
8f81449e JN |
431 | PAGER=wc && |
432 | export PAGER && | |
8d68a6d5 | 433 | test_config core.pager 'wc >core.pager_used' && |
8f81449e | 434 | $full_command && |
73e25e7c | 435 | ${if_local_config}test -e core.pager_used |
8f81449e JN |
436 | " |
437 | } | |
438 | ||
bce2c9ae | 439 | test_core_pager_subdir() { |
73e25e7c NTND |
440 | if_local_config= |
441 | used_if_wanted='overrides PAGER' | |
442 | test_pager_subdir_helper "$@" | |
443 | } | |
444 | ||
445 | test_no_local_config_subdir() { | |
446 | if_local_config='! ' | |
447 | used_if_wanted='is not used' | |
448 | test_pager_subdir_helper "$@" | |
449 | } | |
450 | ||
451 | test_pager_subdir_helper() { | |
bce2c9ae JN |
452 | parse_args "$@" |
453 | ||
73e25e7c | 454 | $test_expectation TTY "$cmd - core.pager $used_if_wanted from subdirectory" " |
00648ba0 | 455 | sane_unset GIT_PAGER && |
bce2c9ae | 456 | rm -f core.pager_used && |
0d164519 | 457 | rm -fr sub && |
bce2c9ae JN |
458 | PAGER=wc && |
459 | stampname=\$(pwd)/core.pager_used && | |
460 | export PAGER stampname && | |
8d68a6d5 | 461 | test_config core.pager 'wc >\"\$stampname\"' && |
bce2c9ae JN |
462 | mkdir sub && |
463 | ( | |
464 | cd sub && | |
465 | $full_command | |
466 | ) && | |
73e25e7c | 467 | ${if_local_config}test -e core.pager_used |
bce2c9ae JN |
468 | " |
469 | } | |
470 | ||
8f81449e JN |
471 | test_GIT_PAGER_overrides() { |
472 | parse_args "$@" | |
473 | ||
474 | $test_expectation TTY "$cmd - GIT_PAGER overrides core.pager" " | |
0d164519 | 475 | rm -f GIT_PAGER_used && |
8d68a6d5 | 476 | test_config core.pager wc && |
8f81449e JN |
477 | GIT_PAGER='wc >GIT_PAGER_used' && |
478 | export GIT_PAGER && | |
479 | $full_command && | |
480 | test -e GIT_PAGER_used | |
481 | " | |
482 | } | |
fdf1bc48 | 483 | |
73e25e7c NTND |
484 | test_doesnt_paginate() { |
485 | parse_args "$@" | |
486 | ||
487 | $test_expectation TTY "no pager for '$cmd'" " | |
0d164519 | 488 | rm -f GIT_PAGER_used && |
73e25e7c NTND |
489 | GIT_PAGER='wc >GIT_PAGER_used' && |
490 | export GIT_PAGER && | |
491 | $full_command && | |
492 | ! test -e GIT_PAGER_used | |
493 | " | |
494 | } | |
495 | ||
030149a4 JN |
496 | test_pager_choices() { |
497 | test_default_pager expect_success "$@" | |
498 | test_PAGER_overrides expect_success "$@" | |
499 | test_core_pager_overrides expect_success "$@" | |
500 | test_core_pager_subdir expect_success "$@" | |
501 | test_GIT_PAGER_overrides expect_success "$@" | |
502 | } | |
503 | ||
504 | test_expect_success 'setup: some aliases' ' | |
505 | git config alias.aliasedlog log && | |
506 | git config alias.true "!true" | |
60b6e220 JN |
507 | ' |
508 | ||
030149a4 JN |
509 | test_pager_choices 'git log' |
510 | test_pager_choices 'git -p log' | |
511 | test_pager_choices 'git aliasedlog' | |
512 | ||
513 | test_default_pager expect_success 'git -p aliasedlog' | |
514 | test_PAGER_overrides expect_success 'git -p aliasedlog' | |
515 | test_core_pager_overrides expect_success 'git -p aliasedlog' | |
1a27409a | 516 | test_core_pager_subdir expect_success 'git -p aliasedlog' |
030149a4 JN |
517 | test_GIT_PAGER_overrides expect_success 'git -p aliasedlog' |
518 | ||
519 | test_default_pager expect_success 'git -p true' | |
520 | test_PAGER_overrides expect_success 'git -p true' | |
521 | test_core_pager_overrides expect_success 'git -p true' | |
1a27409a | 522 | test_core_pager_subdir expect_success 'git -p true' |
030149a4 JN |
523 | test_GIT_PAGER_overrides expect_success 'git -p true' |
524 | ||
525 | test_default_pager expect_success test_must_fail 'git -p request-pull' | |
526 | test_PAGER_overrides expect_success test_must_fail 'git -p request-pull' | |
527 | test_core_pager_overrides expect_success test_must_fail 'git -p request-pull' | |
1a27409a | 528 | test_core_pager_subdir expect_success test_must_fail 'git -p request-pull' |
030149a4 | 529 | test_GIT_PAGER_overrides expect_success test_must_fail 'git -p request-pull' |
8f81449e JN |
530 | |
531 | test_default_pager expect_success test_must_fail 'git -p' | |
532 | test_PAGER_overrides expect_success test_must_fail 'git -p' | |
73e25e7c | 533 | test_local_config_ignored expect_failure test_must_fail 'git -p' |
8f81449e JN |
534 | test_GIT_PAGER_overrides expect_success test_must_fail 'git -p' |
535 | ||
1a27409a | 536 | test_expect_success TTY 'core.pager in repo config works and retains cwd' ' |
551d535d JS |
537 | sane_unset GIT_PAGER && |
538 | test_config core.pager "cat >cwd-retained" && | |
539 | ( | |
540 | cd sub && | |
541 | rm -f cwd-retained && | |
542 | test_terminal git -p rev-parse HEAD && | |
543 | test_path_is_file cwd-retained | |
544 | ) | |
545 | ' | |
546 | ||
a9bcf658 | 547 | test_expect_success TTY 'core.pager is found via alias in subdirectory' ' |
3f9c5dfb JS |
548 | sane_unset GIT_PAGER && |
549 | test_config core.pager "cat >via-alias" && | |
550 | ( | |
551 | cd sub && | |
552 | rm -f via-alias && | |
553 | test_terminal git -c alias.r="-p rev-parse" r HEAD && | |
554 | test_path_is_file via-alias | |
555 | ) | |
556 | ' | |
557 | ||
030149a4 | 558 | test_doesnt_paginate expect_failure test_must_fail 'git -p nonsense' |
60b6e220 | 559 | |
773b69bf NTND |
560 | test_pager_choices 'git shortlog' |
561 | test_expect_success 'setup: configure shortlog not to paginate' ' | |
562 | git config pager.shortlog false | |
563 | ' | |
564 | test_doesnt_paginate expect_success 'git shortlog' | |
565 | test_no_local_config_subdir expect_success 'git shortlog' | |
566 | test_default_pager expect_success 'git -p shortlog' | |
567 | test_core_pager_subdir expect_success 'git -p shortlog' | |
568 | ||
d1ea8962 NTND |
569 | test_core_pager_subdir expect_success test_must_fail \ |
570 | 'git -p apply </dev/null' | |
571 | ||
9bad7233 | 572 | test_expect_success TTY 'command-specific pager' ' |
212ad944 | 573 | sane_unset PAGER GIT_PAGER && |
9bad7233 JK |
574 | echo "foo:initial" >expect && |
575 | >actual && | |
8d68a6d5 JK |
576 | test_unconfig core.pager && |
577 | test_config pager.log "sed s/^/foo:/ >actual" && | |
9bad7233 JK |
578 | test_terminal git log --format=%s -1 && |
579 | test_cmp expect actual | |
580 | ' | |
581 | ||
582 | test_expect_success TTY 'command-specific pager overrides core.pager' ' | |
212ad944 | 583 | sane_unset PAGER GIT_PAGER && |
9bad7233 JK |
584 | echo "foo:initial" >expect && |
585 | >actual && | |
99094a7a | 586 | test_config core.pager "exit 1" && |
8d68a6d5 | 587 | test_config pager.log "sed s/^/foo:/ >actual" && |
9bad7233 JK |
588 | test_terminal git log --format=%s -1 && |
589 | test_cmp expect actual | |
590 | ' | |
591 | ||
592 | test_expect_success TTY 'command-specific pager overridden by environment' ' | |
593 | GIT_PAGER="sed s/^/foo:/ >actual" && export GIT_PAGER && | |
594 | >actual && | |
595 | echo "foo:initial" >expect && | |
8d68a6d5 | 596 | test_config pager.log "exit 1" && |
9bad7233 JK |
597 | test_terminal git log --format=%s -1 && |
598 | test_cmp expect actual | |
599 | ' | |
600 | ||
92058e4d JK |
601 | test_expect_success 'setup external command' ' |
602 | cat >git-external <<-\EOF && | |
603 | #!/bin/sh | |
604 | git "$@" | |
605 | EOF | |
606 | chmod +x git-external | |
607 | ' | |
608 | ||
609 | test_expect_success TTY 'command-specific pager works for external commands' ' | |
610 | sane_unset PAGER GIT_PAGER && | |
611 | echo "foo:initial" >expect && | |
612 | >actual && | |
613 | test_config pager.external "sed s/^/foo:/ >actual" && | |
90ae5d27 | 614 | test_terminal git --exec-path="$(pwd)" external log --format=%s -1 && |
92058e4d JK |
615 | test_cmp expect actual |
616 | ' | |
617 | ||
618 | test_expect_success TTY 'sub-commands of externals use their own pager' ' | |
619 | sane_unset PAGER GIT_PAGER && | |
620 | echo "foo:initial" >expect && | |
621 | >actual && | |
622 | test_config pager.log "sed s/^/foo:/ >actual" && | |
623 | test_terminal git --exec-path=. external log --format=%s -1 && | |
624 | test_cmp expect actual | |
625 | ' | |
626 | ||
627 | test_expect_success TTY 'external command pagers override sub-commands' ' | |
628 | sane_unset PAGER GIT_PAGER && | |
92058e4d JK |
629 | >actual && |
630 | test_config pager.external false && | |
631 | test_config pager.log "sed s/^/log:/ >actual" && | |
632 | test_terminal git --exec-path=. external log --format=%s -1 && | |
d3c6751b | 633 | test_must_be_empty actual |
92058e4d JK |
634 | ' |
635 | ||
9e9de18f JK |
636 | test_expect_success 'command with underscores does not complain' ' |
637 | write_script git-under_score <<-\EOF && | |
638 | echo ok | |
639 | EOF | |
640 | git --exec-path=. under_score >actual 2>&1 && | |
641 | echo ok >expect && | |
642 | test_cmp expect actual | |
643 | ' | |
644 | ||
b2d3fd28 KD |
645 | test_expect_success TTY 'git tag with auto-columns ' ' |
646 | test_commit one && | |
647 | test_commit two && | |
648 | test_commit three && | |
649 | test_commit four && | |
650 | test_commit five && | |
651 | cat >expect <<-\EOF && | |
652 | initial one two three four five | |
653 | EOF | |
654 | test_terminal env PAGER="cat >actual" COLUMNS=80 \ | |
655 | git -c column.ui=auto tag --sort=authordate && | |
656 | test_cmp expect actual | |
657 | ' | |
658 | ||
60b6e220 | 659 | test_done |