1. Henrik Stuart
  2. repoman


repoman / tests / output / pull.py

import os
import shutil
from tests.support import write_text

from repoman.ui import SimpleUi as ui
from repoman import forest, cmdutil

from tests.pytest import run, Quiet
from tests.runtests import run_command

def hg_add_file(repo, module, filename, content = 'Some content'):
    modulepath = '%s/%s' % (repo, module)
    filepath = '%s/%s' % (modulepath, filename)
    write_text('%s' % filepath, content)
    os.system('hg add -R %s %s' % (modulepath, filepath))

def hg_commit(repo, module, message = '"Dummy message"'):
    os.system('hg commit -R %s/%s -d "0 0" -m %s' % (repo, module, message))

def get_commit_message(forest, text=[''], extra=[]):
    return ('\n'.join([e for e in text if not e.startswith('HG:')]).strip() +
        '\n'.join([e for e in extra if not e.startswith('HG:')]).strip())

orig_gcm = cmdutil.get_commit_message
cmdutil.get_commit_message = get_commit_message

print('cloning forest1 to forest2')
with Quiet():
    run('clone ../forest1 -M * -b core/dev -d forest2')

print('pull on clean clone - i.e., without incoming changes')
run('pull -R forest2')

print('clone forest2 to forest3')
with Quiet():
    run('clone forest2 -M * -b core/dev -d forest3')

print('add and commit changeset in forest2')
hg_add_file('forest2', 'c', 'baz')
hg_commit('forest2', 'c')

print('pull on working branch (implicit)')
run('pull -R forest3')

print('pull on another branch (i.e., using arg)')
run('pull -R forest3 --branch core/stable')

print('pull on an unknown branch')
run('in -R forest3 --branch unknownbranch')

print('create a new branch core/new1 in forest2')
run('branch --create core/new1 -R forest2 -M a -M b -M c --date "0 0"')
run('-R forest2 up core/dev')

print('pull metadata change specifying an unknown branch and a known branch')
run('pull -R forest3 -b unknownbranch -b core/dev')

print('create another branch in forest2')
run('branch -c core/new2 -R forest2 -M a -M c --date "0 0"')
run('-R forest2 up core/dev')

print('pull metadata change without --branch arg')
run('pull -R forest3')

print('Test --noupdate...')
print('add and commit another changeset in forest2')
hg_add_file('forest2', 'b', 'baz')
hg_commit('forest2', 'b')

print('check parents before and after pull, to check that, in fact, the --noupdate flag prevents an update')
ret, tip_before = run_command('hg parents  --template "{node}" -R %s/%s' % ('forest3', 'b'))
print('tip before pull --noupdate\n%s' % tip_before)
run('pull -R forest3 -b core/dev -b core/stable --noupdate')
ret, tip_after = run_command('hg parents --template "{node}" -R %s/%s' % ('forest3', 'b'))
print('tip after pull --noupdate\n%s' % tip_after)
success = tip_before == tip_after

print('Test (%s): pull with --noupdate flag did %schange status of the working directory.' \
      % (('SUCCESS' if success else 'FAILED') , ('not ' if success else '')))

print('Test fast-forwarding...')

# ... the following is an exact copy of the setup from the in-test,
# and tests exactly the same functionality.
# (While this is somewhat clumsy, we need separate regression tests for in and pull,
#  should their implementations ever diverge.)
print('Setting up test-situation')
print('--update to core/stable in forest2')
run('up core/stable -R forest2')
print('--create a new branch core/new on top of core/stable in forest2')
run('branch --create core/new -R forest2 -M a -M b -M c --date "0 0"')
run('-R forest2 up core/stable')

print('--pull core/new to forest3')
run('pull -R forest3 -b core/new')

print('--merge core/dev into core/stable in forest2')
run('merge core/dev -R forest2')
run('-R forest2 commit -m -d "0 0"')
print('--update to core/new in forest2')
run('up core/new -R forest2')
print('--merge core/stable into core/new in forest2')
print('  (as core/new has no updates and core/stable has been updated (via the merge) core/new is fast-forwarded)')
run('merge core/stable -R forest2')
run('-R forest2 commit -d "0 0"')
print('Done setting up.\n')

print('now pull (on all known branches) from forest3')
print('we expect messages that core/new has been fast-forwarded')
run('pull -R forest3 -b core/dev -b core/stable -b core/new')

print('Test --clean...')
run('-R forest2 up core/dev')
with Quiet():
    run('clone forest2 -b core/dev -M * -d forest4')
hg_add_file('forest2', 'b', 'fooz')
hg_commit('forest2', 'b')
run('pull -R forest4')
os.system('hg -R forest2/b up 2')
hg_add_file('forest2', 'b', 'foozz')
hg_commit('forest2', 'b')
run('pull -R forest4')
run('-R forest4 par --template "{rev}\\n"')
run('-R forest4 undo --yes')
hg_add_file('forest4', 'b', 'bar', content='asldkjlawieur alskejr')
run('pull -R forest4 --clean')
run('-R forest4 par --template "{rev}\\n"')
print 'backup exists:', os.path.exists('forest4/b/bar.orig')


cmdutil.get_commit_message = orig_gcm