~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transform.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-10-14 03:18:36 UTC
  • mfrom: (3363.17.29 merge-into2)
  • Revision ID: pqm@pqm.ubuntu.com-20081014031836-0pn8u98igc7gvtv0
Allow merging into PreviewTrees

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
                              resolve_conflicts, cook_conflicts, 
54
54
                              build_tree, get_backup_name,
55
55
                              _FileMover, resolve_checkout,
56
 
                              TransformPreview)
 
56
                              TransformPreview, create_from_tree)
57
57
 
58
58
class TestTreeTransform(tests.TestCaseWithTransport):
59
59
 
1313
1313
        transform.cancel_creation(trans_id)
1314
1314
        transform.apply()
1315
1315
 
 
1316
    def test_create_from_tree(self):
 
1317
        tree1 = self.make_branch_and_tree('tree1')
 
1318
        self.build_tree_contents([('tree1/foo/',), ('tree1/bar', 'baz')])
 
1319
        tree1.add(['foo', 'bar'], ['foo-id', 'bar-id'])
 
1320
        tree2 = self.make_branch_and_tree('tree2')
 
1321
        tt = TreeTransform(tree2)
 
1322
        foo_trans_id = tt.create_path('foo', tt.root)
 
1323
        create_from_tree(tt, foo_trans_id, tree1, 'foo-id')
 
1324
        bar_trans_id = tt.create_path('bar', tt.root)
 
1325
        create_from_tree(tt, bar_trans_id, tree1, 'bar-id')
 
1326
        tt.apply()
 
1327
        self.assertEqual('directory', osutils.file_kind('tree2/foo'))
 
1328
        self.assertFileEqual('baz', 'tree2/bar')
 
1329
 
 
1330
    def test_create_from_tree_bytes(self):
 
1331
        """Provided lines are used instead of tree content."""
 
1332
        tree1 = self.make_branch_and_tree('tree1')
 
1333
        self.build_tree_contents([('tree1/foo', 'bar'),])
 
1334
        tree1.add('foo', 'foo-id')
 
1335
        tree2 = self.make_branch_and_tree('tree2')
 
1336
        tt = TreeTransform(tree2)
 
1337
        foo_trans_id = tt.create_path('foo', tt.root)
 
1338
        create_from_tree(tt, foo_trans_id, tree1, 'foo-id', bytes='qux')
 
1339
        tt.apply()
 
1340
        self.assertFileEqual('qux', 'tree2/foo')
 
1341
 
 
1342
    def test_create_from_tree_symlink(self):
 
1343
        self.requireFeature(SymlinkFeature)
 
1344
        tree1 = self.make_branch_and_tree('tree1')
 
1345
        os.symlink('bar', 'tree1/foo')
 
1346
        tree1.add('foo', 'foo-id')
 
1347
        tt = TreeTransform(self.make_branch_and_tree('tree2'))
 
1348
        foo_trans_id = tt.create_path('foo', tt.root)
 
1349
        create_from_tree(tt, foo_trans_id, tree1, 'foo-id')
 
1350
        tt.apply()
 
1351
        self.assertEqual('bar', os.readlink('tree2/foo'))
 
1352
 
1316
1353
 
1317
1354
class TransformGroup(object):
1318
1355
 
2497
2534
        self.addCleanup(tt.finalize)
2498
2535
        final_tree = tt.get_preview_tree()
2499
2536
        self.assertEqual('a\nb\nc\n', final_tree.get_file_text('file-id'))
 
2537
 
 
2538
    def test_merge_preview_into_workingtree(self):
 
2539
        tree = self.make_branch_and_tree('tree')
 
2540
        tt = TransformPreview(tree)
 
2541
        self.addCleanup(tt.finalize)
 
2542
        tt.new_file('name', tt.root, 'content', 'file-id')
 
2543
        tree2 = self.make_branch_and_tree('tree2')
 
2544
        pb = progress.DummyProgress()
 
2545
        merger = Merger.from_uncommitted(tree2, tt.get_preview_tree(),
 
2546
                                         pb, tree.basis_tree())
 
2547
        merger.merge_type = Merge3Merger
 
2548
        merger.do_merge()
 
2549
 
 
2550
    def test_merge_preview_into_workingtree_handles_conflicts(self):
 
2551
        tree = self.make_branch_and_tree('tree')
 
2552
        self.build_tree_contents([('tree/foo', 'bar')])
 
2553
        tree.add('foo', 'foo-id')
 
2554
        tree.commit('foo')
 
2555
        tt = TransformPreview(tree)
 
2556
        self.addCleanup(tt.finalize)
 
2557
        trans_id = tt.trans_id_file_id('foo-id')
 
2558
        tt.delete_contents(trans_id)
 
2559
        tt.create_file('baz', trans_id)
 
2560
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
 
2561
        self.build_tree_contents([('tree2/foo', 'qux')])
 
2562
        pb = progress.DummyProgress()
 
2563
        merger = Merger.from_uncommitted(tree2, tt.get_preview_tree(),
 
2564
                                         pb, tree.basis_tree())
 
2565
        merger.merge_type = Merge3Merger
 
2566
        merger.do_merge()
 
2567
 
 
2568
    def test_is_executable(self):
 
2569
        tree = self.make_branch_and_tree('tree')
 
2570
        preview = TransformPreview(tree)
 
2571
        self.addCleanup(preview.finalize)
 
2572
        preview.new_file('foo', preview.root, 'bar', 'baz-id')
 
2573
        preview_tree = preview.get_preview_tree()
 
2574
        self.assertEqual(False, preview_tree.is_executable('baz-id',
 
2575
                                                           'tree/foo'))
 
2576
        self.assertEqual(False, preview_tree.is_executable('baz-id'))