22
22
from bzrlib import (
27
28
from bzrlib.osutils import file_kind, has_symlinks
28
29
from bzrlib.tests import TestNotApplicable
29
from bzrlib.tests.intertree_implementations import TestCaseWithTwoTrees
30
from bzrlib.tests.per_intertree import TestCaseWithTwoTrees
31
32
# TODO: test the include_root option.
32
33
# TODO: test that renaming a directory x->y does not emit a rename for the
371
def check_has_changes(self, expected, tree1, tree2):
372
# has_changes is defined for mutable trees only
373
if not isinstance(tree2, mutabletree.MutableTree):
374
if isinstance(tree1, mutabletree.MutableTree):
375
# Let's switch the trees since has_changes() is commutative
376
# (where we can apply it)
377
tree2, tree1 = tree1, tree2
379
# Neither tree can be used
384
return tree2.has_changes(tree1)
370
389
def mutable_trees_to_locked_test_trees(self, tree1, tree2):
371
390
"""Convert the working trees into test trees.
436
455
tree2 = self.get_tree_no_parents_no_content(tree2)
437
456
tree1, tree2 = self.mutable_trees_to_test_trees(self, tree1, tree2)
438
457
self.assertEqual([], self.do_iter_changes(tree1, tree2))
458
self.check_has_changes(False, tree1, tree2)
440
460
def added(self, tree, file_id):
441
461
path, entry = self.get_path_entry(tree, file_id)
519
539
self.added(tree2, 'c-id'),
520
540
self.deleted(tree1, 'empty-root-id')])
521
541
self.assertEqual(expected_results, self.do_iter_changes(tree1, tree2))
542
self.check_has_changes(True, tree1, tree2)
523
544
def test_empty_specific_files(self):
524
545
tree1 = self.make_branch_and_tree('1')
542
563
self.added(tree2, 'c-id'),
543
564
self.deleted(tree1, 'empty-root-id')])
544
565
self.assertEqual(expected_results, self.do_iter_changes(tree1, tree2))
566
self.check_has_changes(True, tree1, tree2)
546
568
def test_empty_to_abc_content_a_only(self):
547
569
tree1 = self.make_branch_and_tree('1')
593
615
self.assertEqual(
594
616
expected_results,
595
617
self.do_iter_changes(tree1, tree2))
618
self.check_has_changes(True, tree1, tree2)
597
620
def test_content_modification(self):
598
621
tree1 = self.make_branch_and_tree('1')
605
628
(root_id, root_id), ('a', 'a'),
606
629
('file', 'file'), (False, False))],
607
630
self.do_iter_changes(tree1, tree2))
631
self.check_has_changes(True, tree1, tree2)
609
633
def test_meta_modification(self):
610
634
tree1 = self.make_branch_and_tree('1')
834
858
self.content_changed(tree2, 'c-id'),
836
860
self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
861
self.check_has_changes(True, tree1, tree2)
838
863
def test_unversioned_paths_in_tree(self):
839
864
tree1 = self.make_branch_and_tree('tree1')
1051
1076
self.assertEqual(expected,
1052
1077
self.do_iter_changes(tree1, tree2, include_unchanged=True,
1053
1078
want_unversioned=True))
1079
self.check_has_changes(True, tree1, tree2)
1055
1081
def test_versioned_symlinks_specific_files(self):
1056
1082
self.requireFeature(tests.SymlinkFeature)
1072
1098
self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
1073
1099
specific_files=['added', 'changed', 'fromdir', 'fromfile',
1074
1100
'removed', 'unchanged', 'todir', 'tofile']))
1101
self.check_has_changes(True, tree1, tree2)
1076
1103
def test_tree_with_special_names(self):
1077
1104
tree1, tree2, paths, path_ids = self.make_tree_with_special_names()
1078
1105
expected = sorted(self.added(tree2, f_id) for f_id in path_ids)
1079
1106
self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
1107
self.check_has_changes(True, tree1, tree2)
1081
1109
def test_trees_with_special_names(self):
1082
1110
tree1, tree2, paths, path_ids = self.make_trees_with_special_names()
1083
1111
expected = sorted(self.content_changed(tree2, f_id) for f_id in path_ids
1084
1112
if f_id.endswith('_f-id'))
1085
1113
self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
1114
self.check_has_changes(True, tree1, tree2)
1087
1116
def test_trees_with_deleted_dir(self):
1088
1117
tree1 = self.make_branch_and_tree('tree1')
1106
1135
self.deleted(tree1, 'e-id'),
1108
1137
self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
1138
self.check_has_changes(True, tree1, tree2)
1110
1140
def test_added_unicode(self):
1111
1141
tree1 = self.make_branch_and_tree('tree1')
1134
1164
self.assertEqual([self.added(tree2, added_id)],
1135
1165
self.do_iter_changes(tree1, tree2,
1136
1166
specific_files=[u'\u03b1']))
1167
self.check_has_changes(True, tree1, tree2)
1138
1169
def test_deleted_unicode(self):
1139
1170
tree1 = self.make_branch_and_tree('tree1')
1162
1193
self.assertEqual([self.deleted(tree1, deleted_id)],
1163
1194
self.do_iter_changes(tree1, tree2,
1164
1195
specific_files=[u'\u03b1']))
1196
self.check_has_changes(True, tree1, tree2)
1166
1198
def test_modified_unicode(self):
1167
1199
tree1 = self.make_branch_and_tree('tree1')
1191
1223
self.assertEqual([self.content_changed(tree1, mod_id)],
1192
1224
self.do_iter_changes(tree1, tree2,
1193
1225
specific_files=[u'\u03b1']))
1226
self.check_has_changes(True, tree1, tree2)
1195
1228
def test_renamed_unicode(self):
1196
1229
tree1 = self.make_branch_and_tree('tree1')
1221
1254
self.assertEqual([self.renamed(tree1, tree2, rename_id, False)],
1222
1255
self.do_iter_changes(tree1, tree2,
1223
1256
specific_files=[u'\u03b1']))
1257
self.check_has_changes(True, tree1, tree2)
1225
1259
def test_unchanged_unicode(self):
1226
1260
tree1 = self.make_branch_and_tree('tree1')
1309
1343
want_unversioned=True))
1310
1344
self.assertEqual([], # Without want_unversioned we should get nothing
1311
1345
self.do_iter_changes(tree1, tree2))
1346
self.check_has_changes(False, tree1, tree2)
1313
1348
# We should also be able to select just a subset
1314
1349
expected = sorted([
1390
1425
self.assertEqual(expected,
1391
1426
self.do_iter_changes(tree1, tree2))
1427
self.check_has_changes(True, tree1, tree2)
1393
1429
def test_deleted_and_unknown(self):
1394
1430
"""Test a file marked removed, but still present on disk."""