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