/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2255.7.83 by John Arbash Meinel
Update some obvious copyright headers to include 2007.
1
# Copyright (C) 2006, 2007 Canonical Ltd
1852.6.1 by Robert Collins
Start tree implementation tests.
2
#
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.
7
#
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.
12
#
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1852.6.1 by Robert Collins
Start tree implementation tests.
16
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
17
"""Tests for the test trees used by the per_tree tests."""
1852.6.1 by Robert Collins
Start tree implementation tests.
18
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
19
from breezy import errors
6973.6.2 by Jelmer Vernooij
Fix more tests.
20
from breezy.sixish import text_type
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
21
from breezy.tests import per_tree
22
from breezy.tests import (
6861.1.1 by Jelmer Vernooij
More foreign branch test fixes.
23
    TestNotApplicable,
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
24
    TestSkipped,
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
25
    features,
26
    )
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
27
28
29
class TestTreeShapes(per_tree.TestCaseWithTree):
1852.6.1 by Robert Collins
Start tree implementation tests.
30
31
    def test_empty_tree_no_parents(self):
1852.8.3 by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case.
32
        tree = self.make_branch_and_tree('.')
33
        tree = self.get_tree_no_parents_no_content(tree)
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
34
        tree.lock_read()
35
        self.addCleanup(tree.unlock)
1852.6.1 by Robert Collins
Start tree implementation tests.
36
        self.assertEqual([], tree.get_parent_ids())
37
        self.assertEqual([], tree.conflicts())
38
        self.assertEqual([], list(tree.unknowns()))
6825.5.1 by Jelmer Vernooij
Implement Tree.all_versioned_paths.
39
        self.assertEqual([''], list(tree.all_versioned_paths()))
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
40
        self.assertEqual(
6844.1.1 by Jelmer Vernooij
Many more foreign branch fixes.
41
            [('', tree.path2id(''))],
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
42
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
43
44
    def test_abc_tree_no_parents(self):
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
45
        tree = self.make_branch_and_tree('.')
46
        tree = self.get_tree_no_parents_abc_content(tree)
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
47
        tree.lock_read()
48
        self.addCleanup(tree.unlock)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
49
        self.assertEqual([], tree.get_parent_ids())
50
        self.assertEqual([], tree.conflicts())
51
        self.assertEqual([], list(tree.unknowns()))
52
        # __iter__ has no strongly defined order
53
        self.assertEqual(
6825.5.1 by Jelmer Vernooij
Implement Tree.all_versioned_paths.
54
            {'', 'a', 'b', 'b/c'},
55
            set(tree.all_versioned_paths()))
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
56
        self.assertTrue(tree.is_versioned('a'))
57
        self.assertTrue(tree.is_versioned('b'))
58
        self.assertTrue(tree.is_versioned('b/c'))
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
59
        self.assertEqual(
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
60
            [(p, tree.path2id(p)) for p in ['', 'a', 'b', 'b/c']],
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
61
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
6973.7.3 by Jelmer Vernooij
Fix some more tests.
62
        self.assertEqualDiff(b'contents of a\n', tree.get_file_text('a'))
6809.4.4 by Jelmer Vernooij
Swap arguments for Tree.is_executable.
63
        self.assertFalse(tree.is_executable('b/c'))
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
64
65
    def test_abc_tree_content_2_no_parents(self):
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
66
        tree = self.make_branch_and_tree('.')
67
        tree = self.get_tree_no_parents_abc_content_2(tree)
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
68
        tree.lock_read()
69
        self.addCleanup(tree.unlock)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
70
        self.assertEqual([], tree.get_parent_ids())
71
        self.assertEqual([], tree.conflicts())
72
        self.assertEqual([], list(tree.unknowns()))
73
        # __iter__ has no strongly defined order
74
        self.assertEqual(
6825.5.1 by Jelmer Vernooij
Implement Tree.all_versioned_paths.
75
            {'', 'a', 'b', 'b/c'},
76
            set(tree.all_versioned_paths()))
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
77
        self.assertEqual(
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
78
            [(p, tree.path2id(p)) for p in ['', 'a', 'b', 'b/c']],
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
79
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
7397.2.3 by Jelmer Vernooij
Fix passing directories in specific_files in GitWorkingTree.
80
        self.assertEqual(
81
            [(p, tree.path2id(p)) for p in ['b']],
82
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir(
83
                specific_files=['b'])])
6973.7.3 by Jelmer Vernooij
Fix some more tests.
84
        self.assertEqualDiff(b'foobar\n', tree.get_file_text('a'))
6809.4.4 by Jelmer Vernooij
Swap arguments for Tree.is_executable.
85
        self.assertFalse(tree.is_executable('b//c'))
7397.2.3 by Jelmer Vernooij
Fix passing directories in specific_files in GitWorkingTree.
86
        self.assertFalse(tree.is_executable('b/c'))
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
87
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
88
    def test_abc_tree_content_3_no_parents(self):
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
89
        tree = self.make_branch_and_tree('.')
90
        tree = self.get_tree_no_parents_abc_content_3(tree)
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
91
        tree.lock_read()
92
        self.addCleanup(tree.unlock)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
93
        self.assertEqual([], tree.get_parent_ids())
94
        self.assertEqual([], tree.conflicts())
95
        self.assertEqual([], list(tree.unknowns()))
96
        # __iter__ has no strongly defined order
97
        self.assertEqual(
6825.5.1 by Jelmer Vernooij
Implement Tree.all_versioned_paths.
98
            {'', 'a', 'b', 'b/c'},
99
            set(tree.all_versioned_paths()))
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
100
        self.assertEqual(
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
101
            [(p, tree.path2id(p)) for p in ['', 'a', 'b', 'b/c']],
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
102
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
6973.7.3 by Jelmer Vernooij
Fix some more tests.
103
        self.assertEqualDiff(b'contents of a\n', tree.get_file_text('a'))
6809.4.4 by Jelmer Vernooij
Swap arguments for Tree.is_executable.
104
        self.assertTrue(tree.is_executable('b/c'))
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
105
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
106
    def test_abc_tree_content_4_no_parents(self):
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
107
        tree = self.make_branch_and_tree('.')
108
        tree = self.get_tree_no_parents_abc_content_4(tree)
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
109
        tree.lock_read()
110
        self.addCleanup(tree.unlock)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
111
        self.assertEqual([], tree.get_parent_ids())
112
        self.assertEqual([], tree.conflicts())
113
        self.assertEqual([], list(tree.unknowns()))
114
        # __iter__ has no strongly defined order
115
        self.assertEqual(
6825.5.1 by Jelmer Vernooij
Implement Tree.all_versioned_paths.
116
            {'', 'b', 'd', 'b/c'},
117
            set(tree.all_versioned_paths()))
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
118
        self.assertEqual(
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
119
            [(p, tree.path2id(p)) for p in ['', 'b', 'd', 'b/c']],
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
120
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
6973.7.3 by Jelmer Vernooij
Fix some more tests.
121
        self.assertEqualDiff(b'contents of a\n', tree.get_file_text('d'))
6809.4.4 by Jelmer Vernooij
Swap arguments for Tree.is_executable.
122
        self.assertFalse(tree.is_executable('b/c'))
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
123
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
124
    def test_abc_tree_content_5_no_parents(self):
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
125
        tree = self.make_branch_and_tree('.')
126
        tree = self.get_tree_no_parents_abc_content_5(tree)
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
127
        tree.lock_read()
128
        self.addCleanup(tree.unlock)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
129
        self.assertEqual([], tree.get_parent_ids())
130
        self.assertEqual([], tree.conflicts())
131
        self.assertEqual([], list(tree.unknowns()))
132
        # __iter__ has no strongly defined order
133
        self.assertEqual(
6825.5.1 by Jelmer Vernooij
Implement Tree.all_versioned_paths.
134
            {'', 'd', 'b', 'b/c'},
135
            set(tree.all_versioned_paths()))
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
136
        self.assertEqual(
7143.15.2 by Jelmer Vernooij
Run autopep8.
137
            [(p, tree.path2id(p)) for p in ['', 'b', 'd', 'b/c']],
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
138
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
6973.7.3 by Jelmer Vernooij
Fix some more tests.
139
        self.assertEqualDiff(b'bar\n', tree.get_file_text('d'))
6809.4.4 by Jelmer Vernooij
Swap arguments for Tree.is_executable.
140
        self.assertFalse(tree.is_executable('b/c'))
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
141
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
142
    def test_abc_tree_content_6_no_parents(self):
1852.8.7 by Robert Collins
Update tree_implementation test tree factories to be intertree ready.
143
        tree = self.make_branch_and_tree('.')
144
        tree = self.get_tree_no_parents_abc_content_6(tree)
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
145
        tree.lock_read()
146
        self.addCleanup(tree.unlock)
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
147
        self.assertEqual([], tree.get_parent_ids())
148
        self.assertEqual([], tree.conflicts())
7199.3.1 by Jelmer Vernooij
Don't report empty directories as changes.
149
        self.assertEqual([], list(tree.unknowns()))
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
150
        # __iter__ has no strongly defined order
6844.1.1 by Jelmer Vernooij
Many more foreign branch fixes.
151
        expected_paths = (
7143.15.2 by Jelmer Vernooij
Run autopep8.
152
            ['', 'a']
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
153
            + (['b'] if tree.has_versioned_directories() else [])
7143.15.2 by Jelmer Vernooij
Run autopep8.
154
            + ['e'])
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
155
        self.assertEqual(
6844.1.1 by Jelmer Vernooij
Many more foreign branch fixes.
156
            set(expected_paths),
6825.5.1 by Jelmer Vernooij
Implement Tree.all_versioned_paths.
157
            set(tree.all_versioned_paths()))
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
158
        self.assertEqual(
6844.1.1 by Jelmer Vernooij
Many more foreign branch fixes.
159
            [(p, tree.path2id(p)) for p in expected_paths],
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
160
            [(path, node.file_id) for path, node in tree.iter_entries_by_dir()])
6973.7.3 by Jelmer Vernooij
Fix some more tests.
161
        self.assertEqualDiff(b'contents of a\n', tree.get_file_text('a'))
6809.4.4 by Jelmer Vernooij
Swap arguments for Tree.is_executable.
162
        self.assertTrue(tree.is_executable('e'))
2294.1.1 by John Arbash Meinel
Track down some non-ascii deficiencies in commit logic.
163
1852.15.1 by Robert Collins
Add a complex test tree for use with Tree.walkdirs.
164
    def test_tree_with_subdirs_and_all_content_types(self):
165
        # currently this test tree requires unicode. It might be good
166
        # to have it simply stop having the single unicode file in it
167
        # when dealing with a non-unicode filesystem.
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
168
        self.requireFeature(features.SymlinkFeature)
1852.15.1 by Robert Collins
Add a complex test tree for use with Tree.walkdirs.
169
        tree = self.get_tree_with_subdirs_and_all_content_types()
2255.2.64 by John Arbash Meinel
Add the DirStateRevisionTree to the list of 'tree_implementations'
170
        tree.lock_read()
171
        self.addCleanup(tree.unlock)
1852.15.1 by Robert Collins
Add a complex test tree for use with Tree.walkdirs.
172
        self.assertEqual([], tree.get_parent_ids())
173
        self.assertEqual([], tree.conflicts())
7199.3.1 by Jelmer Vernooij
Don't report empty directories as changes.
174
        self.assertEqual([], list(tree.unknowns()))
1852.15.1 by Robert Collins
Add a complex test tree for use with Tree.walkdirs.
175
        # __iter__ has no strongly defined order
2255.2.17 by Robert Collins
tweaks - finishes off all the test_test_trees tests for dirstate.
176
        tree_root = tree.path2id('')
7170.3.1 by Jelmer Vernooij
Make Tree.all_file_ids optional.
177
        try:
178
            all_file_ids = set(tree.all_file_ids())
179
        except errors.UnsupportedOperation:
180
            all_file_ids = None
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
181
        if tree.has_versioned_directories():
7170.3.1 by Jelmer Vernooij
Make Tree.all_file_ids optional.
182
            if all_file_ids is not None:
183
                self.assertEqual(
184
                    {tree.path2id(p) for p in [
185
                        '', '0file', '1top-dir', '1top-dir/1dir-in-1topdir',
186
                        '1top-dir/0file-in-1topdir', 'symlink', u'2utf\u1234file']},
187
                    set(tree.all_file_ids()))
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
188
            # note that the order of the paths and fileids is deliberately
189
            # mismatched to ensure that the result order is path based.
190
            self.assertEqual(
191
                [('', 'directory'),
192
                 ('0file', 'file'),
193
                 ('1top-dir', 'directory'),
194
                 (u'2utf\u1234file', 'file'),
195
                 ('symlink', 'symlink'),
196
                 ('1top-dir/0file-in-1topdir', 'file'),
197
                 ('1top-dir/1dir-in-1topdir', 'directory')],
198
                [(path, node.kind) for path, node in tree.iter_entries_by_dir()])
199
        else:
7170.3.1 by Jelmer Vernooij
Make Tree.all_file_ids optional.
200
            if all_file_ids is not None:
201
                self.assertEqual(
202
                    {tree.path2id(p) for p in [
203
                        '', '0file', '1top-dir',
7170.3.2 by Jelmer Vernooij
Merge trunk.
204
                        '1top-dir/0file-in-1topdir', 'symlink',
205
                        u'2utf\u1234file']},
7170.3.1 by Jelmer Vernooij
Make Tree.all_file_ids optional.
206
                    set(tree.all_file_ids()))
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
207
            # note that the order of the paths and fileids is deliberately
208
            # mismatched to ensure that the result order is path based.
209
            self.assertEqual(
210
                [('', 'directory'),
211
                 ('0file', 'file'),
212
                 ('1top-dir', 'directory'),
213
                 (u'2utf\u1234file', 'file'),
214
                 ('symlink', 'symlink'),
215
                 ('1top-dir/0file-in-1topdir', 'file')],
216
                [(path, node.kind) for path, node in tree.iter_entries_by_dir()])
2255.2.106 by John Arbash Meinel
[merge] bzr.dev 2298 (broken)
217
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
218
    def test_tree_with_subdirs_and_all_content_types_wo_symlinks(self):
219
        # currently this test tree requires unicode. It might be good
220
        # to have it simply stop having the single unicode file in it
221
        # when dealing with a non-unicode filesystem.
7143.15.2 by Jelmer Vernooij
Run autopep8.
222
        tree = self.get_tree_with_subdirs_and_all_supported_content_types(
223
            False)
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
224
        tree.lock_read()
225
        self.addCleanup(tree.unlock)
226
        self.assertEqual([], tree.get_parent_ids())
227
        self.assertEqual([], tree.conflicts())
7199.3.1 by Jelmer Vernooij
Don't report empty directories as changes.
228
        self.assertEqual([], list(tree.unknowns()))
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
229
        # __iter__ has no strongly defined order
230
        tree_root = tree.path2id('')
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
231
        if tree.has_versioned_directories():
232
            self.assertEqual(
233
                {'', '0file', '1top-dir', '1top-dir/0file-in-1topdir',
234
                 '1top-dir/1dir-in-1topdir', u'2utf\u1234file'},
235
                set(tree.all_versioned_paths()))
236
            # note that the order of the paths and fileids is deliberately
237
            # mismatched to ensure that the result order is path based.
238
            self.assertEqual(
239
                [('', 'directory'),
240
                 ('0file', 'file'),
241
                 ('1top-dir', 'directory'),
242
                 (u'2utf\u1234file', 'file'),
243
                 ('1top-dir/0file-in-1topdir', 'file'),
244
                 ('1top-dir/1dir-in-1topdir', 'directory')],
245
                [(path, node.kind) for path, node in tree.iter_entries_by_dir()])
246
        else:
247
            self.assertEqual(
248
                {'', '0file', '1top-dir', '1top-dir/0file-in-1topdir',
249
                 u'2utf\u1234file'},
250
                set(tree.all_versioned_paths()))
251
            # note that the order of the paths and fileids is deliberately
252
            # mismatched to ensure that the result order is path based.
253
            self.assertEqual(
254
                [('', 'directory'),
255
                 ('0file', 'file'),
256
                 ('1top-dir', 'directory'),
257
                 (u'2utf\u1234file', 'file'),
258
                 ('1top-dir/0file-in-1topdir', 'file')],
259
                [(path, node.kind) for path, node in tree.iter_entries_by_dir()])
260
261
    def _create_tree_with_utf8(self, tree):
262
        self.requireFeature(features.UnicodeFilenameFeature)
263
264
        # We avoid combining characters in file names here, normalization
265
        # checks (as performed by some file systems (OSX) are outside the scope
266
        # of these tests).  We use the euro sign \N{Euro Sign} or \u20ac in
267
        # unicode strings or '\xe2\x82\ac' (its utf-8 encoding) in raw strings.
268
        paths = [u'',
269
                 u'fo\N{Euro Sign}o',
270
                 u'ba\N{Euro Sign}r/',
271
                 u'ba\N{Euro Sign}r/ba\N{Euro Sign}z',
7143.15.2 by Jelmer Vernooij
Run autopep8.
272
                 ]
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
273
        # bzr itself does not create unicode file ids, but we want them for
274
        # testing.
7045.4.11 by Jelmer Vernooij
Some more tests fixed.
275
        file_ids = [b'TREE_ROOT',
276
                    b'fo\xe2\x82\xaco-id',
277
                    b'ba\xe2\x82\xacr-id',
278
                    b'ba\xe2\x82\xacz-id',
7143.15.2 by Jelmer Vernooij
Run autopep8.
279
                    ]
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
280
        self.build_tree(paths[1:])
7358.14.1 by Jelmer Vernooij
Remove Tree.get_root_id() in favour of Tree.path2id('').
281
        if tree.path2id('') is None:
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
282
            # Some trees do not have a root yet.
283
            tree.add(paths, file_ids)
284
        else:
285
            # Some trees will already have a root
286
            if tree.supports_setting_file_ids():
287
                tree.set_root_id(file_ids[0])
288
                tree.add(paths[1:], file_ids[1:])
289
            else:
290
                tree.add(paths[1:])
291
        if tree.branch.repository._format.supports_setting_revision_ids:
292
            try:
293
                tree.commit(u'in\xedtial', rev_id=u'r\xe9v-1'.encode('utf8'))
294
            except errors.NonAsciiRevisionId:
295
                raise TestSkipped('non-ascii revision ids not supported')
296
        else:
297
            tree.commit(u'in\xedtial')
298
299
        return tree
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
300
2294.1.1 by John Arbash Meinel
Track down some non-ascii deficiencies in commit logic.
301
    def test_tree_with_utf8(self):
302
        tree = self.make_branch_and_tree('.')
6861.1.2 by Jelmer Vernooij
Fix test.
303
        if not tree.supports_setting_file_ids():
6861.1.1 by Jelmer Vernooij
More foreign branch test fixes.
304
            raise TestNotApplicable(
305
                'format does not support custom file ids')
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
306
        self._create_tree_with_utf8(tree)
307
308
        tree = self.workingtree_to_test_tree(tree)
2294.1.2 by John Arbash Meinel
Track down and add tests that all tree.commit() can handle
309
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
310
        revision_id = u'r\xe9v-1'.encode('utf8')
6973.13.2 by Jelmer Vernooij
Fix some more tests.
311
        root_id = b'TREE_ROOT'
3638.3.12 by Vincent Ladeuil
Fix test missed in the previous commit (--starting-with doesn't
312
        bar_id = u'ba\N{Euro Sign}r-id'.encode('utf8')
313
        foo_id = u'fo\N{Euro Sign}o-id'.encode('utf8')
314
        baz_id = u'ba\N{Euro Sign}z-id'.encode('utf8')
315
        path_and_ids = [(u'', root_id, None, None),
316
                        (u'ba\N{Euro Sign}r', bar_id, root_id, revision_id),
317
                        (u'fo\N{Euro Sign}o', foo_id, root_id, revision_id),
318
                        (u'ba\N{Euro Sign}r/ba\N{Euro Sign}z',
319
                         baz_id, bar_id, revision_id),
7143.15.2 by Jelmer Vernooij
Run autopep8.
320
                        ]
6885.6.1 by Jelmer Vernooij
Support specific_files argument to Tree.iter_entries_by_dir.
321
        with tree.lock_read():
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
322
            path_entries = list(tree.iter_entries_by_dir())
323
2294.1.7 by John Arbash Meinel
Add tests for parent ids in test_test_trees
324
        for expected, (path, ie) in zip(path_and_ids, path_entries):
7143.15.2 by Jelmer Vernooij
Run autopep8.
325
            self.assertEqual(expected[0], path)  # Paths should match
6973.6.2 by Jelmer Vernooij
Fix more tests.
326
            self.assertIsInstance(path, text_type)
2294.1.7 by John Arbash Meinel
Add tests for parent ids in test_test_trees
327
            self.assertEqual(expected[1], ie.file_id)
7045.4.34 by Jelmer Vernooij
Fix some more tests.
328
            self.assertIsInstance(ie.file_id, bytes)
2294.1.7 by John Arbash Meinel
Add tests for parent ids in test_test_trees
329
            self.assertEqual(expected[2], ie.parent_id)
330
            if expected[2] is not None:
7045.4.34 by Jelmer Vernooij
Fix some more tests.
331
                self.assertIsInstance(ie.parent_id, bytes)
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
332
            # WorkingTree's return None for the last modified revision
2294.1.7 by John Arbash Meinel
Add tests for parent ids in test_test_trees
333
            if ie.revision is not None:
7045.4.34 by Jelmer Vernooij
Fix some more tests.
334
                self.assertIsInstance(ie.revision, bytes)
2294.1.7 by John Arbash Meinel
Add tests for parent ids in test_test_trees
335
                if expected[0] != '':
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
336
                    # Some trees will preserve the revision id of the tree root,
337
                    # but not all will
2294.1.7 by John Arbash Meinel
Add tests for parent ids in test_test_trees
338
                    self.assertEqual(revision_id, ie.revision)
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
339
        self.assertEqual(len(path_and_ids), len(path_entries))
340
        get_revision_id = getattr(tree, 'get_revision_id', None)
341
        if get_revision_id is not None:
7045.4.34 by Jelmer Vernooij
Fix some more tests.
342
            self.assertIsInstance(get_revision_id(), bytes)
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
343
        last_revision = getattr(tree, 'last_revision', None)
344
        if last_revision is not None:
7045.4.34 by Jelmer Vernooij
Fix some more tests.
345
            self.assertIsInstance(last_revision(), bytes)
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
346
2294.1.2 by John Arbash Meinel
Track down and add tests that all tree.commit() can handle
347
    def test_tree_with_merged_utf8(self):
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
348
        wt = self.make_branch_and_tree('.')
349
350
        self._create_tree_with_utf8(wt)
351
352
        tree2 = wt.controldir.sprout('tree2').open_workingtree()
353
        self.build_tree([u'tree2/ba\N{Euro Sign}r/qu\N{Euro Sign}x'])
354
        if wt.supports_setting_file_ids():
355
            tree2.add([u'ba\N{Euro Sign}r/qu\N{Euro Sign}x'],
356
                      [u'qu\N{Euro Sign}x-id'.encode('utf-8')])
357
        else:
358
            tree2.add([u'ba\N{Euro Sign}r/qu\N{Euro Sign}x'])
359
        if wt.branch.repository._format.supports_setting_revision_ids:
360
            tree2.commit(u'to m\xe9rge', rev_id=u'r\xe9v-2'.encode('utf8'))
361
        else:
362
            tree2.commit(u'to m\xe9rge')
363
7143.15.2 by Jelmer Vernooij
Run autopep8.
364
        self.assertTrue(tree2.is_versioned(
365
            u'ba\N{Euro Sign}r/qu\N{Euro Sign}x'))
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
366
        wt.merge_from_branch(tree2.branch)
367
        self.assertTrue(wt.is_versioned(u'ba\N{Euro Sign}r/qu\N{Euro Sign}x'))
368
369
        if wt.branch.repository._format.supports_setting_revision_ids:
370
            wt.commit(u'm\xe9rge', rev_id=u'r\xe9v-3'.encode('utf8'))
371
        else:
372
            wt.commit(u'm\xe9rge')
373
        tree = self.workingtree_to_test_tree(wt)
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
374
375
        revision_id_1 = u'r\xe9v-1'.encode('utf8')
376
        revision_id_2 = u'r\xe9v-2'.encode('utf8')
6973.13.2 by Jelmer Vernooij
Fix some more tests.
377
        root_id = b'TREE_ROOT'
3638.3.11 by Vincent Ladeuil
Fix failing tests by avoiding unicode combinig encodings (we test
378
        bar_id = u'ba\N{Euro Sign}r-id'.encode('utf8')
379
        foo_id = u'fo\N{Euro Sign}o-id'.encode('utf8')
380
        baz_id = u'ba\N{Euro Sign}z-id'.encode('utf8')
381
        qux_id = u'qu\N{Euro Sign}x-id'.encode('utf8')
2294.1.10 by John Arbash Meinel
Switch all apis over to utf8 file ids. All tests pass
382
        path_and_ids = [(u'', root_id, None, None),
3638.3.11 by Vincent Ladeuil
Fix failing tests by avoiding unicode combinig encodings (we test
383
                        (u'ba\N{Euro Sign}r', bar_id, root_id, revision_id_1),
384
                        (u'fo\N{Euro Sign}o', foo_id, root_id, revision_id_1),
385
                        (u'ba\N{Euro Sign}r/ba\N{Euro Sign}z',
386
                         baz_id, bar_id, revision_id_1),
387
                        (u'ba\N{Euro Sign}r/qu\N{Euro Sign}x',
388
                         qux_id, bar_id, revision_id_2),
7143.15.2 by Jelmer Vernooij
Run autopep8.
389
                        ]
6885.6.1 by Jelmer Vernooij
Support specific_files argument to Tree.iter_entries_by_dir.
390
        with tree.lock_read():
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
391
            path_entries = list(tree.iter_entries_by_dir())
392
3638.3.11 by Vincent Ladeuil
Fix failing tests by avoiding unicode combinig encodings (we test
393
        for (epath, efid, eparent, erev), (path, ie) in zip(path_and_ids,
394
                                                            path_entries):
7143.15.2 by Jelmer Vernooij
Run autopep8.
395
            self.assertEqual(epath, path)  # Paths should match
6973.6.2 by Jelmer Vernooij
Fix more tests.
396
            self.assertIsInstance(path, text_type)
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
397
            self.assertIsInstance(ie.file_id, bytes)
398
            if wt.supports_setting_file_ids():
399
                self.assertEqual(efid, ie.file_id)
400
                self.assertEqual(eparent, ie.parent_id)
3638.3.11 by Vincent Ladeuil
Fix failing tests by avoiding unicode combinig encodings (we test
401
            if eparent is not None:
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
402
                self.assertIsInstance(ie.parent_id, bytes)
403
        self.assertEqual(len(path_and_ids), len(path_entries),
404
                         "%r vs %r" % (
405
                             [p for (p, f, pf, r) in path_and_ids],
406
                             [p for (p, e) in path_entries]))
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
407
        get_revision_id = getattr(tree, 'get_revision_id', None)
408
        if get_revision_id is not None:
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
409
            self.assertIsInstance(get_revision_id(), bytes)
2294.1.3 by John Arbash Meinel
Make sure the inventory enrtries returned are properly formed.
410
        last_revision = getattr(tree, 'last_revision', None)
411
        if last_revision is not None:
6913.1.1 by Jelmer Vernooij
Move utf-8 specific code closer to where it's run, and make foreign branch compatible.
412
            self.assertIsInstance(last_revision(), bytes)
7404.3.1 by Jelmer Vernooij
Add follow_tree_references argument to Tree.iter_entries_by_dir.
413
414
    def skip_if_no_reference(self, tree):
415
        if not getattr(tree, 'supports_tree_reference', lambda: False)():
416
            raise TestNotApplicable('Tree references not supported')
417
418
    def create_nested(self):
419
        work_tree = self.make_branch_and_tree('wt')
420
        with work_tree.lock_write():
421
            self.skip_if_no_reference(work_tree)
422
            subtree = self.make_branch_and_tree('wt/subtree')
423
            self.build_tree(['wt/subtree/a'])
424
            subtree.add(['a'])
425
            subtree.commit('foo')
426
            work_tree.add_reference(subtree)
427
        tree = self._convert_tree(work_tree)
428
        self.skip_if_no_reference(tree)
429
        return tree, subtree
430
431
    def test_iter_entries_with_unfollowed_reference(self):
432
        tree, subtree = self.create_nested()
433
        expected = [
434
            ('', 'directory'),
435
            ('subtree', 'tree-reference')]
436
        with tree.lock_read():
7404.3.2 by Jelmer Vernooij
Merge rename of flag to recurse_nested.
437
            path_entries = list(tree.iter_entries_by_dir(recurse_nested=False))
7404.3.1 by Jelmer Vernooij
Add follow_tree_references argument to Tree.iter_entries_by_dir.
438
            actual = [(path, ie.kind)
439
                      for path, ie in path_entries]
440
        self.assertEqual(expected, actual)
441
442
    def test_iter_entries_with_followed_reference(self):
443
        tree, subtree = self.create_nested()
444
        expected = [
445
            ('', 'directory'),
446
            ('subtree', 'directory'),
447
            ('subtree/a', 'file')]
448
        with tree.lock_read():
7404.3.2 by Jelmer Vernooij
Merge rename of flag to recurse_nested.
449
            path_entries = list(tree.iter_entries_by_dir(recurse_nested=True))
7404.3.1 by Jelmer Vernooij
Add follow_tree_references argument to Tree.iter_entries_by_dir.
450
            actual = [(path, ie.kind)
451
                      for path, ie in path_entries]
452
        self.assertEqual(expected, actual)