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