Source

repoman / tests / output / update.py

Full commit
# -*- coding: latin1 -*-

import os
import codecs

from repoman import cmdutil

from tests.pytest import run, Quiet

with Quiet():
    run('-q clone ../forest1 sol1 -b core/dev -d updatetest')
    run('-q clone ../forest1 -e -b core/dev -d updatetest2')
os.chdir('updatetest')

def get_update_changeset_choice(forest, module, candidates):
    '''Always choose the last candidate.'''
    return len(candidates)

orig_get_update_changeset_choice = cmdutil.get_update_changeset_choice
cmdutil.get_update_changeset_choice = get_update_changeset_choice

def write_file(f, cont):
    if isinstance(f, list):
        f = os.path.join(*f)
    with open(f, 'w') as fl:
        fl.write(cont)

def write_file_and_commit(f, cont):
    if isinstance(f, list):
        f = os.path.join(*f)
    write_file(f, cont)
    os.system('hg -R %s ci -d "0 0" -Am commit' % os.path.dirname(f))

def print_file(f):
    with codecs.open(f, 'r', 'utf-8-sig') as fl:
        print fl.read()

try:
    with open(os.path.join('a', '.hg', 'hgrc'), 'a') as f:
        f.write('\n[ui]\nmerge=internal:local\n')

    print 'Unknown branch, failure'
    run('update foo/bar')

    write_file_and_commit(['a', 'foo'], 'foobar')
    os.system('hg -R a up 1')

    print
    print 'Update to latest version of current branch'
    run('parents')
    run('update')
    run('parents')

    print
    print 'Update with outstanding changes, failure'
    os.system('hg -R a up 1')
    with open(os.path.join('a', 'foo'), 'w') as f:
        f.write('foobarbaz')
    run('update')

    print
    print 'Update with outstanding changes and --merge'
    run('update --merge')
    run('parents')
    run('status')

    print
    print 'Update in-place with --clean'
    run('update --clean')
    run('parents')
    run('status')

    print
    print 'Update to base'
    run('update --base')
    run('parents')

    print
    print 'Update to other branch'
    run('update core/stable')
    run('parents')

    print
    print 'Update in-place between two branches'
    run('update -b core/dev')
    run('branch -c core/branch1')
    run('branch -c core/branch2')
    run('update core/branch1')
    print_file(os.path.join('.repo', 'branch'))
    run('update core/branch2')
    print_file(os.path.join('.repo', 'branch'))
    
    print
    print 'Two revisions, failure'
    run('update -b core/dev core/dev')

    print
    print 'Update to illegal branch name'
    run('update -b /core/dev')

    print
    print 'Update to local revision'
    run('update --local 0')

    print
    print 'Update with --clean to non-covering branch'
    run('branch -c core/branch3 -M a')
    run('update --clean core/branch3')

    print
    print 'Update with --clean to branch with local non-ASCII name, with backup'
    run('branch -c core/���')
    os.unlink('a/foo.orig')
    write_file_and_commit(['a', 'neu'], 'foobar')
    os.system('hg -R a up -C 0')
    write_file(['a', 'neu'], 'foobar2')
    run('update --clean core/���')
    print sorted([f for f in os.listdir('a') if f.startswith('neu')])

    print
    print 'Update with --date to branch with local non-ASCII name'
    write_file_and_commit(['b', 'foo'], 'foo bar baz qux')
    run('update --date "0 0" core/���')
    run('info')
    os.system('hg -R b glog')

    print
    print 'Check update to base of extended branch'
    run('branch -d "0 0" -M a -c core/test/ext')
    run('branch -d "0 0" -M b -e core/test/ext')
    run('-N c update --base core/test/ext')

finally:
    os.chdir('..')
    cmdutil.get_update_changeset_choice = orig_get_update_changeset_choice

os.chdir('updatetest2')
try:
    run('update core/stable')
finally:
    os.chdir('..')