Source

repoman / tests / output / undo.py

import os
import shutil
from mercurial import encoding
from repoman import cmdutil
from tests.pytest import run, Quiet

def append(path, text):
    with file(path, 'ab') as f:
        f.write(text)

def get_commit_message(forest, text=[''], extra=[]):
    return u'some message'.encode(encoding.encoding)

with Quiet():
    run('clone ../forest1 -M a -M b -b core/dev -d undof --debug --traceback')

orig_gcm = cmdutil.get_commit_message
cmdutil.get_commit_message = get_commit_message
os.chdir('undof')
try:

    print '% no initial undo information'
    run('undo')
 
    print '% review undo of commit'
    with Quiet():
        with open('a/foo', 'ab') as f:
            f.write('some data\n')
        run('commit -m -d "0 0"')
    run('undo')

    print '% accept undo'
    run('undo --yes')

    print '% undo with tampered module'
    with Quiet():
        with open('a/foo', 'ab') as f:
            f.write('some data\n')
        with open('b/foo', 'ab') as f:
            f.write('some data\n')
        run('commit -m -d "0 0"')
    import time
    time.sleep(1)
    os.system('hg -q -R b rollback')
    run('undo --yes')

    print '% undo branch creation'
    with Quiet():
        run('branch -c core/test')
    run('info')
    print 'undo in .root/.hg/store:', 'undo' in os.listdir('.root/.hg/store')
    print 'repoman.undo not in .root/.hg/store:', 'repoman.undo' not in os.listdir('.root/.hg/store')
    run('undo --yes')
    run('info')
    
finally:
    os.chdir('..')
    shutil.rmtree('undof')

with Quiet():
    run('clone ../forest1 -M a -M b -b core/dev -d forest2')
    # setup forest2 for merge (a) and fast forward (b)
    run('-R forest2 up core/stable')
    run('-R forest2 branch --create core/new --date "0 0"')
    run('-R forest2 up core/stable')
    append(os.path.join('forest2', 'a', 'foo'), 'foo\n')
    os.system('hg -R forest2/a ci -m foo -d "0 0"')
    append(os.path.join('forest2', 'b', 'foo'), 'foo\n')
    os.system('hg -R forest2/b ci -m foo -d "0 0"')
    run('-R forest2 up core/new')
    append(os.path.join('forest2', 'a', 'foo'), 'foo\n')
    os.system('hg -R forest2/a ci -m foo -d "0 0"')
    run('-R forest2 branch --create core/removed --date "0 0"')
    run('clone forest2 -M a -M b -b core/new -d undof2')

os.chdir('undof2')
try:
    print '% undo merge without undoing metadata pull'
    os.system('hg -R .root par')
    os.system('hg -R .root --quiet strip -n tip')
    run('pull')
    os.system('hg -R .root par')
    run('merge core/stable')
    run('commit -m -d "0 0"')
    os.system('hg -R .root par')
    run('undo --yes')
    os.system('hg -R .root glog')
    
finally:
    os.chdir('..')
    shutil.rmtree('undof2')
    cmdutil.get_commit_message = orig_gcm