|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +test_description='Test automatic use of a pager.' |
| 4 | + |
| 5 | +. ./test-lib.sh |
| 6 | + |
| 7 | +rm -f stdout_is_tty |
| 8 | +test_expect_success 'is stdout a terminal?' ' |
| 9 | + if test -t 1 |
| 10 | + then |
| 11 | + : > stdout_is_tty |
| 12 | + fi |
| 13 | +' |
| 14 | + |
| 15 | +if test -e stdout_is_tty |
| 16 | +then |
| 17 | + test_set_prereq TTY |
| 18 | +else |
| 19 | + say stdout is not a terminal, so skipping some tests. |
| 20 | +fi |
| 21 | + |
| 22 | +unset GIT_PAGER GIT_PAGER_IN_USE |
| 23 | +git config --unset core.pager |
| 24 | +PAGER='cat > paginated.out' |
| 25 | +export PAGER |
| 26 | + |
| 27 | +test_expect_success 'setup' ' |
| 28 | + test_commit initial |
| 29 | +' |
| 30 | + |
| 31 | +rm -f paginated.out |
| 32 | +test_expect_success TTY 'some commands use a pager' ' |
| 33 | + git log && |
| 34 | + test -e paginated.out |
| 35 | +' |
| 36 | + |
| 37 | +rm -f paginated.out |
| 38 | +test_expect_success TTY 'some commands do not use a pager' ' |
| 39 | + git rev-list HEAD && |
| 40 | + ! test -e paginated.out |
| 41 | +' |
| 42 | + |
| 43 | +rm -f paginated.out |
| 44 | +test_expect_success 'no pager when stdout is a pipe' ' |
| 45 | + git log | cat && |
| 46 | + ! test -e paginated.out |
| 47 | +' |
| 48 | + |
| 49 | +rm -f paginated.out |
| 50 | +test_expect_success 'no pager when stdout is a regular file' ' |
| 51 | + git log > file && |
| 52 | + ! test -e paginated.out |
| 53 | +' |
| 54 | + |
| 55 | +rm -f paginated.out |
| 56 | +test_expect_success TTY 'git --paginate rev-list uses a pager' ' |
| 57 | + git --paginate rev-list HEAD && |
| 58 | + test -e paginated.out |
| 59 | +' |
| 60 | + |
| 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 |
| 65 | +' |
| 66 | + |
| 67 | +rm -f paginated.out |
| 68 | +test_expect_success TTY 'no pager with --no-pager' ' |
| 69 | + git --no-pager log && |
| 70 | + ! test -e paginated.out |
| 71 | +' |
| 72 | + |
| 73 | +# A colored commit log will begin with an appropriate ANSI escape |
| 74 | +# for the first color; the text "commit" comes later. |
| 75 | +colorful() { |
| 76 | + read firstline < $1 |
| 77 | + ! expr "$firstline" : "^[a-zA-Z]" >/dev/null |
| 78 | +} |
| 79 | + |
| 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 && |
| 85 | + colorful colorful.log |
| 86 | +' |
| 87 | + |
| 88 | +rm -f 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 |
| 93 | +' |
| 94 | + |
| 95 | +rm -f paginated.out |
| 96 | +git config color.ui auto |
| 97 | +test_expect_success TTY 'color when writing to a pager' ' |
| 98 | + TERM=vt100 git log && |
| 99 | + colorful paginated.out |
| 100 | +' |
| 101 | + |
| 102 | +rm -f colorful.log |
| 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 |
| 107 | +' |
| 108 | + |
| 109 | +unset PAGER GIT_PAGER |
| 110 | +git config --unset core.pager |
| 111 | +test_expect_success 'determine default pager' ' |
| 112 | + less=$(git var GIT_PAGER) && |
| 113 | + test -n "$less" |
| 114 | +' |
| 115 | + |
| 116 | +if expr "$less" : '^[a-z]*$' > /dev/null && test_have_prereq TTY |
| 117 | +then |
| 118 | + test_set_prereq SIMPLEPAGER |
| 119 | +fi |
| 120 | + |
| 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 && |
| 126 | + #!$SHELL_PATH |
| 127 | + : > default_pager_used |
| 128 | + EOF |
| 129 | + chmod +x $less && |
| 130 | + PATH=.:$PATH git log && |
| 131 | + test -e default_pager_used |
| 132 | +' |
| 133 | + |
| 134 | +unset GIT_PAGER |
| 135 | +git config --unset core.pager |
| 136 | +rm -f PAGER_used |
| 137 | +test_expect_success TTY 'PAGER overrides default pager' ' |
| 138 | + PAGER=": > PAGER_used" && |
| 139 | + export PAGER && |
| 140 | + git log && |
| 141 | + test -e PAGER_used |
| 142 | +' |
| 143 | + |
| 144 | +unset GIT_PAGER |
| 145 | +rm -f core.pager_used |
| 146 | +test_expect_success TTY 'core.pager overrides PAGER' ' |
| 147 | + PAGER=: && |
| 148 | + export PAGER && |
| 149 | + git config core.pager ": > core.pager_used" && |
| 150 | + git log && |
| 151 | + test -e core.pager_used |
| 152 | +' |
| 153 | + |
| 154 | +rm -f GIT_PAGER_used |
| 155 | +test_expect_success TTY 'GIT_PAGER overrides core.pager' ' |
| 156 | + git config core.pager : && |
| 157 | + GIT_PAGER=": > GIT_PAGER_used" && |
| 158 | + export GIT_PAGER && |
| 159 | + git log && |
| 160 | + test -e GIT_PAGER_used |
| 161 | +' |
| 162 | + |
| 163 | +test_done |
0 commit comments