Source

repoman / tests / output / outgoing.py

Full commit
import codecs
import os
import shutil
from repoman import cmdutil, util
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 '\n'.join([e for e in text if not e.startswith('HG:')]).strip()
orig_gcm = cmdutil.get_commit_message
cmdutil.get_commit_message = get_commit_message

with Quiet():
    run('clone ../forest1 -M * -b * -d forest2')
    run('clone forest2 sol1 -b core/dev')
    append('sol1/a/foo', 'a new line added!\n')
    os.system('hg -q -R sol1/a ci -d "0 0" -m change1')
    run('-R sol1 branch -c -d "0 0" core/foo')
    os.system('hg -q -R sol1/a up 0')
    append('sol1/a/foo', 'new branch!\n')
    os.system('hg -q -R sol1/a branch core/foo')
    os.system('hg -q -R sol1/a ci -d "0 0" -m change2')
    run('-R sol1 up core/dev')
    os.system('hg -q -R sol1/a up 1')
    append('sol1/a/foo', 'yet another line added!\n')
    os.system('hg -q -R sol1/a ci -d "0 0" -m change3')
    run('clone ../forest1 -M * -b core/dev -d pushtest1')
    run('clone pushtest1 -M * -b core/dev -d pushtest2')
    run('-R pushtest1 branch -c core/foo -d "0 0"')
    run('-R pushtest2 branch -c core/bar -d "0 0"')
    with open(os.path.join('pushtest2', 'a', 'foo'), 'a') as fh:
        fh.write('foo')
    os.system('hg -q -R pushtest2/a ci -d "0 0" -m foo')

print '\n% push multiple heads: with preview'
run('-R sol1 push')
print '\n% push multiple heads: without preview'
run('-R sol1 push --noninteractive')
print '\n% push multiple heads: one is a pseudo-head'
run('-R sol1 push -b core/foo')

print '\n% push with applied mq patch'
with Quiet():
    os.system('hg -q -R sol1/a rollback')
    run('-R sol1 up -C core/foo')
    append('sol1/a/foo', 'a patch!\n')
    os.system('hg -R sol1/a qnew -d "0 0" -fg test')
run('-R sol1 push --current')
run('-R sol1 push --noninteractive --current')
with Quiet():
    run('-R sol1 up core/dev')
    os.system('hg -q -R sol1/a up 1')

run('-R sol1 outgoing -b core/dev --current')
run('-R sol1 outgoing --current')
run('-R sol1 outgoing -b core/dev')
run('-R sol1 outgoing -b foo/bar')
run('-R sol1 push')
run('-R sol1 push --noninteractive')
run('-R sol1 push')

run('-R pushtest2 push --noninteractive')
run('-R pushtest2 pull')
run('-R pushtest2 push --noninteractive')

# test --no-metadata-pull
os.system('hg -R pushtest1/.root up -C')
run('-R pushtest1 branch -c foo/test --root -d "0 0"')
run('-R pushtest2 push --noninteractive --no-metadata-pull')
run('-R pushtest2 push --noninteractive --debug')

# Test order of modules
with Quiet():
    run('clone forest2 -M * -b * -d forestorder')
    run('-R forestorder modadd AT')
    run('-R forestorder modadd Ac')
    with codecs.open(os.path.join('forestorder', '.root', 'solutions', 'sol5'), 'ab', 'utf-8-sig') as fh:
        fh.write('AT\nAc\n')
    os.system('hg -q -R forestorder/.root ci -d "0 0" -Am "Added solution"')
    run('clone forestorder sol5 -b core/dev')
origsort = util.sortmodules
util.sortmodules = lambda x: sorted(x, key=str.lower)
run('-R sol5 outgoing -b core/dev')
util.sortmodules = origsort

try:
    shutil.rmtree('sol1')
    shutil.rmtree('forest2')
    shutil.rmtree('sol5')
    shutil.rmtree('forestorder')
except:
    pass