1
# Copyright (C) 2007 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
"""Test that WorkingTree.basis_tree() yields a valid tree."""
19
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
22
class TestBasisTree(TestCaseWithWorkingTree):
24
def test_emtpy_tree(self):
25
"""A working tree with no parents."""
26
tree = self.make_branch_and_tree('tree')
27
basis_tree = tree.basis_tree()
29
basis_tree.lock_read()
31
self.assertEqual([], list(basis_tree.list_files(include_root=True)))
35
def test_same_tree(self):
36
"""Test basis_tree when working tree hasn't been modified."""
37
tree = self.make_branch_and_tree('.')
38
self.build_tree(['file', 'dir/', 'dir/subfile'])
39
tree.add(['file', 'dir', 'dir/subfile'])
40
revision_id = tree.commit('initial tree')
42
basis_tree = tree.basis_tree()
43
basis_tree.lock_read()
45
self.assertEqual(revision_id, basis_tree.get_revision_id())
46
# list_files() may return in either dirblock or sorted order
47
# TODO: jam 20070215 Should list_files have an explicit order?
48
self.assertEqual(['', 'dir', 'dir/subfile', 'file'],
49
sorted(info[0] for info in basis_tree.list_files(True)))
53
def test_altered_tree(self):
54
"""Test basis really is basis after working has been modified."""
55
tree = self.make_branch_and_tree('.')
56
self.build_tree(['file', 'dir/', 'dir/subfile'])
57
tree.add(['file', 'dir', 'dir/subfile'])
58
revision_id = tree.commit('initial tree')
60
self.build_tree(['new file', 'new dir/'])
61
tree.rename_one('file', 'dir/new file')
62
tree.unversion([tree.path2id('dir/subfile')])
63
tree.add(['new file', 'new dir'])
65
basis_tree = tree.basis_tree()
66
basis_tree.lock_read()
68
self.assertEqual(revision_id, basis_tree.get_revision_id())
69
# list_files() may return in either dirblock or sorted order
70
# TODO: jam 20070215 Should list_files have an explicit order?
71
self.assertEqual(['', 'dir', 'dir/subfile', 'file'],
72
sorted(info[0] for info in basis_tree.list_files(True)))