##// END OF EJS Templates
tests: conditionalize test-commandserver.t based on extra extensions...
Gregory Szorc -
r37445:6282c196 default
parent child Browse files
Show More
@@ -1,1027 +1,1030 b''
1 #if windows
1 #if windows
2 $ PYTHONPATH="$TESTDIR/../contrib;$PYTHONPATH"
2 $ PYTHONPATH="$TESTDIR/../contrib;$PYTHONPATH"
3 #else
3 #else
4 $ PYTHONPATH="$TESTDIR/../contrib:$PYTHONPATH"
4 $ PYTHONPATH="$TESTDIR/../contrib:$PYTHONPATH"
5 #endif
5 #endif
6 $ export PYTHONPATH
6 $ export PYTHONPATH
7
7
8 typical client does not want echo-back messages, so test without it:
8 typical client does not want echo-back messages, so test without it:
9
9
10 $ grep -v '^promptecho ' < $HGRCPATH >> $HGRCPATH.new
10 $ grep -v '^promptecho ' < $HGRCPATH >> $HGRCPATH.new
11 $ mv $HGRCPATH.new $HGRCPATH
11 $ mv $HGRCPATH.new $HGRCPATH
12
12
13 $ hg init repo
13 $ hg init repo
14 $ cd repo
14 $ cd repo
15
15
16 >>> from __future__ import absolute_import, print_function
16 >>> from __future__ import absolute_import, print_function
17 >>> import os
17 >>> import os
18 >>> import sys
18 >>> import sys
19 >>> from hgclient import check, readchannel, runcommand
19 >>> from hgclient import check, readchannel, runcommand
20 >>> @check
20 >>> @check
21 ... def hellomessage(server):
21 ... def hellomessage(server):
22 ... ch, data = readchannel(server)
22 ... ch, data = readchannel(server)
23 ... print('%c, %r' % (ch, data))
23 ... print('%c, %r' % (ch, data))
24 ... # run an arbitrary command to make sure the next thing the server
24 ... # run an arbitrary command to make sure the next thing the server
25 ... # sends isn't part of the hello message
25 ... # sends isn't part of the hello message
26 ... runcommand(server, ['id'])
26 ... runcommand(server, ['id'])
27 o, 'capabilities: getencoding runcommand\nencoding: *\npid: *' (glob)
27 o, 'capabilities: getencoding runcommand\nencoding: *\npid: *' (glob)
28 *** runcommand id
28 *** runcommand id
29 000000000000 tip
29 000000000000 tip
30
30
31 >>> from hgclient import check
31 >>> from hgclient import check
32 >>> @check
32 >>> @check
33 ... def unknowncommand(server):
33 ... def unknowncommand(server):
34 ... server.stdin.write('unknowncommand\n')
34 ... server.stdin.write('unknowncommand\n')
35 abort: unknown command unknowncommand
35 abort: unknown command unknowncommand
36
36
37 >>> from hgclient import check, readchannel, runcommand
37 >>> from hgclient import check, readchannel, runcommand
38 >>> @check
38 >>> @check
39 ... def checkruncommand(server):
39 ... def checkruncommand(server):
40 ... # hello block
40 ... # hello block
41 ... readchannel(server)
41 ... readchannel(server)
42 ...
42 ...
43 ... # no args
43 ... # no args
44 ... runcommand(server, [])
44 ... runcommand(server, [])
45 ...
45 ...
46 ... # global options
46 ... # global options
47 ... runcommand(server, ['id', '--quiet'])
47 ... runcommand(server, ['id', '--quiet'])
48 ...
48 ...
49 ... # make sure global options don't stick through requests
49 ... # make sure global options don't stick through requests
50 ... runcommand(server, ['id'])
50 ... runcommand(server, ['id'])
51 ...
51 ...
52 ... # --config
52 ... # --config
53 ... runcommand(server, ['id', '--config', 'ui.quiet=True'])
53 ... runcommand(server, ['id', '--config', 'ui.quiet=True'])
54 ...
54 ...
55 ... # make sure --config doesn't stick
55 ... # make sure --config doesn't stick
56 ... runcommand(server, ['id'])
56 ... runcommand(server, ['id'])
57 ...
57 ...
58 ... # negative return code should be masked
58 ... # negative return code should be masked
59 ... runcommand(server, ['id', '-runknown'])
59 ... runcommand(server, ['id', '-runknown'])
60 *** runcommand
60 *** runcommand
61 Mercurial Distributed SCM
61 Mercurial Distributed SCM
62
62
63 basic commands:
63 basic commands:
64
64
65 add add the specified files on the next commit
65 add add the specified files on the next commit
66 annotate show changeset information by line for each file
66 annotate show changeset information by line for each file
67 clone make a copy of an existing repository
67 clone make a copy of an existing repository
68 commit commit the specified files or all outstanding changes
68 commit commit the specified files or all outstanding changes
69 diff diff repository (or selected files)
69 diff diff repository (or selected files)
70 export dump the header and diffs for one or more changesets
70 export dump the header and diffs for one or more changesets
71 forget forget the specified files on the next commit
71 forget forget the specified files on the next commit
72 init create a new repository in the given directory
72 init create a new repository in the given directory
73 log show revision history of entire repository or files
73 log show revision history of entire repository or files
74 merge merge another revision into working directory
74 merge merge another revision into working directory
75 pull pull changes from the specified source
75 pull pull changes from the specified source
76 push push changes to the specified destination
76 push push changes to the specified destination
77 remove remove the specified files on the next commit
77 remove remove the specified files on the next commit
78 serve start stand-alone webserver
78 serve start stand-alone webserver
79 status show changed files in the working directory
79 status show changed files in the working directory
80 summary summarize working directory state
80 summary summarize working directory state
81 update update working directory (or switch revisions)
81 update update working directory (or switch revisions)
82
82
83 (use 'hg help' for the full list of commands or 'hg -v' for details)
83 (use 'hg help' for the full list of commands or 'hg -v' for details)
84 *** runcommand id --quiet
84 *** runcommand id --quiet
85 000000000000
85 000000000000
86 *** runcommand id
86 *** runcommand id
87 000000000000 tip
87 000000000000 tip
88 *** runcommand id --config ui.quiet=True
88 *** runcommand id --config ui.quiet=True
89 000000000000
89 000000000000
90 *** runcommand id
90 *** runcommand id
91 000000000000 tip
91 000000000000 tip
92 *** runcommand id -runknown
92 *** runcommand id -runknown
93 abort: unknown revision 'unknown'!
93 abort: unknown revision 'unknown'!
94 [255]
94 [255]
95
95
96 >>> from hgclient import check, readchannel
96 >>> from hgclient import check, readchannel
97 >>> @check
97 >>> @check
98 ... def inputeof(server):
98 ... def inputeof(server):
99 ... readchannel(server)
99 ... readchannel(server)
100 ... server.stdin.write('runcommand\n')
100 ... server.stdin.write('runcommand\n')
101 ... # close stdin while server is waiting for input
101 ... # close stdin while server is waiting for input
102 ... server.stdin.close()
102 ... server.stdin.close()
103 ...
103 ...
104 ... # server exits with 1 if the pipe closed while reading the command
104 ... # server exits with 1 if the pipe closed while reading the command
105 ... print('server exit code =', server.wait())
105 ... print('server exit code =', server.wait())
106 server exit code = 1
106 server exit code = 1
107
107
108 >>> from hgclient import check, readchannel, runcommand, stringio
108 >>> from hgclient import check, readchannel, runcommand, stringio
109 >>> @check
109 >>> @check
110 ... def serverinput(server):
110 ... def serverinput(server):
111 ... readchannel(server)
111 ... readchannel(server)
112 ...
112 ...
113 ... patch = """
113 ... patch = """
114 ... # HG changeset patch
114 ... # HG changeset patch
115 ... # User test
115 ... # User test
116 ... # Date 0 0
116 ... # Date 0 0
117 ... # Node ID c103a3dec114d882c98382d684d8af798d09d857
117 ... # Node ID c103a3dec114d882c98382d684d8af798d09d857
118 ... # Parent 0000000000000000000000000000000000000000
118 ... # Parent 0000000000000000000000000000000000000000
119 ... 1
119 ... 1
120 ...
120 ...
121 ... diff -r 000000000000 -r c103a3dec114 a
121 ... diff -r 000000000000 -r c103a3dec114 a
122 ... --- /dev/null Thu Jan 01 00:00:00 1970 +0000
122 ... --- /dev/null Thu Jan 01 00:00:00 1970 +0000
123 ... +++ b/a Thu Jan 01 00:00:00 1970 +0000
123 ... +++ b/a Thu Jan 01 00:00:00 1970 +0000
124 ... @@ -0,0 +1,1 @@
124 ... @@ -0,0 +1,1 @@
125 ... +1
125 ... +1
126 ... """
126 ... """
127 ...
127 ...
128 ... runcommand(server, ['import', '-'], input=stringio(patch))
128 ... runcommand(server, ['import', '-'], input=stringio(patch))
129 ... runcommand(server, ['log'])
129 ... runcommand(server, ['log'])
130 *** runcommand import -
130 *** runcommand import -
131 applying patch from stdin
131 applying patch from stdin
132 *** runcommand log
132 *** runcommand log
133 changeset: 0:eff892de26ec
133 changeset: 0:eff892de26ec
134 tag: tip
134 tag: tip
135 user: test
135 user: test
136 date: Thu Jan 01 00:00:00 1970 +0000
136 date: Thu Jan 01 00:00:00 1970 +0000
137 summary: 1
137 summary: 1
138
138
139
139
140 check strict parsing of early options:
140 check strict parsing of early options:
141
141
142 >>> import os
142 >>> import os
143 >>> from hgclient import check, readchannel, runcommand
143 >>> from hgclient import check, readchannel, runcommand
144 >>> os.environ['HGPLAIN'] = '+strictflags'
144 >>> os.environ['HGPLAIN'] = '+strictflags'
145 >>> @check
145 >>> @check
146 ... def cwd(server):
146 ... def cwd(server):
147 ... readchannel(server)
147 ... readchannel(server)
148 ... runcommand(server, ['log', '-b', '--config=alias.log=!echo pwned',
148 ... runcommand(server, ['log', '-b', '--config=alias.log=!echo pwned',
149 ... 'default'])
149 ... 'default'])
150 *** runcommand log -b --config=alias.log=!echo pwned default
150 *** runcommand log -b --config=alias.log=!echo pwned default
151 abort: unknown revision '--config=alias.log=!echo pwned'!
151 abort: unknown revision '--config=alias.log=!echo pwned'!
152 [255]
152 [255]
153
153
154 check that "histedit --commands=-" can read rules from the input channel:
154 check that "histedit --commands=-" can read rules from the input channel:
155
155
156 >>> import cStringIO
156 >>> import cStringIO
157 >>> from hgclient import check, readchannel, runcommand
157 >>> from hgclient import check, readchannel, runcommand
158 >>> @check
158 >>> @check
159 ... def serverinput(server):
159 ... def serverinput(server):
160 ... readchannel(server)
160 ... readchannel(server)
161 ... rules = 'pick eff892de26ec\n'
161 ... rules = 'pick eff892de26ec\n'
162 ... runcommand(server, ['histedit', '0', '--commands=-',
162 ... runcommand(server, ['histedit', '0', '--commands=-',
163 ... '--config', 'extensions.histedit='],
163 ... '--config', 'extensions.histedit='],
164 ... input=cStringIO.StringIO(rules))
164 ... input=cStringIO.StringIO(rules))
165 *** runcommand histedit 0 --commands=- --config extensions.histedit=
165 *** runcommand histedit 0 --commands=- --config extensions.histedit=
166
166
167 check that --cwd doesn't persist between requests:
167 check that --cwd doesn't persist between requests:
168
168
169 $ mkdir foo
169 $ mkdir foo
170 $ touch foo/bar
170 $ touch foo/bar
171 >>> from hgclient import check, readchannel, runcommand
171 >>> from hgclient import check, readchannel, runcommand
172 >>> @check
172 >>> @check
173 ... def cwd(server):
173 ... def cwd(server):
174 ... readchannel(server)
174 ... readchannel(server)
175 ... runcommand(server, ['--cwd', 'foo', 'st', 'bar'])
175 ... runcommand(server, ['--cwd', 'foo', 'st', 'bar'])
176 ... runcommand(server, ['st', 'foo/bar'])
176 ... runcommand(server, ['st', 'foo/bar'])
177 *** runcommand --cwd foo st bar
177 *** runcommand --cwd foo st bar
178 ? bar
178 ? bar
179 *** runcommand st foo/bar
179 *** runcommand st foo/bar
180 ? foo/bar
180 ? foo/bar
181
181
182 $ rm foo/bar
182 $ rm foo/bar
183
183
184
184
185 check that local configs for the cached repo aren't inherited when -R is used:
185 check that local configs for the cached repo aren't inherited when -R is used:
186
186
187 $ cat <<EOF >> .hg/hgrc
187 $ cat <<EOF >> .hg/hgrc
188 > [ui]
188 > [ui]
189 > foo = bar
189 > foo = bar
190 > EOF
190 > EOF
191
191
192 #if no-extraextensions
193
192 >>> from hgclient import check, readchannel, runcommand, sep
194 >>> from hgclient import check, readchannel, runcommand, sep
193 >>> @check
195 >>> @check
194 ... def localhgrc(server):
196 ... def localhgrc(server):
195 ... readchannel(server)
197 ... readchannel(server)
196 ...
198 ...
197 ... # the cached repo local hgrc contains ui.foo=bar, so showconfig should
199 ... # the cached repo local hgrc contains ui.foo=bar, so showconfig should
198 ... # show it
200 ... # show it
199 ... runcommand(server, ['showconfig'], outfilter=sep)
201 ... runcommand(server, ['showconfig'], outfilter=sep)
200 ...
202 ...
201 ... # but not for this repo
203 ... # but not for this repo
202 ... runcommand(server, ['init', 'foo'])
204 ... runcommand(server, ['init', 'foo'])
203 ... runcommand(server, ['-R', 'foo', 'showconfig', 'ui', 'defaults'])
205 ... runcommand(server, ['-R', 'foo', 'showconfig', 'ui', 'defaults'])
204 *** runcommand showconfig
206 *** runcommand showconfig
205 bundle.mainreporoot=$TESTTMP/repo
207 bundle.mainreporoot=$TESTTMP/repo
206 devel.all-warnings=true
208 devel.all-warnings=true
207 devel.default-date=0 0
209 devel.default-date=0 0
208 extensions.fsmonitor= (fsmonitor !)
210 extensions.fsmonitor= (fsmonitor !)
209 largefiles.usercache=$TESTTMP/.cache/largefiles
211 largefiles.usercache=$TESTTMP/.cache/largefiles
210 lfs.usercache=$TESTTMP/.cache/lfs
212 lfs.usercache=$TESTTMP/.cache/lfs
211 ui.slash=True
213 ui.slash=True
212 ui.interactive=False
214 ui.interactive=False
213 ui.mergemarkers=detailed
215 ui.mergemarkers=detailed
214 ui.foo=bar
216 ui.foo=bar
215 ui.nontty=true
217 ui.nontty=true
216 web.address=localhost
218 web.address=localhost
217 web\.ipv6=(?:True|False) (re)
219 web\.ipv6=(?:True|False) (re)
218 web.server-header=testing stub value
220 web.server-header=testing stub value
219 *** runcommand init foo
221 *** runcommand init foo
220 *** runcommand -R foo showconfig ui defaults
222 *** runcommand -R foo showconfig ui defaults
221 ui.slash=True
223 ui.slash=True
222 ui.interactive=False
224 ui.interactive=False
223 ui.mergemarkers=detailed
225 ui.mergemarkers=detailed
224 ui.nontty=true
226 ui.nontty=true
227 #endif
225
228
226 $ rm -R foo
229 $ rm -R foo
227
230
228 #if windows
231 #if windows
229 $ PYTHONPATH="$TESTTMP/repo;$PYTHONPATH"
232 $ PYTHONPATH="$TESTTMP/repo;$PYTHONPATH"
230 #else
233 #else
231 $ PYTHONPATH="$TESTTMP/repo:$PYTHONPATH"
234 $ PYTHONPATH="$TESTTMP/repo:$PYTHONPATH"
232 #endif
235 #endif
233
236
234 $ cat <<EOF > hook.py
237 $ cat <<EOF > hook.py
235 > from __future__ import print_function
238 > from __future__ import print_function
236 > import sys
239 > import sys
237 > def hook(**args):
240 > def hook(**args):
238 > print('hook talking')
241 > print('hook talking')
239 > print('now try to read something: %r' % sys.stdin.read())
242 > print('now try to read something: %r' % sys.stdin.read())
240 > EOF
243 > EOF
241
244
242 >>> from hgclient import check, readchannel, runcommand, stringio
245 >>> from hgclient import check, readchannel, runcommand, stringio
243 >>> @check
246 >>> @check
244 ... def hookoutput(server):
247 ... def hookoutput(server):
245 ... readchannel(server)
248 ... readchannel(server)
246 ... runcommand(server, ['--config',
249 ... runcommand(server, ['--config',
247 ... 'hooks.pre-identify=python:hook.hook',
250 ... 'hooks.pre-identify=python:hook.hook',
248 ... 'id'],
251 ... 'id'],
249 ... input=stringio('some input'))
252 ... input=stringio('some input'))
250 *** runcommand --config hooks.pre-identify=python:hook.hook id
253 *** runcommand --config hooks.pre-identify=python:hook.hook id
251 eff892de26ec tip
254 eff892de26ec tip
252 hook talking
255 hook talking
253 now try to read something: ''
256 now try to read something: ''
254
257
255 Clean hook cached version
258 Clean hook cached version
256 $ rm hook.py*
259 $ rm hook.py*
257 $ rm -Rf __pycache__
260 $ rm -Rf __pycache__
258
261
259 $ echo a >> a
262 $ echo a >> a
260 >>> import os
263 >>> import os
261 >>> from hgclient import check, readchannel, runcommand
264 >>> from hgclient import check, readchannel, runcommand
262 >>> @check
265 >>> @check
263 ... def outsidechanges(server):
266 ... def outsidechanges(server):
264 ... readchannel(server)
267 ... readchannel(server)
265 ... runcommand(server, ['status'])
268 ... runcommand(server, ['status'])
266 ... os.system('hg ci -Am2')
269 ... os.system('hg ci -Am2')
267 ... runcommand(server, ['tip'])
270 ... runcommand(server, ['tip'])
268 ... runcommand(server, ['status'])
271 ... runcommand(server, ['status'])
269 *** runcommand status
272 *** runcommand status
270 M a
273 M a
271 *** runcommand tip
274 *** runcommand tip
272 changeset: 1:d3a0a68be6de
275 changeset: 1:d3a0a68be6de
273 tag: tip
276 tag: tip
274 user: test
277 user: test
275 date: Thu Jan 01 00:00:00 1970 +0000
278 date: Thu Jan 01 00:00:00 1970 +0000
276 summary: 2
279 summary: 2
277
280
278 *** runcommand status
281 *** runcommand status
279
282
280 >>> import os
283 >>> import os
281 >>> from hgclient import check, readchannel, runcommand
284 >>> from hgclient import check, readchannel, runcommand
282 >>> @check
285 >>> @check
283 ... def bookmarks(server):
286 ... def bookmarks(server):
284 ... readchannel(server)
287 ... readchannel(server)
285 ... runcommand(server, ['bookmarks'])
288 ... runcommand(server, ['bookmarks'])
286 ...
289 ...
287 ... # changes .hg/bookmarks
290 ... # changes .hg/bookmarks
288 ... os.system('hg bookmark -i bm1')
291 ... os.system('hg bookmark -i bm1')
289 ... os.system('hg bookmark -i bm2')
292 ... os.system('hg bookmark -i bm2')
290 ... runcommand(server, ['bookmarks'])
293 ... runcommand(server, ['bookmarks'])
291 ...
294 ...
292 ... # changes .hg/bookmarks.current
295 ... # changes .hg/bookmarks.current
293 ... os.system('hg upd bm1 -q')
296 ... os.system('hg upd bm1 -q')
294 ... runcommand(server, ['bookmarks'])
297 ... runcommand(server, ['bookmarks'])
295 ...
298 ...
296 ... runcommand(server, ['bookmarks', 'bm3'])
299 ... runcommand(server, ['bookmarks', 'bm3'])
297 ... f = open('a', 'ab')
300 ... f = open('a', 'ab')
298 ... f.write('a\n')
301 ... f.write('a\n')
299 ... f.close()
302 ... f.close()
300 ... runcommand(server, ['commit', '-Amm'])
303 ... runcommand(server, ['commit', '-Amm'])
301 ... runcommand(server, ['bookmarks'])
304 ... runcommand(server, ['bookmarks'])
302 ... print('')
305 ... print('')
303 *** runcommand bookmarks
306 *** runcommand bookmarks
304 no bookmarks set
307 no bookmarks set
305 *** runcommand bookmarks
308 *** runcommand bookmarks
306 bm1 1:d3a0a68be6de
309 bm1 1:d3a0a68be6de
307 bm2 1:d3a0a68be6de
310 bm2 1:d3a0a68be6de
308 *** runcommand bookmarks
311 *** runcommand bookmarks
309 * bm1 1:d3a0a68be6de
312 * bm1 1:d3a0a68be6de
310 bm2 1:d3a0a68be6de
313 bm2 1:d3a0a68be6de
311 *** runcommand bookmarks bm3
314 *** runcommand bookmarks bm3
312 *** runcommand commit -Amm
315 *** runcommand commit -Amm
313 *** runcommand bookmarks
316 *** runcommand bookmarks
314 bm1 1:d3a0a68be6de
317 bm1 1:d3a0a68be6de
315 bm2 1:d3a0a68be6de
318 bm2 1:d3a0a68be6de
316 * bm3 2:aef17e88f5f0
319 * bm3 2:aef17e88f5f0
317
320
318
321
319 >>> import os
322 >>> import os
320 >>> from hgclient import check, readchannel, runcommand
323 >>> from hgclient import check, readchannel, runcommand
321 >>> @check
324 >>> @check
322 ... def tagscache(server):
325 ... def tagscache(server):
323 ... readchannel(server)
326 ... readchannel(server)
324 ... runcommand(server, ['id', '-t', '-r', '0'])
327 ... runcommand(server, ['id', '-t', '-r', '0'])
325 ... os.system('hg tag -r 0 foo')
328 ... os.system('hg tag -r 0 foo')
326 ... runcommand(server, ['id', '-t', '-r', '0'])
329 ... runcommand(server, ['id', '-t', '-r', '0'])
327 *** runcommand id -t -r 0
330 *** runcommand id -t -r 0
328
331
329 *** runcommand id -t -r 0
332 *** runcommand id -t -r 0
330 foo
333 foo
331
334
332 >>> import os
335 >>> import os
333 >>> from hgclient import check, readchannel, runcommand
336 >>> from hgclient import check, readchannel, runcommand
334 >>> @check
337 >>> @check
335 ... def setphase(server):
338 ... def setphase(server):
336 ... readchannel(server)
339 ... readchannel(server)
337 ... runcommand(server, ['phase', '-r', '.'])
340 ... runcommand(server, ['phase', '-r', '.'])
338 ... os.system('hg phase -r . -p')
341 ... os.system('hg phase -r . -p')
339 ... runcommand(server, ['phase', '-r', '.'])
342 ... runcommand(server, ['phase', '-r', '.'])
340 *** runcommand phase -r .
343 *** runcommand phase -r .
341 3: draft
344 3: draft
342 *** runcommand phase -r .
345 *** runcommand phase -r .
343 3: public
346 3: public
344
347
345 $ echo a >> a
348 $ echo a >> a
346 >>> from hgclient import check, readchannel, runcommand
349 >>> from hgclient import check, readchannel, runcommand
347 >>> @check
350 >>> @check
348 ... def rollback(server):
351 ... def rollback(server):
349 ... readchannel(server)
352 ... readchannel(server)
350 ... runcommand(server, ['phase', '-r', '.', '-p'])
353 ... runcommand(server, ['phase', '-r', '.', '-p'])
351 ... runcommand(server, ['commit', '-Am.'])
354 ... runcommand(server, ['commit', '-Am.'])
352 ... runcommand(server, ['rollback'])
355 ... runcommand(server, ['rollback'])
353 ... runcommand(server, ['phase', '-r', '.'])
356 ... runcommand(server, ['phase', '-r', '.'])
354 ... print('')
357 ... print('')
355 *** runcommand phase -r . -p
358 *** runcommand phase -r . -p
356 no phases changed
359 no phases changed
357 *** runcommand commit -Am.
360 *** runcommand commit -Am.
358 *** runcommand rollback
361 *** runcommand rollback
359 repository tip rolled back to revision 3 (undo commit)
362 repository tip rolled back to revision 3 (undo commit)
360 working directory now based on revision 3
363 working directory now based on revision 3
361 *** runcommand phase -r .
364 *** runcommand phase -r .
362 3: public
365 3: public
363
366
364
367
365 >>> import os
368 >>> import os
366 >>> from hgclient import check, readchannel, runcommand
369 >>> from hgclient import check, readchannel, runcommand
367 >>> @check
370 >>> @check
368 ... def branch(server):
371 ... def branch(server):
369 ... readchannel(server)
372 ... readchannel(server)
370 ... runcommand(server, ['branch'])
373 ... runcommand(server, ['branch'])
371 ... os.system('hg branch foo')
374 ... os.system('hg branch foo')
372 ... runcommand(server, ['branch'])
375 ... runcommand(server, ['branch'])
373 ... os.system('hg branch default')
376 ... os.system('hg branch default')
374 *** runcommand branch
377 *** runcommand branch
375 default
378 default
376 marked working directory as branch foo
379 marked working directory as branch foo
377 (branches are permanent and global, did you want a bookmark?)
380 (branches are permanent and global, did you want a bookmark?)
378 *** runcommand branch
381 *** runcommand branch
379 foo
382 foo
380 marked working directory as branch default
383 marked working directory as branch default
381 (branches are permanent and global, did you want a bookmark?)
384 (branches are permanent and global, did you want a bookmark?)
382
385
383 $ touch .hgignore
386 $ touch .hgignore
384 >>> import os
387 >>> import os
385 >>> from hgclient import check, readchannel, runcommand
388 >>> from hgclient import check, readchannel, runcommand
386 >>> @check
389 >>> @check
387 ... def hgignore(server):
390 ... def hgignore(server):
388 ... readchannel(server)
391 ... readchannel(server)
389 ... runcommand(server, ['commit', '-Am.'])
392 ... runcommand(server, ['commit', '-Am.'])
390 ... f = open('ignored-file', 'ab')
393 ... f = open('ignored-file', 'ab')
391 ... f.write('')
394 ... f.write('')
392 ... f.close()
395 ... f.close()
393 ... f = open('.hgignore', 'ab')
396 ... f = open('.hgignore', 'ab')
394 ... f.write('ignored-file')
397 ... f.write('ignored-file')
395 ... f.close()
398 ... f.close()
396 ... runcommand(server, ['status', '-i', '-u'])
399 ... runcommand(server, ['status', '-i', '-u'])
397 ... print('')
400 ... print('')
398 *** runcommand commit -Am.
401 *** runcommand commit -Am.
399 adding .hgignore
402 adding .hgignore
400 *** runcommand status -i -u
403 *** runcommand status -i -u
401 I ignored-file
404 I ignored-file
402
405
403
406
404 cache of non-public revisions should be invalidated on repository change
407 cache of non-public revisions should be invalidated on repository change
405 (issue4855):
408 (issue4855):
406
409
407 >>> import os
410 >>> import os
408 >>> from hgclient import check, readchannel, runcommand
411 >>> from hgclient import check, readchannel, runcommand
409 >>> @check
412 >>> @check
410 ... def phasesetscacheaftercommit(server):
413 ... def phasesetscacheaftercommit(server):
411 ... readchannel(server)
414 ... readchannel(server)
412 ... # load _phasecache._phaserevs and _phasesets
415 ... # load _phasecache._phaserevs and _phasesets
413 ... runcommand(server, ['log', '-qr', 'draft()'])
416 ... runcommand(server, ['log', '-qr', 'draft()'])
414 ... # create draft commits by another process
417 ... # create draft commits by another process
415 ... for i in range(5, 7):
418 ... for i in range(5, 7):
416 ... f = open('a', 'ab')
419 ... f = open('a', 'ab')
417 ... f.seek(0, os.SEEK_END)
420 ... f.seek(0, os.SEEK_END)
418 ... f.write('a\n')
421 ... f.write('a\n')
419 ... f.close()
422 ... f.close()
420 ... os.system('hg commit -Aqm%d' % i)
423 ... os.system('hg commit -Aqm%d' % i)
421 ... # new commits should be listed as draft revisions
424 ... # new commits should be listed as draft revisions
422 ... runcommand(server, ['log', '-qr', 'draft()'])
425 ... runcommand(server, ['log', '-qr', 'draft()'])
423 ... print('')
426 ... print('')
424 *** runcommand log -qr draft()
427 *** runcommand log -qr draft()
425 4:7966c8e3734d
428 4:7966c8e3734d
426 *** runcommand log -qr draft()
429 *** runcommand log -qr draft()
427 4:7966c8e3734d
430 4:7966c8e3734d
428 5:41f6602d1c4f
431 5:41f6602d1c4f
429 6:10501e202c35
432 6:10501e202c35
430
433
431
434
432 >>> import os
435 >>> import os
433 >>> from hgclient import check, readchannel, runcommand
436 >>> from hgclient import check, readchannel, runcommand
434 >>> @check
437 >>> @check
435 ... def phasesetscacheafterstrip(server):
438 ... def phasesetscacheafterstrip(server):
436 ... readchannel(server)
439 ... readchannel(server)
437 ... # load _phasecache._phaserevs and _phasesets
440 ... # load _phasecache._phaserevs and _phasesets
438 ... runcommand(server, ['log', '-qr', 'draft()'])
441 ... runcommand(server, ['log', '-qr', 'draft()'])
439 ... # strip cached revisions by another process
442 ... # strip cached revisions by another process
440 ... os.system('hg --config extensions.strip= strip -q 5')
443 ... os.system('hg --config extensions.strip= strip -q 5')
441 ... # shouldn't abort by "unknown revision '6'"
444 ... # shouldn't abort by "unknown revision '6'"
442 ... runcommand(server, ['log', '-qr', 'draft()'])
445 ... runcommand(server, ['log', '-qr', 'draft()'])
443 ... print('')
446 ... print('')
444 *** runcommand log -qr draft()
447 *** runcommand log -qr draft()
445 4:7966c8e3734d
448 4:7966c8e3734d
446 5:41f6602d1c4f
449 5:41f6602d1c4f
447 6:10501e202c35
450 6:10501e202c35
448 *** runcommand log -qr draft()
451 *** runcommand log -qr draft()
449 4:7966c8e3734d
452 4:7966c8e3734d
450
453
451
454
452 cache of phase roots should be invalidated on strip (issue3827):
455 cache of phase roots should be invalidated on strip (issue3827):
453
456
454 >>> import os
457 >>> import os
455 >>> from hgclient import check, readchannel, runcommand, sep
458 >>> from hgclient import check, readchannel, runcommand, sep
456 >>> @check
459 >>> @check
457 ... def phasecacheafterstrip(server):
460 ... def phasecacheafterstrip(server):
458 ... readchannel(server)
461 ... readchannel(server)
459 ...
462 ...
460 ... # create new head, 5:731265503d86
463 ... # create new head, 5:731265503d86
461 ... runcommand(server, ['update', '-C', '0'])
464 ... runcommand(server, ['update', '-C', '0'])
462 ... f = open('a', 'ab')
465 ... f = open('a', 'ab')
463 ... f.write('a\n')
466 ... f.write('a\n')
464 ... f.close()
467 ... f.close()
465 ... runcommand(server, ['commit', '-Am.', 'a'])
468 ... runcommand(server, ['commit', '-Am.', 'a'])
466 ... runcommand(server, ['log', '-Gq'])
469 ... runcommand(server, ['log', '-Gq'])
467 ...
470 ...
468 ... # make it public; draft marker moves to 4:7966c8e3734d
471 ... # make it public; draft marker moves to 4:7966c8e3734d
469 ... runcommand(server, ['phase', '-p', '.'])
472 ... runcommand(server, ['phase', '-p', '.'])
470 ... # load _phasecache.phaseroots
473 ... # load _phasecache.phaseroots
471 ... runcommand(server, ['phase', '.'], outfilter=sep)
474 ... runcommand(server, ['phase', '.'], outfilter=sep)
472 ...
475 ...
473 ... # strip 1::4 outside server
476 ... # strip 1::4 outside server
474 ... os.system('hg -q --config extensions.mq= strip 1')
477 ... os.system('hg -q --config extensions.mq= strip 1')
475 ...
478 ...
476 ... # shouldn't raise "7966c8e3734d: no node!"
479 ... # shouldn't raise "7966c8e3734d: no node!"
477 ... runcommand(server, ['branches'])
480 ... runcommand(server, ['branches'])
478 *** runcommand update -C 0
481 *** runcommand update -C 0
479 1 files updated, 0 files merged, 2 files removed, 0 files unresolved
482 1 files updated, 0 files merged, 2 files removed, 0 files unresolved
480 (leaving bookmark bm3)
483 (leaving bookmark bm3)
481 *** runcommand commit -Am. a
484 *** runcommand commit -Am. a
482 created new head
485 created new head
483 *** runcommand log -Gq
486 *** runcommand log -Gq
484 @ 5:731265503d86
487 @ 5:731265503d86
485 |
488 |
486 | o 4:7966c8e3734d
489 | o 4:7966c8e3734d
487 | |
490 | |
488 | o 3:b9b85890c400
491 | o 3:b9b85890c400
489 | |
492 | |
490 | o 2:aef17e88f5f0
493 | o 2:aef17e88f5f0
491 | |
494 | |
492 | o 1:d3a0a68be6de
495 | o 1:d3a0a68be6de
493 |/
496 |/
494 o 0:eff892de26ec
497 o 0:eff892de26ec
495
498
496 *** runcommand phase -p .
499 *** runcommand phase -p .
497 *** runcommand phase .
500 *** runcommand phase .
498 5: public
501 5: public
499 *** runcommand branches
502 *** runcommand branches
500 default 1:731265503d86
503 default 1:731265503d86
501
504
502 in-memory cache must be reloaded if transaction is aborted. otherwise
505 in-memory cache must be reloaded if transaction is aborted. otherwise
503 changelog and manifest would have invalid node:
506 changelog and manifest would have invalid node:
504
507
505 $ echo a >> a
508 $ echo a >> a
506 >>> from hgclient import check, readchannel, runcommand
509 >>> from hgclient import check, readchannel, runcommand
507 >>> @check
510 >>> @check
508 ... def txabort(server):
511 ... def txabort(server):
509 ... readchannel(server)
512 ... readchannel(server)
510 ... runcommand(server, ['commit', '--config', 'hooks.pretxncommit=false',
513 ... runcommand(server, ['commit', '--config', 'hooks.pretxncommit=false',
511 ... '-mfoo'])
514 ... '-mfoo'])
512 ... runcommand(server, ['verify'])
515 ... runcommand(server, ['verify'])
513 *** runcommand commit --config hooks.pretxncommit=false -mfoo
516 *** runcommand commit --config hooks.pretxncommit=false -mfoo
514 transaction abort!
517 transaction abort!
515 rollback completed
518 rollback completed
516 abort: pretxncommit hook exited with status 1
519 abort: pretxncommit hook exited with status 1
517 [255]
520 [255]
518 *** runcommand verify
521 *** runcommand verify
519 checking changesets
522 checking changesets
520 checking manifests
523 checking manifests
521 crosschecking files in changesets and manifests
524 crosschecking files in changesets and manifests
522 checking files
525 checking files
523 1 files, 2 changesets, 2 total revisions
526 1 files, 2 changesets, 2 total revisions
524 $ hg revert --no-backup -aq
527 $ hg revert --no-backup -aq
525
528
526 $ cat >> .hg/hgrc << EOF
529 $ cat >> .hg/hgrc << EOF
527 > [experimental]
530 > [experimental]
528 > evolution.createmarkers=True
531 > evolution.createmarkers=True
529 > EOF
532 > EOF
530
533
531 >>> import os
534 >>> import os
532 >>> from hgclient import check, readchannel, runcommand
535 >>> from hgclient import check, readchannel, runcommand
533 >>> @check
536 >>> @check
534 ... def obsolete(server):
537 ... def obsolete(server):
535 ... readchannel(server)
538 ... readchannel(server)
536 ...
539 ...
537 ... runcommand(server, ['up', 'null'])
540 ... runcommand(server, ['up', 'null'])
538 ... runcommand(server, ['phase', '-df', 'tip'])
541 ... runcommand(server, ['phase', '-df', 'tip'])
539 ... cmd = 'hg debugobsolete `hg log -r tip --template {node}`'
542 ... cmd = 'hg debugobsolete `hg log -r tip --template {node}`'
540 ... if os.name == 'nt':
543 ... if os.name == 'nt':
541 ... cmd = 'sh -c "%s"' % cmd # run in sh, not cmd.exe
544 ... cmd = 'sh -c "%s"' % cmd # run in sh, not cmd.exe
542 ... os.system(cmd)
545 ... os.system(cmd)
543 ... runcommand(server, ['log', '--hidden'])
546 ... runcommand(server, ['log', '--hidden'])
544 ... runcommand(server, ['log'])
547 ... runcommand(server, ['log'])
545 *** runcommand up null
548 *** runcommand up null
546 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
549 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
547 *** runcommand phase -df tip
550 *** runcommand phase -df tip
548 obsoleted 1 changesets
551 obsoleted 1 changesets
549 *** runcommand log --hidden
552 *** runcommand log --hidden
550 changeset: 1:731265503d86
553 changeset: 1:731265503d86
551 tag: tip
554 tag: tip
552 user: test
555 user: test
553 date: Thu Jan 01 00:00:00 1970 +0000
556 date: Thu Jan 01 00:00:00 1970 +0000
554 obsolete: pruned
557 obsolete: pruned
555 summary: .
558 summary: .
556
559
557 changeset: 0:eff892de26ec
560 changeset: 0:eff892de26ec
558 bookmark: bm1
561 bookmark: bm1
559 bookmark: bm2
562 bookmark: bm2
560 bookmark: bm3
563 bookmark: bm3
561 user: test
564 user: test
562 date: Thu Jan 01 00:00:00 1970 +0000
565 date: Thu Jan 01 00:00:00 1970 +0000
563 summary: 1
566 summary: 1
564
567
565 *** runcommand log
568 *** runcommand log
566 changeset: 0:eff892de26ec
569 changeset: 0:eff892de26ec
567 bookmark: bm1
570 bookmark: bm1
568 bookmark: bm2
571 bookmark: bm2
569 bookmark: bm3
572 bookmark: bm3
570 tag: tip
573 tag: tip
571 user: test
574 user: test
572 date: Thu Jan 01 00:00:00 1970 +0000
575 date: Thu Jan 01 00:00:00 1970 +0000
573 summary: 1
576 summary: 1
574
577
575
578
576 $ cat <<EOF >> .hg/hgrc
579 $ cat <<EOF >> .hg/hgrc
577 > [extensions]
580 > [extensions]
578 > mq =
581 > mq =
579 > EOF
582 > EOF
580
583
581 >>> import os
584 >>> import os
582 >>> from hgclient import check, readchannel, runcommand
585 >>> from hgclient import check, readchannel, runcommand
583 >>> @check
586 >>> @check
584 ... def mqoutsidechanges(server):
587 ... def mqoutsidechanges(server):
585 ... readchannel(server)
588 ... readchannel(server)
586 ...
589 ...
587 ... # load repo.mq
590 ... # load repo.mq
588 ... runcommand(server, ['qapplied'])
591 ... runcommand(server, ['qapplied'])
589 ... os.system('hg qnew 0.diff')
592 ... os.system('hg qnew 0.diff')
590 ... # repo.mq should be invalidated
593 ... # repo.mq should be invalidated
591 ... runcommand(server, ['qapplied'])
594 ... runcommand(server, ['qapplied'])
592 ...
595 ...
593 ... runcommand(server, ['qpop', '--all'])
596 ... runcommand(server, ['qpop', '--all'])
594 ... os.system('hg qqueue --create foo')
597 ... os.system('hg qqueue --create foo')
595 ... # repo.mq should be recreated to point to new queue
598 ... # repo.mq should be recreated to point to new queue
596 ... runcommand(server, ['qqueue', '--active'])
599 ... runcommand(server, ['qqueue', '--active'])
597 *** runcommand qapplied
600 *** runcommand qapplied
598 *** runcommand qapplied
601 *** runcommand qapplied
599 0.diff
602 0.diff
600 *** runcommand qpop --all
603 *** runcommand qpop --all
601 popping 0.diff
604 popping 0.diff
602 patch queue now empty
605 patch queue now empty
603 *** runcommand qqueue --active
606 *** runcommand qqueue --active
604 foo
607 foo
605
608
606 $ cat <<EOF > dbgui.py
609 $ cat <<EOF > dbgui.py
607 > import os
610 > import os
608 > import sys
611 > import sys
609 > from mercurial import commands, registrar
612 > from mercurial import commands, registrar
610 > cmdtable = {}
613 > cmdtable = {}
611 > command = registrar.command(cmdtable)
614 > command = registrar.command(cmdtable)
612 > @command(b"debuggetpass", norepo=True)
615 > @command(b"debuggetpass", norepo=True)
613 > def debuggetpass(ui):
616 > def debuggetpass(ui):
614 > ui.write("%s\\n" % ui.getpass())
617 > ui.write("%s\\n" % ui.getpass())
615 > @command(b"debugprompt", norepo=True)
618 > @command(b"debugprompt", norepo=True)
616 > def debugprompt(ui):
619 > def debugprompt(ui):
617 > ui.write("%s\\n" % ui.prompt("prompt:"))
620 > ui.write("%s\\n" % ui.prompt("prompt:"))
618 > @command(b"debugreadstdin", norepo=True)
621 > @command(b"debugreadstdin", norepo=True)
619 > def debugreadstdin(ui):
622 > def debugreadstdin(ui):
620 > ui.write("read: %r\n" % sys.stdin.read(1))
623 > ui.write("read: %r\n" % sys.stdin.read(1))
621 > @command(b"debugwritestdout", norepo=True)
624 > @command(b"debugwritestdout", norepo=True)
622 > def debugwritestdout(ui):
625 > def debugwritestdout(ui):
623 > os.write(1, "low-level stdout fd and\n")
626 > os.write(1, "low-level stdout fd and\n")
624 > sys.stdout.write("stdout should be redirected to stderr\n")
627 > sys.stdout.write("stdout should be redirected to stderr\n")
625 > sys.stdout.flush()
628 > sys.stdout.flush()
626 > EOF
629 > EOF
627 $ cat <<EOF >> .hg/hgrc
630 $ cat <<EOF >> .hg/hgrc
628 > [extensions]
631 > [extensions]
629 > dbgui = dbgui.py
632 > dbgui = dbgui.py
630 > EOF
633 > EOF
631
634
632 >>> from hgclient import check, readchannel, runcommand, stringio
635 >>> from hgclient import check, readchannel, runcommand, stringio
633 >>> @check
636 >>> @check
634 ... def getpass(server):
637 ... def getpass(server):
635 ... readchannel(server)
638 ... readchannel(server)
636 ... runcommand(server, ['debuggetpass', '--config',
639 ... runcommand(server, ['debuggetpass', '--config',
637 ... 'ui.interactive=True'],
640 ... 'ui.interactive=True'],
638 ... input=stringio('1234\n'))
641 ... input=stringio('1234\n'))
639 ... runcommand(server, ['debuggetpass', '--config',
642 ... runcommand(server, ['debuggetpass', '--config',
640 ... 'ui.interactive=True'],
643 ... 'ui.interactive=True'],
641 ... input=stringio('\n'))
644 ... input=stringio('\n'))
642 ... runcommand(server, ['debuggetpass', '--config',
645 ... runcommand(server, ['debuggetpass', '--config',
643 ... 'ui.interactive=True'],
646 ... 'ui.interactive=True'],
644 ... input=stringio(''))
647 ... input=stringio(''))
645 ... runcommand(server, ['debugprompt', '--config',
648 ... runcommand(server, ['debugprompt', '--config',
646 ... 'ui.interactive=True'],
649 ... 'ui.interactive=True'],
647 ... input=stringio('5678\n'))
650 ... input=stringio('5678\n'))
648 ... runcommand(server, ['debugreadstdin'])
651 ... runcommand(server, ['debugreadstdin'])
649 ... runcommand(server, ['debugwritestdout'])
652 ... runcommand(server, ['debugwritestdout'])
650 *** runcommand debuggetpass --config ui.interactive=True
653 *** runcommand debuggetpass --config ui.interactive=True
651 password: 1234
654 password: 1234
652 *** runcommand debuggetpass --config ui.interactive=True
655 *** runcommand debuggetpass --config ui.interactive=True
653 password:
656 password:
654 *** runcommand debuggetpass --config ui.interactive=True
657 *** runcommand debuggetpass --config ui.interactive=True
655 password: abort: response expected
658 password: abort: response expected
656 [255]
659 [255]
657 *** runcommand debugprompt --config ui.interactive=True
660 *** runcommand debugprompt --config ui.interactive=True
658 prompt: 5678
661 prompt: 5678
659 *** runcommand debugreadstdin
662 *** runcommand debugreadstdin
660 read: ''
663 read: ''
661 *** runcommand debugwritestdout
664 *** runcommand debugwritestdout
662 low-level stdout fd and
665 low-level stdout fd and
663 stdout should be redirected to stderr
666 stdout should be redirected to stderr
664
667
665
668
666 run commandserver in commandserver, which is silly but should work:
669 run commandserver in commandserver, which is silly but should work:
667
670
668 >>> from __future__ import print_function
671 >>> from __future__ import print_function
669 >>> from hgclient import check, readchannel, runcommand, stringio
672 >>> from hgclient import check, readchannel, runcommand, stringio
670 >>> @check
673 >>> @check
671 ... def nested(server):
674 ... def nested(server):
672 ... print('%c, %r' % readchannel(server))
675 ... print('%c, %r' % readchannel(server))
673 ... class nestedserver(object):
676 ... class nestedserver(object):
674 ... stdin = stringio('getencoding\n')
677 ... stdin = stringio('getencoding\n')
675 ... stdout = stringio()
678 ... stdout = stringio()
676 ... runcommand(server, ['serve', '--cmdserver', 'pipe'],
679 ... runcommand(server, ['serve', '--cmdserver', 'pipe'],
677 ... output=nestedserver.stdout, input=nestedserver.stdin)
680 ... output=nestedserver.stdout, input=nestedserver.stdin)
678 ... nestedserver.stdout.seek(0)
681 ... nestedserver.stdout.seek(0)
679 ... print('%c, %r' % readchannel(nestedserver)) # hello
682 ... print('%c, %r' % readchannel(nestedserver)) # hello
680 ... print('%c, %r' % readchannel(nestedserver)) # getencoding
683 ... print('%c, %r' % readchannel(nestedserver)) # getencoding
681 o, 'capabilities: getencoding runcommand\nencoding: *\npid: *' (glob)
684 o, 'capabilities: getencoding runcommand\nencoding: *\npid: *' (glob)
682 *** runcommand serve --cmdserver pipe
685 *** runcommand serve --cmdserver pipe
683 o, 'capabilities: getencoding runcommand\nencoding: *\npid: *' (glob)
686 o, 'capabilities: getencoding runcommand\nencoding: *\npid: *' (glob)
684 r, '*' (glob)
687 r, '*' (glob)
685
688
686
689
687 start without repository:
690 start without repository:
688
691
689 $ cd ..
692 $ cd ..
690
693
691 >>> from __future__ import print_function
694 >>> from __future__ import print_function
692 >>> from hgclient import check, readchannel, runcommand
695 >>> from hgclient import check, readchannel, runcommand
693 >>> @check
696 >>> @check
694 ... def hellomessage(server):
697 ... def hellomessage(server):
695 ... ch, data = readchannel(server)
698 ... ch, data = readchannel(server)
696 ... print('%c, %r' % (ch, data))
699 ... print('%c, %r' % (ch, data))
697 ... # run an arbitrary command to make sure the next thing the server
700 ... # run an arbitrary command to make sure the next thing the server
698 ... # sends isn't part of the hello message
701 ... # sends isn't part of the hello message
699 ... runcommand(server, ['id'])
702 ... runcommand(server, ['id'])
700 o, 'capabilities: getencoding runcommand\nencoding: *\npid: *' (glob)
703 o, 'capabilities: getencoding runcommand\nencoding: *\npid: *' (glob)
701 *** runcommand id
704 *** runcommand id
702 abort: there is no Mercurial repository here (.hg not found)
705 abort: there is no Mercurial repository here (.hg not found)
703 [255]
706 [255]
704
707
705 >>> from hgclient import check, readchannel, runcommand
708 >>> from hgclient import check, readchannel, runcommand
706 >>> @check
709 >>> @check
707 ... def startwithoutrepo(server):
710 ... def startwithoutrepo(server):
708 ... readchannel(server)
711 ... readchannel(server)
709 ... runcommand(server, ['init', 'repo2'])
712 ... runcommand(server, ['init', 'repo2'])
710 ... runcommand(server, ['id', '-R', 'repo2'])
713 ... runcommand(server, ['id', '-R', 'repo2'])
711 *** runcommand init repo2
714 *** runcommand init repo2
712 *** runcommand id -R repo2
715 *** runcommand id -R repo2
713 000000000000 tip
716 000000000000 tip
714
717
715
718
716 don't fall back to cwd if invalid -R path is specified (issue4805):
719 don't fall back to cwd if invalid -R path is specified (issue4805):
717
720
718 $ cd repo
721 $ cd repo
719 $ hg serve --cmdserver pipe -R ../nonexistent
722 $ hg serve --cmdserver pipe -R ../nonexistent
720 abort: repository ../nonexistent not found!
723 abort: repository ../nonexistent not found!
721 [255]
724 [255]
722 $ cd ..
725 $ cd ..
723
726
724
727
725 unix domain socket:
728 unix domain socket:
726
729
727 $ cd repo
730 $ cd repo
728 $ hg update -q
731 $ hg update -q
729
732
730 #if unix-socket unix-permissions
733 #if unix-socket unix-permissions
731
734
732 >>> from __future__ import print_function
735 >>> from __future__ import print_function
733 >>> from hgclient import check, readchannel, runcommand, stringio, unixserver
736 >>> from hgclient import check, readchannel, runcommand, stringio, unixserver
734 >>> server = unixserver('.hg/server.sock', '.hg/server.log')
737 >>> server = unixserver('.hg/server.sock', '.hg/server.log')
735 >>> def hellomessage(conn):
738 >>> def hellomessage(conn):
736 ... ch, data = readchannel(conn)
739 ... ch, data = readchannel(conn)
737 ... print('%c, %r' % (ch, data))
740 ... print('%c, %r' % (ch, data))
738 ... runcommand(conn, ['id'])
741 ... runcommand(conn, ['id'])
739 >>> check(hellomessage, server.connect)
742 >>> check(hellomessage, server.connect)
740 o, 'capabilities: getencoding runcommand\nencoding: *\npid: *' (glob)
743 o, 'capabilities: getencoding runcommand\nencoding: *\npid: *' (glob)
741 *** runcommand id
744 *** runcommand id
742 eff892de26ec tip bm1/bm2/bm3
745 eff892de26ec tip bm1/bm2/bm3
743 >>> def unknowncommand(conn):
746 >>> def unknowncommand(conn):
744 ... readchannel(conn)
747 ... readchannel(conn)
745 ... conn.stdin.write('unknowncommand\n')
748 ... conn.stdin.write('unknowncommand\n')
746 >>> check(unknowncommand, server.connect) # error sent to server.log
749 >>> check(unknowncommand, server.connect) # error sent to server.log
747 >>> def serverinput(conn):
750 >>> def serverinput(conn):
748 ... readchannel(conn)
751 ... readchannel(conn)
749 ... patch = """
752 ... patch = """
750 ... # HG changeset patch
753 ... # HG changeset patch
751 ... # User test
754 ... # User test
752 ... # Date 0 0
755 ... # Date 0 0
753 ... 2
756 ... 2
754 ...
757 ...
755 ... diff -r eff892de26ec -r 1ed24be7e7a0 a
758 ... diff -r eff892de26ec -r 1ed24be7e7a0 a
756 ... --- a/a
759 ... --- a/a
757 ... +++ b/a
760 ... +++ b/a
758 ... @@ -1,1 +1,2 @@
761 ... @@ -1,1 +1,2 @@
759 ... 1
762 ... 1
760 ... +2
763 ... +2
761 ... """
764 ... """
762 ... runcommand(conn, ['import', '-'], input=stringio(patch))
765 ... runcommand(conn, ['import', '-'], input=stringio(patch))
763 ... runcommand(conn, ['log', '-rtip', '-q'])
766 ... runcommand(conn, ['log', '-rtip', '-q'])
764 >>> check(serverinput, server.connect)
767 >>> check(serverinput, server.connect)
765 *** runcommand import -
768 *** runcommand import -
766 applying patch from stdin
769 applying patch from stdin
767 *** runcommand log -rtip -q
770 *** runcommand log -rtip -q
768 2:1ed24be7e7a0
771 2:1ed24be7e7a0
769 >>> server.shutdown()
772 >>> server.shutdown()
770
773
771 $ cat .hg/server.log
774 $ cat .hg/server.log
772 listening at .hg/server.sock
775 listening at .hg/server.sock
773 abort: unknown command unknowncommand
776 abort: unknown command unknowncommand
774 killed!
777 killed!
775 $ rm .hg/server.log
778 $ rm .hg/server.log
776
779
777 if server crashed before hello, traceback will be sent to 'e' channel as
780 if server crashed before hello, traceback will be sent to 'e' channel as
778 last ditch:
781 last ditch:
779
782
780 $ cat <<EOF >> .hg/hgrc
783 $ cat <<EOF >> .hg/hgrc
781 > [cmdserver]
784 > [cmdserver]
782 > log = inexistent/path.log
785 > log = inexistent/path.log
783 > EOF
786 > EOF
784 >>> from __future__ import print_function
787 >>> from __future__ import print_function
785 >>> from hgclient import check, readchannel, unixserver
788 >>> from hgclient import check, readchannel, unixserver
786 >>> server = unixserver('.hg/server.sock', '.hg/server.log')
789 >>> server = unixserver('.hg/server.sock', '.hg/server.log')
787 >>> def earlycrash(conn):
790 >>> def earlycrash(conn):
788 ... while True:
791 ... while True:
789 ... try:
792 ... try:
790 ... ch, data = readchannel(conn)
793 ... ch, data = readchannel(conn)
791 ... if not data.startswith(' '):
794 ... if not data.startswith(' '):
792 ... print('%c, %r' % (ch, data))
795 ... print('%c, %r' % (ch, data))
793 ... except EOFError:
796 ... except EOFError:
794 ... break
797 ... break
795 >>> check(earlycrash, server.connect)
798 >>> check(earlycrash, server.connect)
796 e, 'Traceback (most recent call last):\n'
799 e, 'Traceback (most recent call last):\n'
797 e, "IOError: *" (glob)
800 e, "IOError: *" (glob)
798 >>> server.shutdown()
801 >>> server.shutdown()
799
802
800 $ cat .hg/server.log | grep -v '^ '
803 $ cat .hg/server.log | grep -v '^ '
801 listening at .hg/server.sock
804 listening at .hg/server.sock
802 Traceback (most recent call last):
805 Traceback (most recent call last):
803 IOError: * (glob)
806 IOError: * (glob)
804 killed!
807 killed!
805 #endif
808 #endif
806 #if no-unix-socket
809 #if no-unix-socket
807
810
808 $ hg serve --cmdserver unix -a .hg/server.sock
811 $ hg serve --cmdserver unix -a .hg/server.sock
809 abort: unsupported platform
812 abort: unsupported platform
810 [255]
813 [255]
811
814
812 #endif
815 #endif
813
816
814 $ cd ..
817 $ cd ..
815
818
816 Test that accessing to invalid changelog cache is avoided at
819 Test that accessing to invalid changelog cache is avoided at
817 subsequent operations even if repo object is reused even after failure
820 subsequent operations even if repo object is reused even after failure
818 of transaction (see 0a7610758c42 also)
821 of transaction (see 0a7610758c42 also)
819
822
820 "hg log" after failure of transaction is needed to detect invalid
823 "hg log" after failure of transaction is needed to detect invalid
821 cache in repoview: this can't detect by "hg verify" only.
824 cache in repoview: this can't detect by "hg verify" only.
822
825
823 Combination of "finalization" and "empty-ness of changelog" (2 x 2 =
826 Combination of "finalization" and "empty-ness of changelog" (2 x 2 =
824 4) are tested, because '00changelog.i' are differently changed in each
827 4) are tested, because '00changelog.i' are differently changed in each
825 cases.
828 cases.
826
829
827 $ cat > $TESTTMP/failafterfinalize.py <<EOF
830 $ cat > $TESTTMP/failafterfinalize.py <<EOF
828 > # extension to abort transaction after finalization forcibly
831 > # extension to abort transaction after finalization forcibly
829 > from mercurial import commands, error, extensions, lock as lockmod
832 > from mercurial import commands, error, extensions, lock as lockmod
830 > from mercurial import registrar
833 > from mercurial import registrar
831 > cmdtable = {}
834 > cmdtable = {}
832 > command = registrar.command(cmdtable)
835 > command = registrar.command(cmdtable)
833 > configtable = {}
836 > configtable = {}
834 > configitem = registrar.configitem(configtable)
837 > configitem = registrar.configitem(configtable)
835 > configitem('failafterfinalize', 'fail',
838 > configitem('failafterfinalize', 'fail',
836 > default=None,
839 > default=None,
837 > )
840 > )
838 > def fail(tr):
841 > def fail(tr):
839 > raise error.Abort('fail after finalization')
842 > raise error.Abort('fail after finalization')
840 > def reposetup(ui, repo):
843 > def reposetup(ui, repo):
841 > class failrepo(repo.__class__):
844 > class failrepo(repo.__class__):
842 > def commitctx(self, ctx, error=False):
845 > def commitctx(self, ctx, error=False):
843 > if self.ui.configbool('failafterfinalize', 'fail'):
846 > if self.ui.configbool('failafterfinalize', 'fail'):
844 > # 'sorted()' by ASCII code on category names causes
847 > # 'sorted()' by ASCII code on category names causes
845 > # invoking 'fail' after finalization of changelog
848 > # invoking 'fail' after finalization of changelog
846 > # using "'cl-%i' % id(self)" as category name
849 > # using "'cl-%i' % id(self)" as category name
847 > self.currenttransaction().addfinalize('zzzzzzzz', fail)
850 > self.currenttransaction().addfinalize('zzzzzzzz', fail)
848 > return super(failrepo, self).commitctx(ctx, error)
851 > return super(failrepo, self).commitctx(ctx, error)
849 > repo.__class__ = failrepo
852 > repo.__class__ = failrepo
850 > EOF
853 > EOF
851
854
852 $ hg init repo3
855 $ hg init repo3
853 $ cd repo3
856 $ cd repo3
854
857
855 $ cat <<EOF >> $HGRCPATH
858 $ cat <<EOF >> $HGRCPATH
856 > [ui]
859 > [ui]
857 > logtemplate = {rev} {desc|firstline} ({files})\n
860 > logtemplate = {rev} {desc|firstline} ({files})\n
858 >
861 >
859 > [extensions]
862 > [extensions]
860 > failafterfinalize = $TESTTMP/failafterfinalize.py
863 > failafterfinalize = $TESTTMP/failafterfinalize.py
861 > EOF
864 > EOF
862
865
863 - test failure with "empty changelog"
866 - test failure with "empty changelog"
864
867
865 $ echo foo > foo
868 $ echo foo > foo
866 $ hg add foo
869 $ hg add foo
867
870
868 (failure before finalization)
871 (failure before finalization)
869
872
870 >>> from hgclient import check, readchannel, runcommand
873 >>> from hgclient import check, readchannel, runcommand
871 >>> @check
874 >>> @check
872 ... def abort(server):
875 ... def abort(server):
873 ... readchannel(server)
876 ... readchannel(server)
874 ... runcommand(server, ['commit',
877 ... runcommand(server, ['commit',
875 ... '--config', 'hooks.pretxncommit=false',
878 ... '--config', 'hooks.pretxncommit=false',
876 ... '-mfoo'])
879 ... '-mfoo'])
877 ... runcommand(server, ['log'])
880 ... runcommand(server, ['log'])
878 ... runcommand(server, ['verify', '-q'])
881 ... runcommand(server, ['verify', '-q'])
879 *** runcommand commit --config hooks.pretxncommit=false -mfoo
882 *** runcommand commit --config hooks.pretxncommit=false -mfoo
880 transaction abort!
883 transaction abort!
881 rollback completed
884 rollback completed
882 abort: pretxncommit hook exited with status 1
885 abort: pretxncommit hook exited with status 1
883 [255]
886 [255]
884 *** runcommand log
887 *** runcommand log
885 *** runcommand verify -q
888 *** runcommand verify -q
886
889
887 (failure after finalization)
890 (failure after finalization)
888
891
889 >>> from hgclient import check, readchannel, runcommand
892 >>> from hgclient import check, readchannel, runcommand
890 >>> @check
893 >>> @check
891 ... def abort(server):
894 ... def abort(server):
892 ... readchannel(server)
895 ... readchannel(server)
893 ... runcommand(server, ['commit',
896 ... runcommand(server, ['commit',
894 ... '--config', 'failafterfinalize.fail=true',
897 ... '--config', 'failafterfinalize.fail=true',
895 ... '-mfoo'])
898 ... '-mfoo'])
896 ... runcommand(server, ['log'])
899 ... runcommand(server, ['log'])
897 ... runcommand(server, ['verify', '-q'])
900 ... runcommand(server, ['verify', '-q'])
898 *** runcommand commit --config failafterfinalize.fail=true -mfoo
901 *** runcommand commit --config failafterfinalize.fail=true -mfoo
899 transaction abort!
902 transaction abort!
900 rollback completed
903 rollback completed
901 abort: fail after finalization
904 abort: fail after finalization
902 [255]
905 [255]
903 *** runcommand log
906 *** runcommand log
904 *** runcommand verify -q
907 *** runcommand verify -q
905
908
906 - test failure with "not-empty changelog"
909 - test failure with "not-empty changelog"
907
910
908 $ echo bar > bar
911 $ echo bar > bar
909 $ hg add bar
912 $ hg add bar
910 $ hg commit -mbar bar
913 $ hg commit -mbar bar
911
914
912 (failure before finalization)
915 (failure before finalization)
913
916
914 >>> from hgclient import check, readchannel, runcommand
917 >>> from hgclient import check, readchannel, runcommand
915 >>> @check
918 >>> @check
916 ... def abort(server):
919 ... def abort(server):
917 ... readchannel(server)
920 ... readchannel(server)
918 ... runcommand(server, ['commit',
921 ... runcommand(server, ['commit',
919 ... '--config', 'hooks.pretxncommit=false',
922 ... '--config', 'hooks.pretxncommit=false',
920 ... '-mfoo', 'foo'])
923 ... '-mfoo', 'foo'])
921 ... runcommand(server, ['log'])
924 ... runcommand(server, ['log'])
922 ... runcommand(server, ['verify', '-q'])
925 ... runcommand(server, ['verify', '-q'])
923 *** runcommand commit --config hooks.pretxncommit=false -mfoo foo
926 *** runcommand commit --config hooks.pretxncommit=false -mfoo foo
924 transaction abort!
927 transaction abort!
925 rollback completed
928 rollback completed
926 abort: pretxncommit hook exited with status 1
929 abort: pretxncommit hook exited with status 1
927 [255]
930 [255]
928 *** runcommand log
931 *** runcommand log
929 0 bar (bar)
932 0 bar (bar)
930 *** runcommand verify -q
933 *** runcommand verify -q
931
934
932 (failure after finalization)
935 (failure after finalization)
933
936
934 >>> from hgclient import check, readchannel, runcommand
937 >>> from hgclient import check, readchannel, runcommand
935 >>> @check
938 >>> @check
936 ... def abort(server):
939 ... def abort(server):
937 ... readchannel(server)
940 ... readchannel(server)
938 ... runcommand(server, ['commit',
941 ... runcommand(server, ['commit',
939 ... '--config', 'failafterfinalize.fail=true',
942 ... '--config', 'failafterfinalize.fail=true',
940 ... '-mfoo', 'foo'])
943 ... '-mfoo', 'foo'])
941 ... runcommand(server, ['log'])
944 ... runcommand(server, ['log'])
942 ... runcommand(server, ['verify', '-q'])
945 ... runcommand(server, ['verify', '-q'])
943 *** runcommand commit --config failafterfinalize.fail=true -mfoo foo
946 *** runcommand commit --config failafterfinalize.fail=true -mfoo foo
944 transaction abort!
947 transaction abort!
945 rollback completed
948 rollback completed
946 abort: fail after finalization
949 abort: fail after finalization
947 [255]
950 [255]
948 *** runcommand log
951 *** runcommand log
949 0 bar (bar)
952 0 bar (bar)
950 *** runcommand verify -q
953 *** runcommand verify -q
951
954
952 $ cd ..
955 $ cd ..
953
956
954 Test symlink traversal over cached audited paths:
957 Test symlink traversal over cached audited paths:
955 -------------------------------------------------
958 -------------------------------------------------
956
959
957 #if symlink
960 #if symlink
958
961
959 set up symlink hell
962 set up symlink hell
960
963
961 $ mkdir merge-symlink-out
964 $ mkdir merge-symlink-out
962 $ hg init merge-symlink
965 $ hg init merge-symlink
963 $ cd merge-symlink
966 $ cd merge-symlink
964 $ touch base
967 $ touch base
965 $ hg commit -qAm base
968 $ hg commit -qAm base
966 $ ln -s ../merge-symlink-out a
969 $ ln -s ../merge-symlink-out a
967 $ hg commit -qAm 'symlink a -> ../merge-symlink-out'
970 $ hg commit -qAm 'symlink a -> ../merge-symlink-out'
968 $ hg up -q 0
971 $ hg up -q 0
969 $ mkdir a
972 $ mkdir a
970 $ touch a/poisoned
973 $ touch a/poisoned
971 $ hg commit -qAm 'file a/poisoned'
974 $ hg commit -qAm 'file a/poisoned'
972 $ hg log -G -T '{rev}: {desc}\n'
975 $ hg log -G -T '{rev}: {desc}\n'
973 @ 2: file a/poisoned
976 @ 2: file a/poisoned
974 |
977 |
975 | o 1: symlink a -> ../merge-symlink-out
978 | o 1: symlink a -> ../merge-symlink-out
976 |/
979 |/
977 o 0: base
980 o 0: base
978
981
979
982
980 try trivial merge after update: cache of audited paths should be discarded,
983 try trivial merge after update: cache of audited paths should be discarded,
981 and the merge should fail (issue5628)
984 and the merge should fail (issue5628)
982
985
983 $ hg up -q null
986 $ hg up -q null
984 >>> from hgclient import check, readchannel, runcommand
987 >>> from hgclient import check, readchannel, runcommand
985 >>> @check
988 >>> @check
986 ... def merge(server):
989 ... def merge(server):
987 ... readchannel(server)
990 ... readchannel(server)
988 ... # audit a/poisoned as a good path
991 ... # audit a/poisoned as a good path
989 ... runcommand(server, ['up', '-qC', '2'])
992 ... runcommand(server, ['up', '-qC', '2'])
990 ... runcommand(server, ['up', '-qC', '1'])
993 ... runcommand(server, ['up', '-qC', '1'])
991 ... # here a is a symlink, so a/poisoned is bad
994 ... # here a is a symlink, so a/poisoned is bad
992 ... runcommand(server, ['merge', '2'])
995 ... runcommand(server, ['merge', '2'])
993 *** runcommand up -qC 2
996 *** runcommand up -qC 2
994 *** runcommand up -qC 1
997 *** runcommand up -qC 1
995 *** runcommand merge 2
998 *** runcommand merge 2
996 abort: path 'a/poisoned' traverses symbolic link 'a'
999 abort: path 'a/poisoned' traverses symbolic link 'a'
997 [255]
1000 [255]
998 $ ls ../merge-symlink-out
1001 $ ls ../merge-symlink-out
999
1002
1000 cache of repo.auditor should be discarded, so matcher would never traverse
1003 cache of repo.auditor should be discarded, so matcher would never traverse
1001 symlinks:
1004 symlinks:
1002
1005
1003 $ hg up -qC 0
1006 $ hg up -qC 0
1004 $ touch ../merge-symlink-out/poisoned
1007 $ touch ../merge-symlink-out/poisoned
1005 >>> from hgclient import check, readchannel, runcommand
1008 >>> from hgclient import check, readchannel, runcommand
1006 >>> @check
1009 >>> @check
1007 ... def files(server):
1010 ... def files(server):
1008 ... readchannel(server)
1011 ... readchannel(server)
1009 ... runcommand(server, ['up', '-qC', '2'])
1012 ... runcommand(server, ['up', '-qC', '2'])
1010 ... # audit a/poisoned as a good path
1013 ... # audit a/poisoned as a good path
1011 ... runcommand(server, ['files', 'a/poisoned'])
1014 ... runcommand(server, ['files', 'a/poisoned'])
1012 ... runcommand(server, ['up', '-qC', '0'])
1015 ... runcommand(server, ['up', '-qC', '0'])
1013 ... runcommand(server, ['up', '-qC', '1'])
1016 ... runcommand(server, ['up', '-qC', '1'])
1014 ... # here 'a' is a symlink, so a/poisoned should be warned
1017 ... # here 'a' is a symlink, so a/poisoned should be warned
1015 ... runcommand(server, ['files', 'a/poisoned'])
1018 ... runcommand(server, ['files', 'a/poisoned'])
1016 *** runcommand up -qC 2
1019 *** runcommand up -qC 2
1017 *** runcommand files a/poisoned
1020 *** runcommand files a/poisoned
1018 a/poisoned
1021 a/poisoned
1019 *** runcommand up -qC 0
1022 *** runcommand up -qC 0
1020 *** runcommand up -qC 1
1023 *** runcommand up -qC 1
1021 *** runcommand files a/poisoned
1024 *** runcommand files a/poisoned
1022 abort: path 'a/poisoned' traverses symbolic link 'a'
1025 abort: path 'a/poisoned' traverses symbolic link 'a'
1023 [255]
1026 [255]
1024
1027
1025 $ cd ..
1028 $ cd ..
1026
1029
1027 #endif
1030 #endif
General Comments 0
You need to be logged in to leave comments. Login now