Source

repoman / tests / output / combine.py

import os
from tests.pytest import run

def append(text, f='foo'):
    with open(f, 'ab') as fl:
        fl.write(text)
        fl.write('\n')

def sitrep(rev=None, gl=False, copies=False):
    if gl:
        os.system('hg gl')
    else:
        os.system('hg -q par')
    if rev is not None:
        os.system('hg diff -r %d' % rev)
    else:
        if copies:
            os.system('hg st -C')
        else:
            os.system('hg st')

os.system('hg init combinetest')
os.chdir('combinetest')

try:
    append('init')
    os.system('hg -q ci -d "0 0" -Am init')
    append('base')
    os.system('hg -q ci -d "0 0" -m base')
    append('a1')
    os.system('hg -q ci -d "0 0" -m a1')
    append('a2')
    os.system('hg -q ci -d "0 0" -m a2')
    os.system('hg -q up 1')
    append('a1\na2')
    os.system('hg -q ci -d "0 0" -m b')
    os.system('hg -q up 3')

    print '\n* initial graph:'
    os.system('hg gl')

    print '\n* combine with non-parent (fail)'
    run('combine -kC 4')

    print '\n* combine with unrelated changesets present (fail)'
    run('combine -kC 1')

    print '\n* combine linear sub-graph (ok)'
    run('combine -kC 2')
    sitrep(3)
    os.system('hg -q up -C 3')

    print '\n* combine with local changes (fail)'
    append('change')
    run('combine -kC 2')

    print '\n* combine -w with local changes (ok)'
    append('change')
    run('combine -wkC 2')
    sitrep()
    os.system('hg -q up -C 3')

    print '\n* combine with strip (default) (ok)'
    run('combine -C 2')
    sitrep(gl=True)
    os.system('hg -q unbundle .combine-to-3044535ca74c.backup')
    os.unlink('.combine-to-3044535ca74c.backup')
    os.system('hg -q up -C 4')
    sitrep(gl=True)

    print '\n* combine linear sub-graph of branchy graph (fail)'
    os.system('hg -q merge')
    os.system('hg -q ci -d "0 0" -m merge')
    run('combine -kC 3')

    print '\n* combine complete branchy graph with public phases (fail)'
    os.system('hg phase -p 2')
    run('combine -kC 1')

    print '\n* combine complete branchy graph (ok)'
    os.system('hg phase -fd 0')
    run('combine -kC 1')
    sitrep(5)
    os.system('hg -q up -C 3')

    print '\n* combine branchy graph with unrelated changeset present (fail)'
    append('leaf', f='bar')
    os.system('hg -q ci -d "0 0" -Am leaf')
    os.system('hg -q up -C 5')
    run('combine -kC 1')
    os.system('hg -q up -C 6')

    print '\n* combine with chained renames (ok)'
    os.system('hg -q mv bar bar2')
    os.system('hg -q ci -d "0 0" -m move1')
    os.system('hg -q mv bar2 bar3')
    os.system('hg -q ci -d "0 0" -m move2')
    os.system('hg -q mv bar3 bar4')
    run('combine -wkC 7')
    sitrep(copies=True)
    os.system('hg -q up -C 6')
    os.unlink('bar4')

    print '\n* combine with rename from non-existent file (ok)'
    append('new', 'ket')
    os.system('hg -q add ket')
    os.system('hg -q ci -d "0 0" -m new')
    os.system('hg -q mv ket ket2')
    os.system('hg -q ci -d "0 0" -m move')
    run('combine -wkC 9')
    sitrep(copies=True)
    os.system('hg -q up -C 10')

    print '\n* combine with added file in .hgignore (ok)'
    append('new', 'ignore')
    append('ignore', '.hgignore')
    os.system('hg -q add ignore')
    os.system('hg -q ci -d "0 0" -m ignored')
    append('new', 'ignore')
    run('combine -wkC 11')
    sitrep()

finally:
    os.chdir('..')