~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_merge.py

(gz) Fix test failure on alpha by correcting format string for
 gc_chk_sha1_record (Martin [gz])

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
 
        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
 
 
437
390
    def test_make_merger(self):
438
391
        this_tree = self.make_branch_and_tree('this')
439
392
        this_tree.commit('rev1', rev_id='rev1')
503
456
        finally:
504
457
            tree_file.close()
505
458
 
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
 
 
524
459
    def test_merge_add_into_deleted_root(self):
525
460
        # Yes, people actually do this.  And report bugs if it breaks.
526
461
        source = self.make_branch_and_tree('source', format='rich-root-pack')
1892
1827
        builder.build_snapshot('C-id', ['A-id'], [])
1893
1828
        builder.build_snapshot('E-id', ['C-id', 'B-id'],
1894
1829
            [('unversion', 'a-id'),
1895
 
             ('flush', None),
1896
1830
             ('add', (u'a', 'a-id', 'directory', None))])
1897
1831
        builder.build_snapshot('D-id', ['B-id', 'C-id'], [])
1898
1832
        merge_obj = self.make_merge_obj(builder, 'E-id')
1916
1850
        builder.build_snapshot('E-id', ['C-id', 'B-id'], [])
1917
1851
        builder.build_snapshot('D-id', ['B-id', 'C-id'],
1918
1852
            [('unversion', 'a-id'),
1919
 
             ('flush', None),
1920
1853
             ('add', (u'a', 'a-id', 'directory', None))])
1921
1854
        merge_obj = self.make_merge_obj(builder, 'E-id')
1922
1855
        entries = list(merge_obj._entries_lca())
2185
2118
        self.assertTrue(wt.is_executable('foo-id'))
2186
2119
 
2187
2120
    def test_create_symlink(self):
2188
 
        self.requireFeature(features.SymlinkFeature)
 
2121
        self.requireFeature(tests.SymlinkFeature)
2189
2122
        #   A
2190
2123
        #  / \
2191
2124
        # B   C
2250
2183
                             wt.get_file_text('foo-id'))
2251
2184
 
2252
2185
    def test_modified_symlink(self):
2253
 
        self.requireFeature(features.SymlinkFeature)
 
2186
        self.requireFeature(tests.SymlinkFeature)
2254
2187
        #   A       Create symlink foo => bar
2255
2188
        #  / \
2256
2189
        # B   C     B relinks foo => baz
2295
2228
        self.assertEqual('bing', wt.get_symlink_target('foo-id'))
2296
2229
 
2297
2230
    def test_renamed_symlink(self):
2298
 
        self.requireFeature(features.SymlinkFeature)
 
2231
        self.requireFeature(tests.SymlinkFeature)
2299
2232
        #   A       Create symlink foo => bar
2300
2233
        #  / \
2301
2234
        # B   C     B renames foo => barry
2351
2284
        self.assertEqual('blah', wt.id2path('foo-id'))
2352
2285
 
2353
2286
    def test_symlink_no_content_change(self):
2354
 
        self.requireFeature(features.SymlinkFeature)
 
2287
        self.requireFeature(tests.SymlinkFeature)
2355
2288
        #   A       Create symlink foo => bar
2356
2289
        #  / \
2357
2290
        # B   C     B relinks foo => baz
2402
2335
        self.assertEqual('bing', wt.get_symlink_target('foo-id'))
2403
2336
 
2404
2337
    def test_symlink_this_changed_kind(self):
2405
 
        self.requireFeature(features.SymlinkFeature)
 
2338
        self.requireFeature(tests.SymlinkFeature)
2406
2339
        #   A       Nothing
2407
2340
        #  / \
2408
2341
        # B   C     B creates symlink foo => bar
2455
2388
 
2456
2389
    def test_symlink_all_wt(self):
2457
2390
        """Check behavior if all trees are Working Trees."""
2458
 
        self.requireFeature(features.SymlinkFeature)
 
2391
        self.requireFeature(tests.SymlinkFeature)
2459
2392
        # The big issue is that entry.symlink_target is None for WorkingTrees.
2460
2393
        # So we need to make sure we handle that case correctly.
2461
2394
        #   A   foo => bar
2930
2863
 
2931
2864
    def get_merger_factory(self):
2932
2865
        # Allows  the inner methods to access the test attributes
2933
 
        calls = self.calls
 
2866
        test = self
2934
2867
 
2935
2868
        class FooMerger(_mod_merge.ConfigurableFileMerger):
2936
2869
            name_prefix = "foo"
2937
2870
            default_files = ['bar']
2938
2871
 
2939
2872
            def merge_text(self, params):
2940
 
                calls.append('merge_text')
 
2873
                test.calls.append('merge_text')
2941
2874
                return ('not_applicable', None)
2942
2875
 
2943
2876
        def factory(merger):