~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_merge.py

  • Committer: Patch Queue Manager
  • Date: 2011-09-22 14:12:18 UTC
  • mfrom: (6155.3.1 jam)
  • Revision ID: pqm@pqm.ubuntu.com-20110922141218-86s4uu6nqvourw4f
(jameinel) Cleanup comments bzrlib/smart/__init__.py (John A Meinel)

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
from bzrlib.merge import transform_tree, merge_inner, _PlanMerge
38
38
from bzrlib.osutils import basename, pathjoin, file_kind
39
39
from bzrlib.tests import (
 
40
    features,
40
41
    TestCaseWithMemoryTransport,
41
42
    TestCaseWithTransport,
42
43
    test_merge_core,
90
91
        os.chdir('branch2')
91
92
        self.run_bzr('merge ../branch1/baz', retcode=3)
92
93
        self.run_bzr('merge ../branch1/foo')
93
 
        self.failUnlessExists('foo')
94
 
        self.failIfExists('bar')
 
94
        self.assertPathExists('foo')
 
95
        self.assertPathDoesNotExist('bar')
95
96
        wt2 = WorkingTree.open('.') # opens branch2
96
97
        self.assertEqual([tip], wt2.get_parent_ids())
97
98
 
121
122
        finally:
122
123
            wt1.unlock()
123
124
 
 
125
    def test_merge_into_null_tree(self):
 
126
        wt = self.make_branch_and_tree('tree')
 
127
        null_tree = wt.basis_tree()
 
128
        self.build_tree(['tree/file'])
 
129
        wt.add('file')
 
130
        wt.commit('tree with root')
 
131
        merger = _mod_merge.Merge3Merger(null_tree, null_tree, null_tree, wt,
 
132
                                         this_branch=wt.branch,
 
133
                                         do_merge=False)
 
134
        with merger.make_preview_transform() as tt:
 
135
            self.assertEqual([], tt.find_conflicts())
 
136
            preview = tt.get_preview_tree()
 
137
            self.assertEqual(wt.get_root_id(), preview.get_root_id())
 
138
 
 
139
    def test_merge_unrelated_retains_root(self):
 
140
        wt = self.make_branch_and_tree('tree')
 
141
        other_tree = self.make_branch_and_tree('other')
 
142
        self.addCleanup(other_tree.lock_read().unlock)
 
143
        merger = _mod_merge.Merge3Merger(wt, wt, wt.basis_tree(), other_tree,
 
144
                                         this_branch=wt.branch,
 
145
                                         do_merge=False)
 
146
        with transform.TransformPreview(wt) as merger.tt:
 
147
            merger._compute_transform()
 
148
            new_root_id = merger.tt.final_file_id(merger.tt.root)
 
149
            self.assertEqual(wt.get_root_id(), new_root_id)
 
150
 
124
151
    def test_create_rename(self):
125
152
        """Rename an inventory entry while creating the file"""
126
153
        tree =self.make_branch_and_tree('.')
157
184
        log = StringIO()
158
185
        merge_inner(tree_b.branch, tree_a, tree_b.basis_tree(),
159
186
                    this_tree=tree_b, ignore_zero=True)
160
 
        self.failUnless('All changes applied successfully.\n' not in
 
187
        self.assertTrue('All changes applied successfully.\n' not in
161
188
            self.get_log())
162
189
        tree_b.revert()
163
190
        merge_inner(tree_b.branch, tree_a, tree_b.basis_tree(),
164
191
                    this_tree=tree_b, ignore_zero=False)
165
 
        self.failUnless('All changes applied successfully.\n' in self.get_log())
 
192
        self.assertTrue('All changes applied successfully.\n' in self.get_log())
166
193
 
167
194
    def test_merge_inner_conflicts(self):
168
195
        tree_a = self.make_branch_and_tree('a')
387
414
                             '>>>>>>> MERGE-SOURCE\n',
388
415
                             'this/file')
389
416
 
 
417
    def test_merge_reverse_revision_range(self):
 
418
        tree = self.make_branch_and_tree(".")
 
419
        tree.lock_write()
 
420
        self.addCleanup(tree.unlock)
 
421
        self.build_tree(['a'])
 
422
        tree.add('a')
 
423
        tree.commit("added a")
 
424
        first_rev = tree.branch.revision_history()[0]
 
425
        merger = _mod_merge.Merger.from_revision_ids(None, tree,
 
426
                                          _mod_revision.NULL_REVISION,
 
427
                                          first_rev)
 
428
        merger.merge_type = _mod_merge.Merge3Merger
 
429
        merger.interesting_files = 'a'
 
430
        conflict_count = merger.do_merge()
 
431
        self.assertEqual(0, conflict_count)
 
432
 
 
433
        self.assertPathDoesNotExist("a")
 
434
        tree.revert()
 
435
        self.assertPathExists("a")
 
436
 
390
437
    def test_make_merger(self):
391
438
        this_tree = self.make_branch_and_tree('this')
392
439
        this_tree.commit('rev1', rev_id='rev1')
456
503
        finally:
457
504
            tree_file.close()
458
505
 
 
506
    def test_merge_require_tree_root(self):
 
507
        tree = self.make_branch_and_tree(".")
 
508
        tree.lock_write()
 
509
        self.addCleanup(tree.unlock)
 
510
        self.build_tree(['a'])
 
511
        tree.add('a')
 
512
        tree.commit("added a")
 
513
        old_root_id = tree.get_root_id()
 
514
        first_rev = tree.branch.revision_history()[0]
 
515
        merger = _mod_merge.Merger.from_revision_ids(None, tree,
 
516
                                          _mod_revision.NULL_REVISION,
 
517
                                          first_rev)
 
518
        merger.merge_type = _mod_merge.Merge3Merger
 
519
        conflict_count = merger.do_merge()
 
520
        self.assertEqual(0, conflict_count)
 
521
        self.assertEquals(set([old_root_id]), tree.all_file_ids())
 
522
        tree.set_parent_ids([])
 
523
 
459
524
    def test_merge_add_into_deleted_root(self):
460
525
        # Yes, people actually do this.  And report bugs if it breaks.
461
526
        source = self.make_branch_and_tree('source', format='rich-root-pack')
1270
1335
        self.assertEqual(['B-id', 'C-id', 'F-id'],
1271
1336
                         [t.get_revision_id() for t in merger._lca_trees])
1272
1337
 
 
1338
    def test_find_base_new_root_criss_cross(self):
 
1339
        # A   B
 
1340
        # |\ /|
 
1341
        # | X |
 
1342
        # |/ \|
 
1343
        # C   D
 
1344
        
 
1345
        builder = self.get_builder()
 
1346
        builder.build_snapshot('A-id', None,
 
1347
            [('add', ('', None, 'directory', None))])
 
1348
        builder.build_snapshot('B-id', [],
 
1349
            [('add', ('', None, 'directory', None))])
 
1350
        builder.build_snapshot('D-id', ['A-id', 'B-id'], [])
 
1351
        builder.build_snapshot('C-id', ['A-id', 'B-id'], [])
 
1352
        merger = self.make_Merger(builder, 'D-id')
 
1353
        self.assertEqual('A-id', merger.base_rev_id)
 
1354
        self.assertTrue(merger._is_criss_cross)
 
1355
        self.assertEqual(['A-id', 'B-id'], [t.get_revision_id()
 
1356
                                            for t in merger._lca_trees])
 
1357
 
1273
1358
    def test_no_criss_cross_passed_to_merge_type(self):
1274
1359
        class LCATreesMerger(LoggingMerger):
1275
1360
            supports_lca_trees = True
1807
1892
        builder.build_snapshot('C-id', ['A-id'], [])
1808
1893
        builder.build_snapshot('E-id', ['C-id', 'B-id'],
1809
1894
            [('unversion', 'a-id'),
 
1895
             ('flush', None),
1810
1896
             ('add', (u'a', 'a-id', 'directory', None))])
1811
1897
        builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1812
1898
        merge_obj = self.make_merge_obj(builder, 'E-id')
1830
1916
        builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1831
1917
        builder.build_snapshot('D-id', ['B-id', 'C-id'],
1832
1918
            [('unversion', 'a-id'),
 
1919
             ('flush', None),
1833
1920
             ('add', (u'a', 'a-id', 'directory', None))])
1834
1921
        merge_obj = self.make_merge_obj(builder, 'E-id')
1835
1922
        entries = list(merge_obj._entries_lca())
2098
2185
        self.assertTrue(wt.is_executable('foo-id'))
2099
2186
 
2100
2187
    def test_create_symlink(self):
2101
 
        self.requireFeature(tests.SymlinkFeature)
 
2188
        self.requireFeature(features.SymlinkFeature)
2102
2189
        #   A
2103
2190
        #  / \
2104
2191
        # B   C
2163
2250
                             wt.get_file_text('foo-id'))
2164
2251
 
2165
2252
    def test_modified_symlink(self):
2166
 
        self.requireFeature(tests.SymlinkFeature)
 
2253
        self.requireFeature(features.SymlinkFeature)
2167
2254
        #   A       Create symlink foo => bar
2168
2255
        #  / \
2169
2256
        # B   C     B relinks foo => baz
2208
2295
        self.assertEqual('bing', wt.get_symlink_target('foo-id'))
2209
2296
 
2210
2297
    def test_renamed_symlink(self):
2211
 
        self.requireFeature(tests.SymlinkFeature)
 
2298
        self.requireFeature(features.SymlinkFeature)
2212
2299
        #   A       Create symlink foo => bar
2213
2300
        #  / \
2214
2301
        # B   C     B renames foo => barry
2264
2351
        self.assertEqual('blah', wt.id2path('foo-id'))
2265
2352
 
2266
2353
    def test_symlink_no_content_change(self):
2267
 
        self.requireFeature(tests.SymlinkFeature)
 
2354
        self.requireFeature(features.SymlinkFeature)
2268
2355
        #   A       Create symlink foo => bar
2269
2356
        #  / \
2270
2357
        # B   C     B relinks foo => baz
2315
2402
        self.assertEqual('bing', wt.get_symlink_target('foo-id'))
2316
2403
 
2317
2404
    def test_symlink_this_changed_kind(self):
2318
 
        self.requireFeature(tests.SymlinkFeature)
 
2405
        self.requireFeature(features.SymlinkFeature)
2319
2406
        #   A       Nothing
2320
2407
        #  / \
2321
2408
        # B   C     B creates symlink foo => bar
2368
2455
 
2369
2456
    def test_symlink_all_wt(self):
2370
2457
        """Check behavior if all trees are Working Trees."""
2371
 
        self.requireFeature(tests.SymlinkFeature)
 
2458
        self.requireFeature(features.SymlinkFeature)
2372
2459
        # The big issue is that entry.symlink_target is None for WorkingTrees.
2373
2460
        # So we need to make sure we handle that case correctly.
2374
2461
        #   A   foo => bar
2843
2930
 
2844
2931
    def get_merger_factory(self):
2845
2932
        # Allows  the inner methods to access the test attributes
2846
 
        test = self
 
2933
        calls = self.calls
2847
2934
 
2848
2935
        class FooMerger(_mod_merge.ConfigurableFileMerger):
2849
2936
            name_prefix = "foo"
2850
2937
            default_files = ['bar']
2851
2938
 
2852
2939
            def merge_text(self, params):
2853
 
                test.calls.append('merge_text')
 
2940
                calls.append('merge_text')
2854
2941
                return ('not_applicable', None)
2855
2942
 
2856
2943
        def factory(merger):