tests/test-revlog-ancestry.py
author Siddharth Agarwal <sid0@fb.com>
Wed, 03 Feb 2016 13:12:06 -0800
changeset 28022 e397b58c0563
parent 27344 43c00ca887d1
child 28763 abe605bbf0de
permissions -rw-r--r--
rebase: respect checkunknown and checkignored in more cases checkunknown and checkignored are currently respected for updates and regular merges, but not for certain kinds of rebases. To be precise, they aren't respected for rebases when: (1) we're rebasing while currently on the destination commit, and (2) an untracked or ignored file F is currently in the working copy, and (3) the same file F is in a source commit, and (4) F has different contents in the source commit. This happens because rebases set force to True when calling merge.update. Setting force to True makes a lot of sense in general, but it turns out the force option is overloaded: there's a deprecated '--force' option in merge that allows you to merge in outstanding changes, including changes in untracked files. We use the 'mergeforce' parameter to tell those two cases apart. I think the behavior during rebases when checkunknown is 'abort' (the default) is wrong -- we should abort on or overwrite differing untracked files, not try to merge them in. However that currently breaks rebases by aborting in the middle -- we need better handling for that case before we can change the default.

import os
from mercurial import hg, ui, merge

u = ui.ui()

repo = hg.repository(u, 'test1', create=1)
os.chdir('test1')

def commit(text, time):
    repo.commit(text=text, date="%d 0" % time)

def addcommit(name, time):
    f = open(name, 'w')
    f.write('%s\n' % name)
    f.close()
    repo[None].add([name])
    commit(name, time)

def update(rev):
    merge.update(repo, rev, False, True)

def merge_(rev):
    merge.update(repo, rev, True, False)

if __name__ == '__main__':
    addcommit("A", 0)
    addcommit("B", 1)

    update(0)
    addcommit("C", 2)

    merge_(1)
    commit("D", 3)

    update(2)
    addcommit("E", 4)
    addcommit("F", 5)

    update(3)
    addcommit("G", 6)

    merge_(5)
    commit("H", 7)

    update(5)
    addcommit("I", 8)

    # Ancestors
    print 'Ancestors of 5'
    for r in repo.changelog.ancestors([5]):
        print r,

    print '\nAncestors of 6 and 5'
    for r in repo.changelog.ancestors([6, 5]):
        print r,

    print '\nAncestors of 5 and 4'
    for r in repo.changelog.ancestors([5, 4]):
        print r,

    print '\nAncestors of 7, stop at 6'
    for r in repo.changelog.ancestors([7], 6):
        print r,

    print '\nAncestors of 7, including revs'
    for r in repo.changelog.ancestors([7], inclusive=True):
        print r,

    print '\nAncestors of 7, 5 and 3, including revs'
    for r in repo.changelog.ancestors([7, 5, 3], inclusive=True):
        print r,

    # Descendants
    print '\n\nDescendants of 5'
    for r in repo.changelog.descendants([5]):
        print r,

    print '\nDescendants of 5 and 3'
    for r in repo.changelog.descendants([5, 3]):
        print r,

    print '\nDescendants of 5 and 4'
    for r in repo.changelog.descendants([5, 4]):
        print r,