Debian Codegraph @

tests/test-pager-legacy.t

raw
1 $ cat >> fakepager.py <<EOF
2 > import sys
3 > for line in sys.stdin:
4 > sys.stdout.write('paged! %r\n' % line)
5 > EOF
6
7 Enable ui.formatted because pager won't fire without it, and set up
8 pager and tell it to use our fake pager that lets us see when the
9 pager was running.
10 $ cat >> $HGRCPATH <<EOF
11 > [ui]
12 > formatted = yes
13 > color = no
14 > [extensions]
15 > pager=
16 > [pager]
17 > pager = "$PYTHON" $TESTTMP/fakepager.py
18 > EOF
19
20 $ hg init repo
21 $ cd repo
22 $ echo a >> a
23 $ hg add a
24 $ hg ci -m 'add a'
25 $ for x in `"$PYTHON" $TESTDIR/seq.py 1 10`; do
26 > echo a $x >> a
27 > hg ci -m "modify a $x"
28 > done
29
30 By default diff and log are paged, but summary is not:
31
32 $ hg diff -c 2 --pager=yes
33 paged! 'diff -r f4be7687d414 -r bce265549556 a\n'
34 paged! '--- a/a\tThu Jan 01 00:00:00 1970 +0000\n'
35 paged! '+++ b/a\tThu Jan 01 00:00:00 1970 +0000\n'
36 paged! '@@ -1,2 +1,3 @@\n'
37 paged! ' a\n'
38 paged! ' a 1\n'
39 paged! '+a 2\n'
40
41 $ hg log --limit 2
42 paged! 'changeset: 10:46106edeeb38\n'
43 paged! 'tag: tip\n'
44 paged! 'user: test\n'
45 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
46 paged! 'summary: modify a 10\n'
47 paged! '\n'
48 paged! 'changeset: 9:6dd8ea7dd621\n'
49 paged! 'user: test\n'
50 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
51 paged! 'summary: modify a 9\n'
52 paged! '\n'
53
54 $ hg summary
55 parent: 10:46106edeeb38 tip
56 modify a 10
57 branch: default
58 commit: (clean)
59 update: (current)
60 phases: 11 draft
61
62 We can enable the pager on summary:
63
64 $ hg --config pager.attend-summary=yes summary
65 paged! 'parent: 10:46106edeeb38 tip\n'
66 paged! ' modify a 10\n'
67 paged! 'branch: default\n'
68 paged! 'commit: (clean)\n'
69 paged! 'update: (current)\n'
70 paged! 'phases: 11 draft\n'
71
72 $ hg --config pager.attend-diff=no diff -c 2
73 diff -r f4be7687d414 -r bce265549556 a
74 --- a/a Thu Jan 01 00:00:00 1970 +0000
75 +++ b/a Thu Jan 01 00:00:00 1970 +0000
76 @@ -1,2 +1,3 @@
77 a
78 a 1
79 +a 2
80
81 If we completely change the attend list that's respected:
82 $ hg --config pager.attend=summary diff -c 2
83 diff -r f4be7687d414 -r bce265549556 a
84 --- a/a Thu Jan 01 00:00:00 1970 +0000
85 +++ b/a Thu Jan 01 00:00:00 1970 +0000
86 @@ -1,2 +1,3 @@
87 a
88 a 1
89 +a 2
90
91 If 'log' is in attend, then 'history' should also be paged:
92 $ hg history --limit 2 --config pager.attend=log
93 paged! 'changeset: 10:46106edeeb38\n'
94 paged! 'tag: tip\n'
95 paged! 'user: test\n'
96 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
97 paged! 'summary: modify a 10\n'
98 paged! '\n'
99 paged! 'changeset: 9:6dd8ea7dd621\n'
100 paged! 'user: test\n'
101 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
102 paged! 'summary: modify a 9\n'
103 paged! '\n'
104
105 Possible bug: history is explicitly ignored in pager config, but
106 because log is in the attend list it still gets pager treatment.
107
108 $ hg history --limit 2 --config pager.attend=log \
109 > --config pager.ignore=history
110 paged! 'changeset: 10:46106edeeb38\n'
111 paged! 'tag: tip\n'
112 paged! 'user: test\n'
113 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
114 paged! 'summary: modify a 10\n'
115 paged! '\n'
116 paged! 'changeset: 9:6dd8ea7dd621\n'
117 paged! 'user: test\n'
118 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
119 paged! 'summary: modify a 9\n'
120 paged! '\n'
121
122 Possible bug: history is explicitly marked as attend-history=no, but
123 it doesn't fail to get paged because log is still in the attend list.
124
125 $ hg history --limit 2 --config pager.attend-history=no
126 paged! 'changeset: 10:46106edeeb38\n'
127 paged! 'tag: tip\n'
128 paged! 'user: test\n'
129 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
130 paged! 'summary: modify a 10\n'
131 paged! '\n'
132 paged! 'changeset: 9:6dd8ea7dd621\n'
133 paged! 'user: test\n'
134 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
135 paged! 'summary: modify a 9\n'
136 paged! '\n'
137
138 Possible bug: disabling pager for log but enabling it for history
139 doesn't result in history being paged.
140
141 $ hg history --limit 2 --config pager.attend-log=no \
142 > --config pager.attend-history=yes
143 changeset: 10:46106edeeb38
144 tag: tip
145 user: test
146 date: Thu Jan 01 00:00:00 1970 +0000
147 summary: modify a 10
148
149 changeset: 9:6dd8ea7dd621
150 user: test
151 date: Thu Jan 01 00:00:00 1970 +0000
152 summary: modify a 9
153
154 Pager should not start if stdout is not a tty.
155
156 $ hg log -l1 -q --config ui.formatted=False
157 10:46106edeeb38
158
159 Pager with color enabled allows colors to come through by default,
160 even though stdout is no longer a tty.
161 $ cat >> $HGRCPATH <<EOF
162 > [ui]
163 > color = always
164 > [color]
165 > mode = ansi
166 > EOF
167 $ hg log --limit 3
168 paged! '\x1b[0;33mchangeset: 10:46106edeeb38\x1b[0m\n'
169 paged! 'tag: tip\n'
170 paged! 'user: test\n'
171 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
172 paged! 'summary: modify a 10\n'
173 paged! '\n'
174 paged! '\x1b[0;33mchangeset: 9:6dd8ea7dd621\x1b[0m\n'
175 paged! 'user: test\n'
176 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
177 paged! 'summary: modify a 9\n'
178 paged! '\n'
179 paged! '\x1b[0;33mchangeset: 8:cff05a6312fe\x1b[0m\n'
180 paged! 'user: test\n'
181 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
182 paged! 'summary: modify a 8\n'
183 paged! '\n'
184
185 Pager works with shell aliases.
186
187 $ cat >> $HGRCPATH <<EOF
188 > [alias]
189 > echoa = !echo a
190 > EOF
191
192 $ hg echoa
193 a
194 $ hg --config pager.attend-echoa=yes echoa
195 paged! 'a\n'
196
197 Pager attributes should be copied to mq repo. Otherwise pager would be started
198 twice and color mode would be lost.
199
200 $ cat >> $HGRCPATH <<EOF
201 > [extensions]
202 > mq =
203 > EOF
204 $ hg init --mq
205 $ hg qnew foo.patch
206 $ hg qpop
207 popping foo.patch
208 patch queue now empty
209 $ hg ci --mq -m 'commit patches'
210 $ hg log --mq --debug
211 starting pager for command 'extension-via-attend-log'
212 paged! '\x1b[0;33mchangeset: 0:6cc2ded15503e368aaf76b6cc3d12f320c9e3b87\x1b[0m\n'
213 paged! 'tag: tip\n'
214 paged! 'phase: draft\n'
215 paged! 'parent: -1:0000000000000000000000000000000000000000\n'
216 paged! 'parent: -1:0000000000000000000000000000000000000000\n'
217 paged! 'manifest: 0:4980de1ae1b612014d5bcfa9507da84ce8891daa\n'
218 paged! 'user: test\n'
219 paged! 'date: Thu Jan 01 00:00:00 1970 +0000\n'
220 paged! 'files+: .hgignore foo.patch series\n'
221 paged! 'extra: branch=default\n'
222 paged! 'description:\n'
223 paged! 'commit patches\n'
224 paged! '\n'
225 paged! '\n'
226
227 Pager works with hg aliases including environment variables.
228
229 $ cat >> $HGRCPATH <<'EOF'
230 > [alias]
231 > printa = log -T "$A\n" -r 0
232 > EOF
233
234 $ A=1 hg --config pager.attend-printa=yes printa
235 paged! '1\n'
236 $ A=2 hg --config pager.attend-printa=yes printa
237 paged! '2\n'
238
239 Something that's explicitly attended is still not paginated if the
240 pager is globally set to off using a flag:
241 $ A=2 hg --config pager.attend-printa=yes printa --pager=no
242 2
243
244 Pager should not override the exit code of other commands
245
246 $ cat >> $TESTTMP/fortytwo.py <<'EOF'
247 > from mercurial import commands, registrar
248 > cmdtable = {}
249 > command = registrar.command(cmdtable)
250 > @command(b'fortytwo', [], b'fortytwo', norepo=True)
251 > def fortytwo(ui, *opts):
252 > ui.write(b'42\n')
253 > return 42
254 > EOF
255
256 $ cat >> $HGRCPATH <<'EOF'
257 > [extensions]
258 > fortytwo = $TESTTMP/fortytwo.py
259 > EOF
260
261 $ hg fortytwo --pager=on
262 paged! '42\n'
263 [42]