Source

repoman / tests / output / uncommit.py

Full commit
import os

from repoman import cmdutil

from tests.pytest import run, Quiet

def get_commit_message(forest, text=[''], extra=[]):
    return u'fancy commit message'.encode('utf-8')

with Quiet():
    run('clone ../forest1 -M * -b core/dev -d uncommittest')
os.chdir(os.path.join('uncommittest', 'a'))

orig_gcm = cmdutil.get_commit_message
cmdutil.get_commit_message = get_commit_message

try:
    with open(os.path.join('.hg', 'hgrc'), 'a') as f:
        f.write('[extensions]\nhgext.mq =\n')

    print '* Uncommit tip'
    with open('foo', 'ab') as f:
        f.write('foo\r\n')
    run('commit -d "0 0" -m')

    run('par -M a')
    run('uncommit')

    print
    print '* Uncommit tip with multiple heads'
    with open('foo', 'ab') as f:
        f.write('foo\r\n')
    run('commit -d "0 0" -m')
    os.system('hg up -r 1')
    with open('foo', 'ab') as f:
        f.write('bar\r\n')
    run('commit -d "0 0" -m')
    run('heads -M a')
    run('uncommit')
    run('heads -M a')

    print
    print '* Uncommit non-tip head with multiple heads'
    with open('foo', 'ab') as f:
        f.write('foo\r\n')
    run('commit -d "0 0" -m')
    os.system('hg up -r 1')
    with open('boo', 'ab') as f:
        f.write('bar\r\n')
    os.system('hg add boo')
    run('commit -d "0 0" -m')
    run('heads -M a')

    print
    print '* Uncommit with local changes'
    with open('boo', 'ab') as f:
        f.write('more\r\n')
    os.system('hg st')
    run('uncommit')
    os.system('hg st')

    print
    print '* Uncommit merge'
    os.system('hg up -C')
    os.system('hg merge --config ui.merge=internal:local')
    run('commit -d "0 0" -m')
    run('uncommit')

    print
    print '* Uncommit non-wdir parent failure'
    run('uncommit -r 0')

    print
    print '* Uncommit non-head failure'
    os.system('hg up -Cr 0')
    run('uncommit')

finally:
    cmdutil.get_commit_message = orig_gcm
    os.chdir('..')