1
# (C) 2005 Canonical Ltd
 
 
3
# This program is free software; you can redistribute it and/or modify
 
 
4
# it under the terms of the GNU General Public License as published by
 
 
5
# the Free Software Foundation; either version 2 of the License, or
 
 
6
# (at your option) any later version.
 
 
8
# This program is distributed in the hope that it will be useful,
 
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 
11
# GNU General Public License for more details.
 
 
13
# You should have received a copy of the GNU General Public License
 
 
14
# along with this program; if not, write to the Free Software
 
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 
17
from bzrlib.selftest import InTempDir
 
 
21
    from bzrlib.branch import Branch
 
 
22
    from bzrlib.commit import commit
 
 
25
    br1 = Branch("branch1", init=True)
 
 
26
    commit(br1, "Commit one")
 
 
27
    commit(br1, "Commit two")
 
 
28
    commit(br1, "Commit three")
 
 
31
    br2 = Branch("branch2", init=True)
 
 
32
    br2.update_revisions(br1)
 
 
33
    commit(br2, "Commit four")
 
 
34
    commit(br2, "Commit five")
 
 
35
    revisions_2 = br2.revision_history()
 
 
36
    br1.add_pending_merge(revisions_2[4])
 
 
37
    commit(br1, "Commit six")
 
 
41
class TestIsAncestor(InTempDir):
 
 
42
    """Test checking whether a revision is an ancestor of another revision"""
 
 
44
        from bzrlib.revision import is_ancestor, MultipleRevisionSources
 
 
45
        from bzrlib.errors import NoSuchRevision
 
 
46
        br1, br2 = make_branches()
 
 
47
        revisions = br1.revision_history()
 
 
48
        revisions_2 = br2.revision_history()
 
 
49
        sources = MultipleRevisionSources(br1, br2)
 
 
51
        assert is_ancestor(revisions[0], revisions[0], sources)
 
 
52
        assert is_ancestor(revisions[1], revisions[0], sources)
 
 
53
        assert not is_ancestor(revisions[0], revisions[1], sources)
 
 
54
        assert is_ancestor(revisions_2[3], revisions[0], sources)
 
 
55
        self.assertRaises(NoSuchRevision, is_ancestor, revisions_2[3],
 
 
57
        assert is_ancestor(revisions[3], revisions_2[4], sources)
 
 
58
        assert is_ancestor(revisions[3], revisions_2[4], br1)
 
 
59
        assert is_ancestor(revisions[3], revisions_2[3], sources)
 
 
60
        assert not is_ancestor(revisions[3], revisions_2[3], br1)