Source

repoman / tests / output / timeupdate.py

Full commit
import os

import mercurial.util

from repoman import ui

from tests.pytest import run, Quiet

datestr = lambda x: mercurial.util.datestr(x, '%Y-%m-%d %H:%M:%S %1%2')

def commit_change(mod, fname, content, cmsg, append=True, date='0 0'):
    with open(os.path.join(mod, fname), 'a' if append else 'w') as fh:
        fh.write(content)
    os.system('hg -R %s ci -m "%s" -d "%s"' % (mod, cmsg, date))

def update(mod, rev):
    os.system('hg -R %s up %d' % (mod, rev))

with Quiet():
    run('clone ../forest1 -M * -b core/dev -d tuptest')

    os.chdir('tuptest')

    commit_change('a', 'foo', 'foo', 'foo', date='20000 -7200')
    commit_change('a', 'foo', 'bar', 'bar', date='100000 -7200')
    update('a', 1)
    run('branch -c core/foo')
    commit_change('a', 'foo', 'baz', 'baz', date='70000 -7200')
    commit_change('a', 'foo', 'quux', 'quux', date='40000 -7200')
    commit_change('a', 'foo', 'corge', 'corge', date='60000 -7200')
    commit_change('a', 'foo', 'grault', 'grault', date='200000 -7200')

def choice(self, *args, **kwargs):
    print ' '.join(args), 's'
    return 's'

origchoice = ui.RepoUi.prompt
ui.ui.prompt = choice

run('-q up core/dev')

print '% updating to exact ', datestr((30000,-7200)), 'on core/dev'
run('-M a update --date "30000 0"')

print
print '% updating to exact existing timestamp', datestr((20000,-7200)), 'on core/dev'
run('-M a update --date "20000 0"')

print
print '% updating to range without match on', datestr((30000,-7200)), 'to', datestr((40000,-7200)), 'on core/dev'
run('-M a update --date "30000 0 to 40000 0"')

print
print '% updating to range with match on lower', datestr((10000,-7200)), 'to', datestr((30000,-7200)), 'on core/dev'
run('-M a update --date "10000 0 to 30000 0"')

print
print '% updating to range with match on upper', datestr((80000,-7200)), 'to', datestr((1100000,-7200)), 'on core/dev'
run('-M a update --date "80000 0 to 1100000 0"')

print
print '% updating to < with no match', datestr((10,-7200)), 'on core/dev'
run('-M a update --date "<10 0" --delta 0')

print
print '% updating to <', datestr((60000,-7200)), 'with delta 0 on core/dev'
run('-M a update --date "<60000 0" --delta 0')

print
print '% updating to <', datestr((60000,-7200)), 'with delta 50000 on core/dev'
run('-M a update --date "<60000 0" --delta 50000')

print
print '% updating to >', datestr((60000,-7200)), 'with delta 0 on core/dev'
run('-M a update --date ">60000 0" --delta 0')

print
print '% updating to >', datestr((90000,-7200)), 'with delta 20000 on core/dev'
run('-M a update --date ">90000 0" --delta 20000')

run('-q up core/foo')

print
print '% updating to range with matches', datestr((35000, -7200)), 'to', datestr((75000,-7200)), 'on core/foo'
run('-M a update --date "35000 0 to 75000 0"')

print
print '% updating to specific', datestr((180000,-7200)), 'with delta 30000 on core/foo'
run('-M a update --date "180000 0" --delta 30000')

ui.ui.prompt = origchoice