Debian Codegraph @

tests/test-commandserver.t

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