1
# Copyright (C) 2006-2009, 2011 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
from breezy import errors, workingtree, tests
20
class TestWorkingTree(tests.TestCaseWithTransport):
22
def make_branch_and_tree(self, relpath, format=None):
24
format = 'development-subtree'
25
return tests.TestCaseWithTransport.make_branch_and_tree(self, relpath,
28
def make_trees(self, format=None, same_root=False):
29
self.build_tree(['tree/',
32
'tree/subtree/file2'])
33
base_tree = self.make_branch_and_tree('tree', format=format)
34
base_tree.add('file', b'file-id')
35
base_tree.commit('first commit', rev_id=b'tree-1')
36
sub_tree = self.make_branch_and_tree('tree/subtree',
37
format='development-subtree')
39
sub_tree.set_root_id(base_tree.path2id(''))
40
sub_tree.add('file2', b'file2-id')
41
sub_tree.commit('first commit', rev_id=b'subtree-1')
42
return base_tree, sub_tree
44
def test_old_knit1_failure(self):
45
"""Ensure that BadSubsumeSource is raised.
47
SubsumeTargetNeedsUpgrade must not be raised, because upgrading the
50
base_tree, sub_tree = self.make_trees(format='knit',
52
self.assertRaises(errors.BadSubsumeSource, base_tree.subsume,
55
def test_knit1_failure(self):
56
base_tree, sub_tree = self.make_trees(format='knit')
57
self.assertRaises(errors.SubsumeTargetNeedsUpgrade, base_tree.subsume,
60
def test_subsume_tree(self):
61
base_tree, sub_tree = self.make_trees()
62
self.assertNotEqual(base_tree.path2id(''), sub_tree.path2id(''))
63
sub_root_id = sub_tree.path2id('')
64
# this test checks the subdir is removed, so it needs to know the
65
# control directory; that changes rarely so just hardcode (and check)
67
self.assertPathExists('tree/subtree/.bzr')
68
base_tree.subsume(sub_tree)
69
self.assertEqual([b'tree-1', b'subtree-1'], base_tree.get_parent_ids())
70
self.assertEqual(sub_root_id, base_tree.path2id('subtree'))
71
self.assertEqual(b'file2-id', base_tree.path2id('subtree/file2'))
72
# subsuming the tree removes the control directory, so you can't open
74
self.assertPathDoesNotExist('tree/subtree/.bzr')
75
with open('tree/subtree/file2', 'rb') as file2:
76
file2_contents = file2.read()
77
base_tree = workingtree.WorkingTree.open('tree')
78
base_tree.commit('combined', rev_id=b'combined-1')
79
self.assertEqual(b'file2-id', base_tree.path2id('subtree/file2'))
80
if base_tree.supports_setting_file_ids():
81
self.assertEqual('subtree/file2', base_tree.id2path(b'file2-id'))
82
self.assertEqualDiff(file2_contents,
83
base_tree.get_file_text('subtree/file2'))
84
basis_tree = base_tree.basis_tree()
85
basis_tree.lock_read()
86
self.addCleanup(basis_tree.unlock)
87
self.assertEqualDiff(file2_contents,
88
base_tree.get_file_text('subtree/file2'))
89
self.assertEqualDiff(file2_contents,
90
basis_tree.get_file_text('subtree/file2'))
91
self.assertEqual(b'subtree-1',
92
basis_tree.get_file_revision('subtree/file2'))
93
self.assertEqual(b'combined-1',
94
basis_tree.get_file_revision('subtree'))
96
def test_subsume_failure(self):
97
base_tree, sub_tree = self.make_trees()
98
if base_tree.path2id('') == sub_tree.path2id(''):
99
raise tests.TestSkipped('This test requires unique roots')
100
self.assertRaises(errors.BadSubsumeSource, base_tree.subsume,
102
self.assertRaises(errors.BadSubsumeSource, sub_tree.subsume,
104
self.build_tree(['subtree2/'])
105
sub_tree2 = self.make_branch_and_tree('subtree2')
106
self.assertRaises(errors.BadSubsumeSource, sub_tree.subsume,
108
self.build_tree(['tree/subtree/subtree3/'])
109
sub_tree3 = self.make_branch_and_tree('tree/subtree/subtree3')
110
self.assertRaises(errors.BadSubsumeSource, base_tree.subsume,