~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/intertree_implementations/test_compare.py

  • Committer: John Arbash Meinel
  • Date: 2007-04-28 15:04:17 UTC
  • mfrom: (2466 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2566.
  • Revision ID: john@arbash-meinel.com-20070428150417-trp3pi0pzd411pu4
[merge] bzr.dev 2466

Show diffs side-by-side

added added

removed removed

Lines of Context:
321
321
        tree2 = self.make_to_branch_and_tree('tree2')
322
322
        tree2.set_root_id(tree1.get_root_id())
323
323
        self.build_tree(['tree2/file', 'tree2/dir/'])
324
 
        # try:
325
 
        os.symlink('target', 'tree2/link')
326
 
        links_supported = True
327
 
        # except ???:
328
 
        #   links_supported = False
 
324
        if has_symlinks():
 
325
            os.symlink('target', 'tree2/link')
 
326
            links_supported = True
 
327
        else:
 
328
            links_supported = False
329
329
        tree1, tree2 = self.mutable_trees_to_test_trees(tree1, tree2)
330
330
        d = self.intertree_class(tree1, tree2).compare(want_unversioned=True)
331
331
        self.assertEqual([], d.added)
333
333
        self.assertEqual([], d.removed)
334
334
        self.assertEqual([], d.renamed)
335
335
        self.assertEqual([], d.unchanged)
336
 
        self.assertEqual([(u'dir', None, 'directory'), (u'file', None, 'file'),
337
 
            (u'link', None, 'symlink')], d.unversioned)
 
336
        expected_unversioned = [(u'dir', None, 'directory'),
 
337
                                (u'file', None, 'file')]
 
338
        if links_supported:
 
339
            expected_unversioned.append((u'link', None, 'symlink'))
 
340
        self.assertEqual(expected_unversioned, d.unversioned)
338
341
 
339
342
 
340
343
class TestIterChanges(TestCaseWithTwoTrees):
776
779
        tree2 = self.make_to_branch_and_tree('tree2')
777
780
        tree2.set_root_id(tree1.get_root_id())
778
781
        self.build_tree(['tree2/file', 'tree2/dir/'])
779
 
        # try:
780
 
        os.symlink('target', 'tree2/link')
781
 
        links_supported = True
782
 
        # except ???:
783
 
        #   links_supported = False
 
782
        if has_symlinks():
 
783
            os.symlink('target', 'tree2/link')
 
784
            links_supported = True
 
785
        else:
 
786
            links_supported = False
784
787
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
785
788
        expected = [
786
789
            self.unversioned(tree2, 'file'),
796
799
        tree1 = self.make_branch_and_tree('tree1')
797
800
        tree2 = self.make_to_branch_and_tree('tree2')
798
801
        self.build_tree(['tree2/file', 'tree2/dir/'])
799
 
        # try:
800
 
        os.symlink('target', 'tree2/link')
801
 
        links_supported = True
802
 
        # except ???:
803
 
        #   links_supported = False
 
802
        if has_symlinks():
 
803
            os.symlink('target', 'tree2/link')
 
804
            links_supported = True
 
805
        else:
 
806
            links_supported = False
804
807
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
805
808
        expected = [
806
809
            self.unversioned(tree2, 'file'),
829
832
        self.build_tree(['tree2/file', 'tree2/dir/',
830
833
            'tree1/file', 'tree2/movedfile',
831
834
            'tree1/dir/', 'tree2/moveddir/'])
832
 
        # try:
833
 
        os.symlink('target', 'tree1/link')
834
 
        os.symlink('target', 'tree2/link')
835
 
        os.symlink('target', 'tree2/movedlink')
836
 
        links_supported = True
837
 
        # except ???:
838
 
        #   links_supported = False
839
 
        tree1.add(['file', 'dir', 'link'], ['file-id', 'dir-id', 'link-id'])
840
 
        tree2.add(['movedfile', 'moveddir', 'movedlink'],
841
 
            ['file-id', 'dir-id', 'link-id'])
 
835
        if has_symlinks():
 
836
            os.symlink('target', 'tree1/link')
 
837
            os.symlink('target', 'tree2/link')
 
838
            os.symlink('target', 'tree2/movedlink')
 
839
            links_supported = True
 
840
        else:
 
841
            links_supported = False
 
842
        tree1.add(['file', 'dir'], ['file-id', 'dir-id'])
 
843
        tree2.add(['movedfile', 'moveddir'], ['file-id', 'dir-id'])
 
844
        if links_supported:
 
845
            tree1.add(['link'], ['link-id'])
 
846
            tree2.add(['movedlink'], ['link-id'])
842
847
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
843
848
        root_id = tree1.path2id('')
844
849
        expected = [
1211
1216
        self.assertEqual([], # Without want_unversioned we should get nothing
1212
1217
                         self.do_iter_changes(tree1, tree2,
1213
1218
                                              specific_files=[u'\u03b1']))
 
1219
 
 
1220
    def test_unknown_empty_dir(self):
 
1221
        tree1 = self.make_branch_and_tree('tree1')
 
1222
        tree2 = self.make_to_branch_and_tree('tree2')
 
1223
        root_id = tree1.get_root_id()
 
1224
        tree2.set_root_id(root_id)
 
1225
 
 
1226
        # Start with 2 identical trees
 
1227
        self.build_tree(['tree1/a/', 'tree1/b/',
 
1228
                         'tree2/a/', 'tree2/b/'])
 
1229
        self.build_tree_contents([('tree1/b/file', 'contents\n'),
 
1230
                                  ('tree2/b/file', 'contents\n')])
 
1231
        tree1.add(['a', 'b', 'b/file'], ['a-id', 'b-id', 'b-file-id'])
 
1232
        tree2.add(['a', 'b', 'b/file'], ['a-id', 'b-id', 'b-file-id'])
 
1233
 
 
1234
        # Now create some unknowns in tree2
 
1235
        # We should find both a/file and a/dir as unknown, but we shouldn't
 
1236
        # recurse into a/dir to find that a/dir/subfile is also unknown.
 
1237
        self.build_tree(['tree2/a/file', 'tree2/a/dir/', 'tree2/a/dir/subfile'])
 
1238
 
 
1239
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
 
1240
 
 
1241
        expected = sorted([
 
1242
            self.unversioned(tree2, u'a/file'),
 
1243
            self.unversioned(tree2, u'a/dir'),
 
1244
            ])
 
1245
        self.assertEqual(expected,
 
1246
                         self.do_iter_changes(tree1, tree2,
 
1247
                                              require_versioned=False,
 
1248
                                              want_unversioned=True))
 
1249
 
 
1250
    def test_rename_over_deleted(self):
 
1251
        tree1 = self.make_branch_and_tree('tree1')
 
1252
        tree2 = self.make_to_branch_and_tree('tree2')
 
1253
        root_id = tree1.get_root_id()
 
1254
        tree2.set_root_id(root_id)
 
1255
 
 
1256
        # The final changes should be:
 
1257
        #   touch a b c d
 
1258
        #   add a b c d
 
1259
        #   commit
 
1260
        #   rm a d
 
1261
        #   mv b a
 
1262
        #   mv c d
 
1263
        self.build_tree_contents([
 
1264
            ('tree1/a', 'a contents\n'),
 
1265
            ('tree1/b', 'b contents\n'),
 
1266
            ('tree1/c', 'c contents\n'),
 
1267
            ('tree1/d', 'd contents\n'),
 
1268
            ('tree2/a', 'b contents\n'),
 
1269
            ('tree2/d', 'c contents\n'),
 
1270
            ])
 
1271
        tree1.add(['a', 'b', 'c', 'd'], ['a-id', 'b-id', 'c-id', 'd-id'])
 
1272
        tree2.add(['a', 'd'], ['b-id', 'c-id'])
 
1273
 
 
1274
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
 
1275
 
 
1276
        expected = sorted([
 
1277
            self.deleted(tree1, 'a-id'),
 
1278
            self.deleted(tree1, 'd-id'),
 
1279
            self.renamed(tree1, tree2, 'b-id', False),
 
1280
            self.renamed(tree1, tree2, 'c-id', False),
 
1281
            ])
 
1282
        self.assertEqual(expected,
 
1283
                         self.do_iter_changes(tree1, tree2))
 
1284
 
 
1285
    def test_deleted_and_unknown(self):
 
1286
        """Test a file marked removed, but still present on disk."""
 
1287
        tree1 = self.make_branch_and_tree('tree1')
 
1288
        tree2 = self.make_to_branch_and_tree('tree2')
 
1289
        root_id = tree1.get_root_id()
 
1290
        tree2.set_root_id(root_id)
 
1291
 
 
1292
        # The final changes should be:
 
1293
        # bzr add a b c
 
1294
        # bzr rm --keep b
 
1295
        self.build_tree_contents([
 
1296
            ('tree1/a', 'a contents\n'),
 
1297
            ('tree1/b', 'b contents\n'),
 
1298
            ('tree1/c', 'c contents\n'),
 
1299
            ('tree2/a', 'a contents\n'),
 
1300
            ('tree2/b', 'b contents\n'),
 
1301
            ('tree2/c', 'c contents\n'),
 
1302
            ])
 
1303
        tree1.add(['a', 'b', 'c'], ['a-id', 'b-id', 'c-id'])
 
1304
        tree2.add(['a', 'c'], ['a-id', 'c-id'])
 
1305
 
 
1306
        tree1, tree2 = self.mutable_trees_to_locked_test_trees(tree1, tree2)
 
1307
 
 
1308
        expected = sorted([
 
1309
            self.deleted(tree1, 'b-id'),
 
1310
            self.unversioned(tree2, 'b'),
 
1311
            ])
 
1312
        self.assertEqual(expected,
 
1313
                         self.do_iter_changes(tree1, tree2,
 
1314
                                              want_unversioned=True))
 
1315
        expected = sorted([
 
1316
            self.deleted(tree1, 'b-id'),
 
1317
            ])
 
1318
        self.assertEqual(expected,
 
1319
                         self.do_iter_changes(tree1, tree2,
 
1320
                                              want_unversioned=False))