162
168
self.addCleanup(tree.unlock)
163
169
self.assertEqual([], tree.get_parent_ids())
164
170
self.assertEqual([], tree.conflicts())
165
self.assertEqual([], list(tree.unknowns()))
171
if tree.has_versioned_directories():
172
self.assertEqual([], list(tree.unknowns()))
174
self.assertEqual(['1top-dir/1dir-in-1topdir'], list(tree.unknowns()))
166
175
# __iter__ has no strongly defined order
167
176
tree_root = tree.path2id('')
169
{tree.path2id(p) for p in [
170
'', '0file', '1top-dir', '1top-dir/1dir-in-1topdir',
171
'1top-dir/0file-in-1topdir', 'symlink', u'2utf\u1234file']},
172
set(tree.all_file_ids()))
173
# note that the order of the paths and fileids is deliberately
174
# mismatched to ensure that the result order is path based.
178
('1top-dir', 'directory'),
179
(u'2utf\u1234file', 'file'),
180
('symlink', 'symlink'),
181
('1top-dir/0file-in-1topdir', 'file'),
182
('1top-dir/1dir-in-1topdir', 'directory')],
183
[(path, node.kind) for path, node in tree.iter_entries_by_dir()])
177
if tree.has_versioned_directories():
179
{tree.path2id(p) for p in [
180
'', '0file', '1top-dir', '1top-dir/1dir-in-1topdir',
181
'1top-dir/0file-in-1topdir', 'symlink', u'2utf\u1234file']},
182
set(tree.all_file_ids()))
183
# note that the order of the paths and fileids is deliberately
184
# mismatched to ensure that the result order is path based.
188
('1top-dir', 'directory'),
189
(u'2utf\u1234file', 'file'),
190
('symlink', 'symlink'),
191
('1top-dir/0file-in-1topdir', 'file'),
192
('1top-dir/1dir-in-1topdir', 'directory')],
193
[(path, node.kind) for path, node in tree.iter_entries_by_dir()])
196
{tree.path2id(p) for p in [
197
'', '0file', '1top-dir',
198
'1top-dir/0file-in-1topdir', 'symlink', u'2utf\u1234file']},
199
set(tree.all_file_ids()))
200
# note that the order of the paths and fileids is deliberately
201
# mismatched to ensure that the result order is path based.
205
('1top-dir', 'directory'),
206
(u'2utf\u1234file', 'file'),
207
('symlink', 'symlink'),
208
('1top-dir/0file-in-1topdir', 'file')],
209
[(path, node.kind) for path, node in tree.iter_entries_by_dir()])
185
211
def test_tree_with_subdirs_and_all_content_types_wo_symlinks(self):
186
212
# currently this test tree requires unicode. It might be good
191
217
self.addCleanup(tree.unlock)
192
218
self.assertEqual([], tree.get_parent_ids())
193
219
self.assertEqual([], tree.conflicts())
194
self.assertEqual([], list(tree.unknowns()))
220
if tree.has_versioned_directories():
221
self.assertEqual([], list(tree.unknowns()))
223
self.assertEqual(['1top-dir/1dir-in-1topdir'], list(tree.unknowns()))
195
224
# __iter__ has no strongly defined order
196
225
tree_root = tree.path2id('')
198
{'', '0file', '1top-dir', '1top-dir/0file-in-1topdir',
199
'1top-dir/1dir-in-1topdir', u'2utf\u1234file'},
200
set(tree.all_versioned_paths()))
201
# note that the order of the paths and fileids is deliberately
202
# mismatched to ensure that the result order is path based.
206
('1top-dir', 'directory'),
207
(u'2utf\u1234file', 'file'),
208
('1top-dir/0file-in-1topdir', 'file'),
209
('1top-dir/1dir-in-1topdir', 'directory')],
210
[(path, node.kind) for path, node in tree.iter_entries_by_dir()])
226
if tree.has_versioned_directories():
228
{'', '0file', '1top-dir', '1top-dir/0file-in-1topdir',
229
'1top-dir/1dir-in-1topdir', u'2utf\u1234file'},
230
set(tree.all_versioned_paths()))
231
# note that the order of the paths and fileids is deliberately
232
# mismatched to ensure that the result order is path based.
236
('1top-dir', 'directory'),
237
(u'2utf\u1234file', 'file'),
238
('1top-dir/0file-in-1topdir', 'file'),
239
('1top-dir/1dir-in-1topdir', 'directory')],
240
[(path, node.kind) for path, node in tree.iter_entries_by_dir()])
243
{'', '0file', '1top-dir', '1top-dir/0file-in-1topdir',
245
set(tree.all_versioned_paths()))
246
# note that the order of the paths and fileids is deliberately
247
# mismatched to ensure that the result order is path based.
251
('1top-dir', 'directory'),
252
(u'2utf\u1234file', 'file'),
253
('1top-dir/0file-in-1topdir', 'file')],
254
[(path, node.kind) for path, node in tree.iter_entries_by_dir()])
256
def _create_tree_with_utf8(self, tree):
257
self.requireFeature(features.UnicodeFilenameFeature)
259
# We avoid combining characters in file names here, normalization
260
# checks (as performed by some file systems (OSX) are outside the scope
261
# of these tests). We use the euro sign \N{Euro Sign} or \u20ac in
262
# unicode strings or '\xe2\x82\ac' (its utf-8 encoding) in raw strings.
265
u'ba\N{Euro Sign}r/',
266
u'ba\N{Euro Sign}r/ba\N{Euro Sign}z',
268
# bzr itself does not create unicode file ids, but we want them for
270
file_ids = ['TREE_ROOT',
271
'fo\xe2\x82\xaco-id',
272
'ba\xe2\x82\xacr-id',
273
'ba\xe2\x82\xacz-id',
275
self.build_tree(paths[1:])
276
if tree.get_root_id() is None:
277
# Some trees do not have a root yet.
278
tree.add(paths, file_ids)
280
# Some trees will already have a root
281
if tree.supports_setting_file_ids():
282
tree.set_root_id(file_ids[0])
283
tree.add(paths[1:], file_ids[1:])
286
if tree.branch.repository._format.supports_setting_revision_ids:
288
tree.commit(u'in\xedtial', rev_id=u'r\xe9v-1'.encode('utf8'))
289
except errors.NonAsciiRevisionId:
290
raise TestSkipped('non-ascii revision ids not supported')
292
tree.commit(u'in\xedtial')
212
296
def test_tree_with_utf8(self):
213
297
tree = self.make_branch_and_tree('.')
214
tree = self.get_tree_with_utf8(tree)
298
if not tree.supports_setting_file_ids():
299
raise TestNotApplicable(
300
'format does not support custom file ids')
301
self._create_tree_with_utf8(tree)
303
tree = self.workingtree_to_test_tree(tree)
216
305
revision_id = u'r\xe9v-1'.encode('utf8')
217
306
root_id = 'TREE_ROOT'
254
340
self.assertIsInstance(last_revision(), str)
256
342
def test_tree_with_merged_utf8(self):
257
tree = self.make_branch_and_tree('.')
258
tree = self.get_tree_with_merged_utf8(tree)
343
wt = self.make_branch_and_tree('.')
345
self._create_tree_with_utf8(wt)
347
tree2 = wt.controldir.sprout('tree2').open_workingtree()
348
self.build_tree([u'tree2/ba\N{Euro Sign}r/qu\N{Euro Sign}x'])
349
if wt.supports_setting_file_ids():
350
tree2.add([u'ba\N{Euro Sign}r/qu\N{Euro Sign}x'],
351
[u'qu\N{Euro Sign}x-id'.encode('utf-8')])
353
tree2.add([u'ba\N{Euro Sign}r/qu\N{Euro Sign}x'])
354
if wt.branch.repository._format.supports_setting_revision_ids:
355
tree2.commit(u'to m\xe9rge', rev_id=u'r\xe9v-2'.encode('utf8'))
357
tree2.commit(u'to m\xe9rge')
359
self.assertTrue(tree2.is_versioned(u'ba\N{Euro Sign}r/qu\N{Euro Sign}x'))
360
wt.merge_from_branch(tree2.branch)
361
self.assertTrue(wt.is_versioned(u'ba\N{Euro Sign}r/qu\N{Euro Sign}x'))
363
if wt.branch.repository._format.supports_setting_revision_ids:
364
wt.commit(u'm\xe9rge', rev_id=u'r\xe9v-3'.encode('utf8'))
366
wt.commit(u'm\xe9rge')
367
tree = self.workingtree_to_test_tree(wt)
260
369
revision_id_1 = u'r\xe9v-1'.encode('utf8')
261
370
revision_id_2 = u'r\xe9v-2'.encode('utf8')
272
381
(u'ba\N{Euro Sign}r/qu\N{Euro Sign}x',
273
382
qux_id, bar_id, revision_id_2),
384
with tree.lock_read():
277
385
path_entries = list(tree.iter_entries_by_dir())
281
387
for (epath, efid, eparent, erev), (path, ie) in zip(path_and_ids,
283
389
self.assertEqual(epath, path) # Paths should match
284
390
self.assertIsInstance(path, unicode)
285
self.assertEqual(efid, ie.file_id)
286
self.assertIsInstance(ie.file_id, str)
287
self.assertEqual(eparent, ie.parent_id)
391
self.assertIsInstance(ie.file_id, bytes)
392
if wt.supports_setting_file_ids():
393
self.assertEqual(efid, ie.file_id)
394
self.assertEqual(eparent, ie.parent_id)
288
395
if eparent is not None:
289
self.assertIsInstance(ie.parent_id, str)
290
# WorkingTree's return None for the last modified revision
291
if ie.revision is not None:
292
self.assertIsInstance(ie.revision, str)
294
# Some trees will preserve the revision id of the tree root,
297
self.assertEqual(erev, ie.revision)
298
self.assertEqual(len(path_and_ids), len(path_entries))
396
self.assertIsInstance(ie.parent_id, bytes)
397
self.assertEqual(len(path_and_ids), len(path_entries),
399
[p for (p, f, pf, r) in path_and_ids],
400
[p for (p, e) in path_entries]))
299
401
get_revision_id = getattr(tree, 'get_revision_id', None)
300
402
if get_revision_id is not None:
301
self.assertIsInstance(get_revision_id(), str)
403
self.assertIsInstance(get_revision_id(), bytes)
302
404
last_revision = getattr(tree, 'last_revision', None)
303
405
if last_revision is not None:
304
self.assertIsInstance(last_revision(), str)
406
self.assertIsInstance(last_revision(), bytes)