13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
17
"""Tests for WorkingTree.revision_tree.
19
These tests are in addition to the tests from
20
per_tree.test_revision_tree which cover the behaviour expected from
19
These tests are in addition to the tests from
20
tree_implementations.test_revision_tree which cover the behaviour expected from
21
21
all Trees. WorkingTrees implement the revision_tree api to allow access to
22
22
cached data, but we don't require that all WorkingTrees have such a cache,
23
23
so these tests are testing that when there is a cache, it performs correctly.
30
from bzrlib.tests import per_workingtree
33
class TestRevisionTree(per_workingtree.TestCaseWithWorkingTree):
26
from bzrlib import errors
27
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
30
class TestRevisionTree(TestCaseWithWorkingTree):
35
32
def test_get_zeroth_basis_tree_via_revision_tree(self):
36
33
tree = self.make_branch_and_tree('.')
87
84
repository_revision_tree = tree.branch.repository.revision_tree(rev1)
88
85
self.assertTreesEqual(repository_revision_tree, cached_revision_tree)
91
class TestRevisionTreeKind(per_workingtree.TestCaseWithWorkingTree):
93
def make_branch_with_merged_deletions(self, relpath='tree'):
94
tree = self.make_branch_and_tree(relpath)
95
files = ['a', 'b/', 'b/c']
96
self.build_tree(files, line_endings='binary',
97
transport=tree.bzrdir.root_transport)
98
tree.set_root_id('root-id')
99
tree.add(files, ['a-id', 'b-id', 'c-id'])
100
tree.commit('a, b and b/c', rev_id='base')
101
tree2 = tree.bzrdir.sprout(relpath + '2').open_workingtree()
103
tree.remove('a', keep_files=False)
104
tree.commit('remove a', rev_id='this')
105
# Delete 'c' in tree2
106
tree2.remove('b/c', keep_files=False)
107
tree2.remove('b', keep_files=False)
108
tree2.commit('remove b/c', rev_id='other')
109
# Merge tree2 into tree
110
tree.merge_from_branch(tree2.branch)
113
def test_kind_parent_tree(self):
114
tree = self.make_branch_with_merged_deletions()
116
self.addCleanup(tree.unlock)
117
parents = tree.get_parent_ids()
118
self.assertEqual(['this', 'other'], parents)
119
basis = tree.revision_tree(parents[0])
121
self.addCleanup(basis.unlock)
122
self.assertRaises(errors.NoSuchId, basis.kind, 'a-id')
123
self.assertEqual(['directory', 'file'],
124
[basis.kind('b-id'), basis.kind('c-id')])
126
other = tree.revision_tree(parents[1])
127
except errors.NoSuchRevisionInTree:
128
raise tests.TestNotApplicable(
129
'Tree type %s caches only the basis revision tree.'
132
self.addCleanup(other.unlock)
133
self.assertRaises(errors.NoSuchId, other.kind, 'b-id')
134
self.assertRaises(errors.NoSuchId, other.kind, 'c-id')
135
self.assertEqual('file', other.kind('a-id'))