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')
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')
733
757
(None, root_id), (None, 'file'), (None, None), (None, False))]
734
758
self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
760
def test_only_in_target_missing_subtree_specific_bug_367632(self):
761
tree1 = self.make_branch_and_tree('tree1')
762
tree2 = self.make_to_branch_and_tree('tree2')
763
tree2.set_root_id(tree1.get_root_id())
764
self.build_tree(['tree2/a-dir/', 'tree2/a-dir/a-file'])
765
tree2.add(['a-dir', 'a-dir/a-file'], ['dir-id', 'file-id'])
766
os.unlink('tree2/a-dir/a-file')
767
os.rmdir('tree2/a-dir')
768
tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
769
self.not_applicable_if_missing_in('a-dir', tree2)
770
root_id = tree1.path2id('')
772
('dir-id', (None, 'a-dir'), False, (False, True),
773
(None, root_id), (None, 'a-dir'), (None, None), (None, False)),
774
('file-id', (None, 'a-dir/a-file'), False, (False, True),
775
(None, 'dir-id'), (None, 'a-file'), (None, None), (None, False))
777
# bug 367632 showed that specifying the root broke some code paths,
778
# so we check this contract with and without it.
779
self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
780
self.assertEqual(expected,
781
self.do_iter_changes(tree1, tree2, specific_files=['']))
736
783
def test_unchanged_with_renames_and_modifications(self):
737
784
"""want_unchanged should generate a list of unchanged entries."""
738
785
tree1 = self.make_branch_and_tree('1')
741
788
tree2 = self.get_tree_no_parents_abc_content_5(tree2)
742
789
tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
743
790
root_id = tree1.path2id('')
745
791
self.assertEqual(sorted([self.unchanged(tree1, root_id),
746
792
self.unchanged(tree1, 'b-id'),
747
793
('a-id', ('a', 'd'), True, (True, True),
834
880
self.content_changed(tree2, 'c-id'),
836
882
self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
883
self.check_has_changes(True, tree1, tree2)
838
885
def test_unversioned_paths_in_tree(self):
839
886
tree1 = self.make_branch_and_tree('tree1')
1051
1098
self.assertEqual(expected,
1052
1099
self.do_iter_changes(tree1, tree2, include_unchanged=True,
1053
1100
want_unversioned=True))
1101
self.check_has_changes(True, tree1, tree2)
1055
1103
def test_versioned_symlinks_specific_files(self):
1056
1104
self.requireFeature(tests.SymlinkFeature)
1072
1120
self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
1073
1121
specific_files=['added', 'changed', 'fromdir', 'fromfile',
1074
1122
'removed', 'unchanged', 'todir', 'tofile']))
1123
self.check_has_changes(True, tree1, tree2)
1076
1125
def test_tree_with_special_names(self):
1077
1126
tree1, tree2, paths, path_ids = self.make_tree_with_special_names()
1078
1127
expected = sorted(self.added(tree2, f_id) for f_id in path_ids)
1079
1128
self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
1129
self.check_has_changes(True, tree1, tree2)
1081
1131
def test_trees_with_special_names(self):
1082
1132
tree1, tree2, paths, path_ids = self.make_trees_with_special_names()
1083
1133
expected = sorted(self.content_changed(tree2, f_id) for f_id in path_ids
1084
1134
if f_id.endswith('_f-id'))
1085
1135
self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
1136
self.check_has_changes(True, tree1, tree2)
1087
1138
def test_trees_with_deleted_dir(self):
1088
1139
tree1 = self.make_branch_and_tree('tree1')
1106
1157
self.deleted(tree1, 'e-id'),
1108
1159
self.assertEqual(expected, self.do_iter_changes(tree1, tree2))
1160
self.check_has_changes(True, tree1, tree2)
1110
1162
def test_added_unicode(self):
1111
1163
tree1 = self.make_branch_and_tree('tree1')
1134
1186
self.assertEqual([self.added(tree2, added_id)],
1135
1187
self.do_iter_changes(tree1, tree2,
1136
1188
specific_files=[u'\u03b1']))
1189
self.check_has_changes(True, tree1, tree2)
1138
1191
def test_deleted_unicode(self):
1139
1192
tree1 = self.make_branch_and_tree('tree1')
1162
1215
self.assertEqual([self.deleted(tree1, deleted_id)],
1163
1216
self.do_iter_changes(tree1, tree2,
1164
1217
specific_files=[u'\u03b1']))
1218
self.check_has_changes(True, tree1, tree2)
1166
1220
def test_modified_unicode(self):
1167
1221
tree1 = self.make_branch_and_tree('tree1')
1191
1245
self.assertEqual([self.content_changed(tree1, mod_id)],
1192
1246
self.do_iter_changes(tree1, tree2,
1193
1247
specific_files=[u'\u03b1']))
1248
self.check_has_changes(True, tree1, tree2)
1195
1250
def test_renamed_unicode(self):
1196
1251
tree1 = self.make_branch_and_tree('tree1')
1221
1276
self.assertEqual([self.renamed(tree1, tree2, rename_id, False)],
1222
1277
self.do_iter_changes(tree1, tree2,
1223
1278
specific_files=[u'\u03b1']))
1279
self.check_has_changes(True, tree1, tree2)
1225
1281
def test_unchanged_unicode(self):
1226
1282
tree1 = self.make_branch_and_tree('tree1')
1309
1365
want_unversioned=True))
1310
1366
self.assertEqual([], # Without want_unversioned we should get nothing
1311
1367
self.do_iter_changes(tree1, tree2))
1368
self.check_has_changes(False, tree1, tree2)
1313
1370
# We should also be able to select just a subset
1314
1371
expected = sorted([
1390
1447
self.assertEqual(expected,
1391
1448
self.do_iter_changes(tree1, tree2))
1449
self.check_has_changes(True, tree1, tree2)
1393
1451
def test_deleted_and_unknown(self):
1394
1452
"""Test a file marked removed, but still present on disk."""