~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_merge.py

  • Committer: Andrew Bennetts
  • Date: 2010-07-29 11:17:57 UTC
  • mfrom: (5050.3.17 2.2)
  • mto: This revision was merged to the branch mainline in revision 5365.
  • Revision ID: andrew.bennetts@canonical.com-20100729111757-018h3pcefo7z0dnq
Merge lp:bzr/2.2 into lp:bzr.

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