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 Tree and InterTree."""
24
from breezy.tests import (
26
TestCaseWithTransport,
28
from breezy.tree import (
29
FileTimestampUnavailable,
36
class TestErrors(TestCase):
38
def test_file_timestamp_unavailable(self):
39
e = FileTimestampUnavailable("/path/foo")
40
self.assertEqual("The filestamp for /path/foo is not available.",
19
from bzrlib.tests import TestCaseWithTransport
20
from bzrlib.tree import InterTree
44
23
class TestInterTree(TestCaseWithTransport):
85
64
def compare(self, want_unchanged=False, specific_files=None,
86
extra_trees=None, require_versioned=False, include_root=False,
87
want_unversioned=False):
65
extra_trees=None, require_versioned=False, include_root=False,
66
want_unversioned=False):
89
68
('compare', self.source, self.target, want_unchanged,
90
specific_files, extra_trees, require_versioned,
69
specific_files, extra_trees, require_versioned,
91
70
include_root, want_unversioned)
94
def find_source_path(self, target_path, recurse='none'):
96
('find_source_path', self.source, self.target, target_path, recurse))
99
74
def is_compatible(klass, source, target):
110
85
RecordingOptimiser.calls = []
111
86
InterTree.register_optimiser(RecordingOptimiser)
112
87
tree = self.make_branch_and_tree('1')
113
null_tree = tree.basis_tree()
114
88
tree2 = self.make_branch_and_tree('2')
115
89
# do a series of calls:
117
91
tree.changes_from(tree2)
118
92
# pass in all optional arguments by position
119
tree.changes_from(tree2, 'unchanged', 'specific', 'extra',
93
tree.changes_from(tree2, 'unchanged', 'specific', 'extra',
121
95
# pass in all optional arguments by keyword
122
96
tree.changes_from(tree2,
123
specific_files='specific',
124
want_unchanged='unchanged',
126
require_versioned='require',
128
want_unversioned=True,
97
specific_files='specific',
98
want_unchanged='unchanged',
100
require_versioned='require',
102
want_unversioned=True,
131
105
InterTree._optimisers = old_optimisers
132
106
self.assertEqual(
134
('find_source_path', null_tree, tree, '', 'none'),
135
('find_source_path', null_tree, tree2, '', 'none'),
136
('compare', tree2, tree, False, None, None, False, False,
138
('compare', tree2, tree, 'unchanged', 'specific', 'extra',
139
'require', True, False),
140
('compare', tree2, tree, 'unchanged', 'specific', 'extra',
141
'require', True, True),
108
('compare', tree2, tree, False, None, None, False, False, False),
109
('compare', tree2, tree, 'unchanged', 'specific', 'extra',
110
'require', True, False),
111
('compare', tree2, tree, 'unchanged', 'specific', 'extra',
112
'require', True, True),
142
113
], RecordingOptimiser.calls)
144
115
def test_changes_from_with_root(self):
146
117
wt = self.make_branch_and_tree('.')
147
118
delta = wt.changes_from(wt.basis_tree())
148
119
self.assertEqual(len(delta.added), 0)
149
delta = wt.changes_from(wt.basis_tree(), include_root=True)
150
self.assertEqual(len(delta.added), 1)
151
self.assertEqual(delta.added[0].path[1], '')
153
def test_changes_from_with_require_versioned(self):
154
"""Ensure the require_versioned option does what's expected."""
155
wt = self.make_branch_and_tree('.')
156
self.build_tree(['known_file', 'unknown_file'])
160
errors.PathsNotVersionedError,
161
wt.changes_from, wt.basis_tree(), wt,
162
specific_files=['known_file', 'unknown_file'],
163
require_versioned=True)
165
# we need to pass a known file with an unknown file to get this to
166
# fail when expected.
167
delta = wt.changes_from(wt.basis_tree(),
168
specific_files=['known_file', 'unknown_file'],
169
require_versioned=False)
170
self.assertEqual(len(delta.added), 1)
173
class FindPreviousPathsTests(TestCaseWithTransport):
176
tree = self.make_branch_and_tree('tree')
177
self.build_tree(['tree/b'])
179
revid1 = tree.commit('first')
180
tree1 = tree.branch.repository.revision_tree(revid1)
182
tree0 = tree.branch.repository.revision_tree(revision.NULL_REVISION)
184
self.assertEqual({'b': None}, find_previous_paths(tree1, tree0, ['b']))
186
def test_find_previous_paths(self):
187
tree = self.make_branch_and_tree('tree')
188
self.build_tree(['tree/b'])
190
revid1 = tree.commit('first')
191
tree1 = tree.branch.repository.revision_tree(revid1)
193
tree.rename_one('b', 'c')
194
self.build_tree(['tree/b'])
196
revid2 = tree.commit('second')
197
tree2 = tree.branch.repository.revision_tree(revid2)
199
self.assertEqual({'c': 'b', 'b': None},
200
find_previous_paths(tree2, tree1, ['b', 'c']))
203
class GetCanonicalPath(TestCaseWithTransport):
205
def test_existing_case(self):
206
# Test that we can find a file from a path with different case
207
tree = self.make_branch_and_tree('tree')
208
self.build_tree(['tree/b'])
212
get_canonical_path(tree, 'b', lambda x: x.lower()))
215
get_canonical_path(tree, 'B', lambda x: x.lower()))
217
def test_nonexistant_preserves_case(self):
218
tree = self.make_branch_and_tree('tree')
221
get_canonical_path(tree, 'b', lambda x: x.lower()))
224
get_canonical_path(tree, 'B', lambda x: x.lower()))
226
def test_in_directory_with_case(self):
227
tree = self.make_branch_and_tree('tree')
228
self.build_tree(['tree/a/', 'tree/a/b'])
229
tree.add(['a', 'a/b'])
232
get_canonical_path(tree, 'a/b', lambda x: x.lower()))
235
get_canonical_path(tree, 'A/B', lambda x: x.lower()))
238
get_canonical_path(tree, 'A/b', lambda x: x.lower()))
241
get_canonical_path(tree, 'A/C', lambda x: x.lower()))
120
delta = wt.changes_from(wt.basis_tree(), wt, include_root=True)
121
self.assertEqual(len(delta.added), 1)
122
self.assertEqual(delta.added[0][0], '')