repoman / tests / output /

import os
from repoman import cmdutil
from tests.pytest import run, Quiet, pushd

with Quiet():
    run('clone ../forest1 -M a -M b -M c -b core/dev -d bundlef')
    run('clone ../forest1 -M a -b core/dev -d bundlef2')

with pushd('bundlef'):

    def write(path, text, mode='ab'):
        with open(path, mode) as f:

    with Quiet():
        write('.root/bundletest', 'some data\n')
        write('a/foo', 'some data\n')
        write('b/foo', 'some data\n')
        os.system('hg -R .root ci -A -d "0 0" -m "commit b"')
        os.system('hg -R a ci -d "0 0" -m "commit a"')
        os.system('hg -R b ci -d "0 0" -m "commit b"')

    print '% preview outgoing'
    run('bundle test.bundle')

    print '% bundle outgoing, no extension'
    run('bundle test --noninteractive')

    def rollback():
        os.system('hg -q -R .root rollback')
        os.system('hg -q -R a rollback')
        os.system('hg -q -R b rollback')

    print '% rollback and view incoming'
    run('in test.repo')

    print '% pull bundle'
    run('pull test.repo')

    print '% rollback, strip and try both in (with and without --log), and pull with missing node'
    os.system('hg -q -R a strip -nf 1')
    run('in test.repo')
    run('in test.repo --log')
    run('pull test.repo')

    print '% in smaller forest'
    with pushd('../bundlef2'):
       run('in ../bundlef/test.repo')
       run('pull ../bundlef/test.repo')

    print '% test bundle --strip'
    # prepare rather complicated repository
    with Quiet():
        with pushd('c'):
            # base cset will be 2
            write('f', 'base')
            os.system('hg -q ci -d "0 0" -Am base')
            run('-M c branch -c core/a')
            write('f', 'leaf1')
            os.system('hg -q ci -d "0 0" -m leaf1')
            os.system('hg -q up 2')
            write('f', 'outer1')
            os.system('hg -q ci -d "0 0" -m outer1')
            write('f', 'outer2')
            os.system('hg -q ci -d "0 0" -m outer2')
            os.system('hg -q up 4')
            run('-M c branch -c core/b')
            write('f', 'p2')
            os.system('hg -q ci -d "0 0" -m p2')
            os.system('hg -q up 4')
            run('-M c branch -c core/c')
            os.system('hg -q merge core/b')
            os.system('hg -q ci -d "0 0" -m merge')
            write('f', 'leaf2')
            os.system('hg -q ci -d "0 0" -m leaf2')
            os.system('hg -q up 7')
            run('-M c branch -c core/d')
            write('f', 'leaf3')
            os.system('hg -q ci -d "0 0" -m leaf3')

    # bundle and strip
    run('-M c bundle strip.bundle -b core/a -b core/c --noninteractive --strip')
    os.system('hg -R c glog')
    with Quiet():
        run('unbundle strip.bundle')
    run('-M c bundle strip.bundle -b core/a -b core/c -b core/d --noninteractive --strip')
    os.system('hg -R c glog')

    print '% test incoming with and without -b'
    run('-qM c in -b . -b core/c strip.bundle')
    run('-qM c in strip.bundle')