220
238
self.intertree_class(tree1, tree2).compare,
221
239
specific_files=['d'],
222
240
require_versioned=True)
243
class TestIterChanges(TestCaseWithTwoTrees):
244
"""Test the comparison iterator"""
246
def test_compare_empty_trees(self):
247
tree1 = self.make_branch_and_tree('1')
248
tree2 = self.make_to_branch_and_tree('2')
249
tree1 = self.get_tree_no_parents_no_content(tree1)
250
tree2 = self.get_to_tree_no_parents_no_content(tree2)
251
self.assertEqual([], list(tree2._iter_changes(tree1)))
253
def added(self, tree, file_id):
254
entry = tree.inventory[file_id]
255
path = tree.id2path(file_id)
256
return (file_id, path, True, (False, True), (None, entry.parent_id),
257
(None, entry.name), (None, entry.kind),
258
(None, entry.executable))
260
def deleted(self, tree, file_id):
261
entry = tree.inventory[file_id]
262
path = tree.id2path(file_id)
263
return (file_id, path, True, (True, False), (entry.parent_id, None),
264
(entry.name, None), (entry.kind, None),
265
(entry.executable, None))
267
def test_empty_to_abc_content(self):
268
tree1 = self.make_branch_and_tree('1')
269
tree2 = self.make_to_branch_and_tree('2')
270
tree1 = self.get_tree_no_parents_no_content(tree1)
271
tree2 = self.get_to_tree_no_parents_abc_content(tree2)
273
self.assertEqual([self.added(tree2, 'root-id'),
274
self.added(tree2, 'a-id'),
275
self.added(tree2, 'b-id'),
276
self.added(tree2, 'c-id'),
277
self.deleted(tree1, 'empty-root-id')],
278
list(tree2._iter_changes(tree1)))
280
def test_empty_to_abc_content_a_only(self):
281
tree1 = self.make_branch_and_tree('1')
282
tree2 = self.make_to_branch_and_tree('2')
283
tree1 = self.get_tree_no_parents_no_content(tree1)
284
tree2 = self.get_to_tree_no_parents_abc_content(tree2)
285
self.assertEqual([self.added(tree2, 'a-id')],
286
list(tree2._iter_changes(tree1,
287
specific_file_ids=['a-id'])))
288
self.assertEqual([self.deleted(tree2, 'a-id')],
289
list(tree1._iter_changes(tree2,
290
specific_file_ids=['a-id'])))
292
def test_empty_to_abc_content_a_and_c_only(self):
293
tree1 = self.make_branch_and_tree('1')
294
tree2 = self.make_to_branch_and_tree('2')
295
tree1 = self.get_tree_no_parents_no_content(tree1)
296
tree2 = self.get_to_tree_no_parents_abc_content(tree2)
297
self.assertEqual([self.added(tree2, 'a-id'),
298
self.added(tree2, 'c-id')],
299
list(tree2._iter_changes(tree1,
300
specific_file_ids=['a-id',
302
d = self.intertree_class(tree1, tree2).compare(
303
specific_files=['a', 'b/c'])
305
def test_abc_content(self):
306
tree1 = self.make_branch_and_tree('1')
307
tree2 = self.make_to_branch_and_tree('2')
308
tree1 = self.get_tree_no_parents_no_content(tree1)
309
tree2 = self.get_to_tree_no_parents_abc_content(tree2)
310
def deleted(file_id):
311
entry = tree2.inventory[file_id]
312
path = tree2.id2path(file_id)
313
return (file_id, path, True, (True, False),
314
(entry.parent_id, None),
315
(entry.name, None), (entry.kind, None),
316
(entry.executable, None))
317
self.assertEqual([self.added(tree1, 'empty-root-id'),
318
deleted('root-id'), deleted('a-id'),
319
deleted('b-id'), deleted('c-id')],
320
list(tree1._iter_changes(tree2)))
322
def test_content_modification(self):
323
tree1 = self.make_branch_and_tree('1')
324
tree2 = self.make_to_branch_and_tree('2')
325
tree1 = self.get_tree_no_parents_abc_content(tree1)
326
tree2 = self.get_to_tree_no_parents_abc_content_2(tree2)
327
root_id = tree1.inventory.root.file_id
328
self.assertEqual([('a-id', 'a', True, (True, True),
329
(root_id, root_id), ('a', 'a'),
330
('file', 'file'), (False, False))],
331
list(tree2._iter_changes(tree1)))
333
def test_meta_modification(self):
334
tree1 = self.make_branch_and_tree('1')
335
tree2 = self.make_to_branch_and_tree('2')
336
tree1 = self.get_tree_no_parents_abc_content(tree1)
337
tree2 = self.get_to_tree_no_parents_abc_content_3(tree2)
338
self.assertEqual([('c-id', 'b/c', False, (True, True),
339
('b-id', 'b-id'), ('c', 'c'), ('file', 'file'),
340
(False, True))], list(tree2._iter_changes(tree1)))
342
def test_file_rename(self):
343
tree1 = self.make_branch_and_tree('1')
344
tree2 = self.make_to_branch_and_tree('2')
345
tree1 = self.get_tree_no_parents_abc_content(tree1)
346
tree2 = self.get_to_tree_no_parents_abc_content_4(tree2)
347
root_id = tree1.inventory.root.file_id
348
self.assertEqual([('a-id', 'd', False, (True, True),
349
(root_id, root_id), ('a', 'd'), ('file', 'file'),
350
(False, False))], list(tree2._iter_changes(tree1)))
352
def test_file_rename_and_modification(self):
353
tree1 = self.make_branch_and_tree('1')
354
tree2 = self.make_to_branch_and_tree('2')
355
tree1 = self.get_tree_no_parents_abc_content(tree1)
356
tree2 = self.get_to_tree_no_parents_abc_content_5(tree2)
357
root_id = tree1.inventory.root.file_id
358
self.assertEqual([('a-id', 'd', True, (True, True),
359
(root_id, root_id), ('a', 'd'), ('file', 'file'),
360
(False, False))], list(tree2._iter_changes(tree1)))
362
def test_file_rename_and_meta_modification(self):
363
tree1 = self.make_branch_and_tree('1')
364
tree2 = self.make_to_branch_and_tree('2')
365
tree1 = self.get_tree_no_parents_abc_content(tree1)
366
tree2 = self.get_to_tree_no_parents_abc_content_6(tree2)
367
root_id = tree1.inventory.root.file_id
368
self.assertEqual([('c-id', 'e', False, (True, True),
369
('b-id', root_id), ('c', 'e'), ('file', 'file'),
370
(False, True))], list(tree2._iter_changes(tree1)))
372
def test_unchanged_with_renames_and_modifications(self):
373
"""want_unchanged should generate a list of unchanged entries."""
374
tree1 = self.make_branch_and_tree('1')
375
tree2 = self.make_to_branch_and_tree('2')
376
tree1 = self.get_tree_no_parents_abc_content(tree1)
377
tree2 = self.get_to_tree_no_parents_abc_content_5(tree2)
378
root_id = tree1.inventory.root.file_id
379
def unchanged(file_id):
380
entry = tree1.inventory[file_id]
381
parent = entry.parent_id
384
executable = entry.executable
385
return (file_id, tree1.id2path(file_id), False, (True, True),
386
(parent, parent), (name, name), (kind, kind),
387
(executable, executable))
388
self.assertEqual([unchanged(root_id), unchanged('b-id'),
389
('a-id', 'd', True, (True, True),
390
(root_id, root_id), ('a', 'd'), ('file', 'file'),
391
(False, False)), unchanged('c-id')],
392
list(tree2._iter_changes(tree1,
393
include_unchanged=True)))