1
# Copyright (C) 2006 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
"""Tests for WorkingTree.revision_tree.
19
These tests are in addition to the tests from
20
tree_implementations.test_revision_tree which cover the behaviour expected from
21
all Trees. WorkingTrees implement the revision_tree api to allow access to
22
cached data, but we don't require that all WorkingTrees have such a cache,
23
so these tests are testing that when there is a cache, it performs correctly.
26
from bzrlib import errors
27
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
30
class TestRevisionTree(TestCaseWithWorkingTree):
32
def test_get_zeroth_basis_tree_via_revision_tree(self):
33
tree = self.make_branch_and_tree('.')
35
revision_tree = tree.revision_tree(tree.last_revision())
36
except errors.NoSuchRevision:
37
# its ok for a working tree to not cache trees, so just return.
39
basis_tree = tree.basis_tree()
40
self.assertTreesEqual(revision_tree, basis_tree)
42
def test_get_nonzeroth_basis_tree_via_revision_tree(self):
43
tree = self.make_branch_and_tree('.')
44
revision1 = tree.commit('first post')
45
revision_tree = tree.revision_tree(revision1)
46
basis_tree = tree.basis_tree()
47
self.assertTreesEqual(revision_tree, basis_tree)
49
def test_get_pending_merge_revision_tree(self):
50
tree = self.make_branch_and_tree('tree1')
51
tree.commit('first post')
52
tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
53
revision1 = tree2.commit('commit in branch', allow_pointless=True)
54
tree.merge_from_branch(tree2.branch)
56
cached_revision_tree = tree.revision_tree(revision1)
57
except errors.NoSuchRevision:
58
# its ok for a working tree to not cache trees, so just return.
60
real_revision_tree = tree2.basis_tree()
61
self.assertTreesEqual(real_revision_tree, cached_revision_tree)
63
def test_get_uncached_basis_via_revision_tree(self):
64
# The basis_tree method returns an empty tree when you ask for the
65
# basis if the basis is not cached, and it is a ghost. However the
66
# revision_tree method should always raise when a request tree is not
67
# cached, so we force this by setting a basis that is a ghost and
68
# thus cannot be cached.
69
tree = self.make_branch_and_tree('.')
70
tree.set_parent_ids(['a-ghost'], allow_leftmost_as_ghost=True)
71
self.assertRaises(errors.NoSuchRevision, tree.revision_tree, 'a-ghost')
73
def test_revision_tree_different_root_id(self):
74
"""A revision tree might have a very different root."""
75
tree = self.make_branch_and_tree('tree1')
76
tree.set_root_id('one')
77
rev1 = tree.commit('first post')
78
tree.set_root_id('two')
80
cached_revision_tree = tree.revision_tree(rev1)
81
except errors.NoSuchRevision:
82
# its ok for a working tree to not cache trees, so just return.
84
repository_revision_tree = tree.branch.repository.revision_tree(rev1)
85
self.assertTreesEqual(repository_revision_tree, cached_revision_tree)