| 1 |
import os |
| 2 |
import sys |
| 3 |
from mercurial import dispatch, main_script |
| 4 |
|
| 5 |
|
| 6 |
def printb(data, end=b'\n'): |
| 7 |
out = getattr(sys.stdout, 'buffer', sys.stdout) |
| 8 |
out.write(data + end) |
| 9 |
out.flush() |
| 10 |
|
| 11 |
|
| 12 |
def testdispatch(cmd): |
| 13 |
"""Simple wrapper around dispatch.dispatch() |
| 14 |
|
| 15 |
Prints command and result value, but does not handle quoting. |
| 16 |
""" |
| 17 |
printb(b"running: %s" % (cmd,)) |
| 18 |
req = main_script.request(cmd.split()) |
| 19 |
result = dispatch.dispatch(req) |
| 20 |
printb(b"result: %r" % (result,)) |
| 21 |
|
| 22 |
|
| 23 |
testdispatch(b"init test1") |
| 24 |
os.chdir('test1') |
| 25 |
|
| 26 |
# create file 'foo', add and commit |
| 27 |
f = open('foo', 'wb') |
| 28 |
f.write(b'foo\n') |
| 29 |
f.close() |
| 30 |
testdispatch(b"add foo") |
| 31 |
testdispatch(b"commit -m commit1 -d 2000-01-01 foo") |
| 32 |
|
| 33 |
# append to file 'foo' and commit |
| 34 |
f = open('foo', 'ab') |
| 35 |
f.write(b'bar\n') |
| 36 |
f.close() |
| 37 |
testdispatch(b"commit -m commit2 -d 2000-01-02 foo") |
| 38 |
|
| 39 |
# check 88803a69b24 (fancyopts modified command table) |
| 40 |
testdispatch(b"log -r 0") |
| 41 |
testdispatch(b"log -r tip") |