~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_merge.py

  • Committer: Andrew Bennetts
  • Date: 2009-03-18 03:24:48 UTC
  • mto: This revision was merged to the branch mainline in revision 4194.
  • Revision ID: andrew.bennetts@canonical.com-20090318032448-f93pjfrhwmv4hwhl
Failing test for BzrDir.open_branchV2 RPC not opening stacked-on branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
import os
18
18
from StringIO import StringIO
29
29
    transform,
30
30
    versionedfile,
31
31
    )
 
32
from bzrlib.branch import Branch
32
33
from bzrlib.conflicts import ConflictList, TextConflict
33
 
from bzrlib.errors import UnrelatedBranches, NoCommits
 
34
from bzrlib.errors import UnrelatedBranches, NoCommits, BzrCommandError
34
35
from bzrlib.merge import transform_tree, merge_inner, _PlanMerge
35
36
from bzrlib.osutils import pathjoin, file_kind
36
 
from bzrlib.tests import (
37
 
    TestCaseWithMemoryTransport,
38
 
    TestCaseWithTransport,
39
 
    test_merge_core,
40
 
    )
 
37
from bzrlib.tests import TestCaseWithTransport, TestCaseWithMemoryTransport
 
38
from bzrlib.trace import (enable_test_log, disable_test_log)
41
39
from bzrlib.workingtree import WorkingTree
42
40
 
43
41
 
154
152
        log = StringIO()
155
153
        merge_inner(tree_b.branch, tree_a, tree_b.basis_tree(),
156
154
                    this_tree=tree_b, ignore_zero=True)
157
 
        self.failUnless('All changes applied successfully.\n' not in
158
 
            self.get_log())
 
155
        log = self._get_log(keep_log_file=True)
 
156
        self.failUnless('All changes applied successfully.\n' not in log)
159
157
        tree_b.revert()
160
158
        merge_inner(tree_b.branch, tree_a, tree_b.basis_tree(),
161
159
                    this_tree=tree_b, ignore_zero=False)
162
 
        self.failUnless('All changes applied successfully.\n' in self.get_log())
 
160
        log = self._get_log(keep_log_file=True)
 
161
        self.failUnless('All changes applied successfully.\n' in log)
163
162
 
164
163
    def test_merge_inner_conflicts(self):
165
164
        tree_a = self.make_branch_and_tree('a')
220
219
        tree_a.add('file')
221
220
        tree_a.commit('commit base')
222
221
        # basis_tree() is only guaranteed to be valid as long as it is actually
223
 
        # the basis tree. This test commits to the tree after grabbing basis,
224
 
        # so we go to the repository.
 
222
        # the basis tree. This mutates the tree after grabbing basis, so go to
 
223
        # the repository.
225
224
        base_tree = tree_a.branch.repository.revision_tree(tree_a.last_revision())
226
225
        tree_b = tree_a.bzrdir.sprout('tree_b').open_workingtree()
227
226
        self.build_tree_contents([('tree_a/file', 'content_2')])
228
227
        tree_a.commit('commit other')
229
228
        other_tree = tree_a.basis_tree()
230
 
        # 'file' is now missing but isn't altered in any commit in b so no
231
 
        # change should be applied.
232
229
        os.unlink('tree_b/file')
233
230
        merge_inner(tree_b.branch, other_tree, base_tree, this_tree=tree_b)
234
231
 
295
292
        tree_a.commit('commit 2')
296
293
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
297
294
        tree_b.rename_one('file_1', 'renamed')
298
 
        merger = _mod_merge.Merger.from_uncommitted(tree_a, tree_b)
 
295
        merger = _mod_merge.Merger.from_uncommitted(tree_a, tree_b,
 
296
                                                    progress.DummyProgress())
299
297
        merger.merge_type = _mod_merge.Merge3Merger
300
298
        merger.do_merge()
301
299
        self.assertEqual(tree_a.get_parent_ids(), [tree_b.last_revision()])
309
307
        tree_a.commit('commit 2')
310
308
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
311
309
        tree_b.rename_one('file_1', 'renamed')
312
 
        merger = _mod_merge.Merger.from_uncommitted(tree_a, tree_b)
 
310
        merger = _mod_merge.Merger.from_uncommitted(tree_a, tree_b,
 
311
                                                    progress.DummyProgress())
313
312
        merger.merge_type = _mod_merge.WeaveMerger
314
313
        merger.do_merge()
315
314
        self.assertEqual(tree_a.get_parent_ids(), [tree_b.last_revision()])
316
315
 
 
316
    def test_Merger_defaults_to_DummyProgress(self):
 
317
        branch = self.make_branch('branch')
 
318
        merger = _mod_merge.Merger(branch, pb=None)
 
319
        self.assertIsInstance(merger._pb, progress.DummyProgress)
 
320
 
317
321
    def prepare_cherrypick(self):
318
322
        """Prepare a pair of trees for cherrypicking tests.
319
323
 
340
344
 
341
345
    def test_weave_cherrypick(self):
342
346
        this_tree, other_tree = self.prepare_cherrypick()
343
 
        merger = _mod_merge.Merger.from_revision_ids(None,
 
347
        merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
344
348
            this_tree, 'rev3b', 'rev2b', other_tree.branch)
345
349
        merger.merge_type = _mod_merge.WeaveMerger
346
350
        merger.do_merge()
348
352
 
349
353
    def test_weave_cannot_reverse_cherrypick(self):
350
354
        this_tree, other_tree = self.prepare_cherrypick()
351
 
        merger = _mod_merge.Merger.from_revision_ids(None,
 
355
        merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
352
356
            this_tree, 'rev2b', 'rev3b', other_tree.branch)
353
357
        merger.merge_type = _mod_merge.WeaveMerger
354
358
        self.assertRaises(errors.CannotReverseCherrypick, merger.do_merge)
355
359
 
356
360
    def test_merge3_can_reverse_cherrypick(self):
357
361
        this_tree, other_tree = self.prepare_cherrypick()
358
 
        merger = _mod_merge.Merger.from_revision_ids(None,
 
362
        merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
359
363
            this_tree, 'rev2b', 'rev3b', other_tree.branch)
360
364
        merger.merge_type = _mod_merge.Merge3Merger
361
365
        merger.do_merge()
373
377
        this_tree.lock_write()
374
378
        self.addCleanup(this_tree.unlock)
375
379
 
376
 
        merger = _mod_merge.Merger.from_revision_ids(None,
 
380
        merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
377
381
            this_tree, 'rev3b', 'rev2b', other_tree.branch)
378
382
        merger.merge_type = _mod_merge.Merge3Merger
379
383
        merger.do_merge()
392
396
        other_tree.commit('rev2', rev_id='rev2b')
393
397
        this_tree.lock_write()
394
398
        self.addCleanup(this_tree.unlock)
395
 
        merger = _mod_merge.Merger.from_revision_ids(None,
 
399
        merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress,
396
400
            this_tree, 'rev2b', other_branch=other_tree.branch)
397
401
        merger.merge_type = _mod_merge.Merge3Merger
398
402
        tree_merger = merger.make_merger()
412
416
        other_tree.commit('rev2', rev_id='rev2b')
413
417
        this_tree.lock_write()
414
418
        self.addCleanup(this_tree.unlock)
415
 
        merger = _mod_merge.Merger.from_revision_ids(None,
 
419
        merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
416
420
            this_tree, 'rev2b', other_branch=other_tree.branch)
417
421
        merger.merge_type = _mod_merge.Merge3Merger
418
422
        tree_merger = merger.make_merger()
442
446
        other_tree.commit('rev2', rev_id='rev2b')
443
447
        this_tree.lock_write()
444
448
        self.addCleanup(this_tree.unlock)
445
 
        merger = _mod_merge.Merger.from_revision_ids(None,
 
449
        merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
446
450
            this_tree, 'rev2b', other_branch=other_tree.branch)
447
451
        merger.merge_type = _mod_merge.Merge3Merger
448
452
        tree_merger = merger.make_merger()
519
523
        self.add_uncommitted_version(('root', 'C:'), [('root', 'A')], 'fabg')
520
524
        return _PlanMerge('B:', 'C:', self.plan_merge_vf, ('root',))
521
525
 
522
 
    def test_base_from_plan(self):
523
 
        self.setup_plan_merge()
524
 
        plan = self.plan_merge_vf.plan_merge('B', 'C')
525
 
        pwm = versionedfile.PlanWeaveMerge(plan)
526
 
        self.assertEqual(['a\n', 'b\n', 'c\n'], pwm.base_from_plan())
527
 
 
528
526
    def test_unique_lines(self):
529
527
        plan = self.setup_plan_merge()
530
528
        self.assertEqual(plan._unique_lines(
828
826
                          ('unchanged', 'f\n'),
829
827
                          ('unchanged', 'g\n')],
830
828
                         list(plan))
831
 
        plan = self.plan_merge_vf.plan_lca_merge('F', 'G')
832
 
        # This is one of the main differences between plan_merge and
833
 
        # plan_lca_merge. plan_lca_merge generates a conflict for 'x => z',
834
 
        # because 'x' was not present in one of the bases. However, in this
835
 
        # case it is spurious because 'x' does not exist in the global base A.
836
 
        self.assertEqual([
837
 
                          ('unchanged', 'h\n'),
838
 
                          ('unchanged', 'a\n'),
839
 
                          ('conflicted-a', 'x\n'),
840
 
                          ('new-b', 'z\n'),
841
 
                          ('unchanged', 'c\n'),
842
 
                          ('unchanged', 'd\n'),
843
 
                          ('unchanged', 'y\n'),
844
 
                          ('unchanged', 'f\n'),
845
 
                          ('unchanged', 'g\n')],
846
 
                         list(plan))
847
 
 
848
 
    def test_criss_cross_flip_flop(self):
849
 
        # This is specificly trying to trigger problems when using limited
850
 
        # ancestry and weaves. The ancestry graph looks like:
851
 
        #       XX      unused ancestor, should not show up in the weave
852
 
        #       |
853
 
        #       A       Unique LCA
854
 
        #      / \  
855
 
        #     B   C     B & C both introduce a new line
856
 
        #     |\ /|  
857
 
        #     | X |  
858
 
        #     |/ \| 
859
 
        #     D   E     B & C are both merged, so both are common ancestors
860
 
        #               In the process of merging, both sides order the new
861
 
        #               lines differently
862
 
        #
863
 
        self.add_rev('root', 'XX', [], 'qrs')
864
 
        self.add_rev('root', 'A', ['XX'], 'abcdef')
865
 
        self.add_rev('root', 'B', ['A'], 'abcdgef')
866
 
        self.add_rev('root', 'C', ['A'], 'abcdhef')
867
 
        self.add_rev('root', 'D', ['B', 'C'], 'abcdghef')
868
 
        self.add_rev('root', 'E', ['C', 'B'], 'abcdhgef')
869
 
        plan = list(self.plan_merge_vf.plan_merge('D', 'E'))
870
 
        self.assertEqual([
871
 
                          ('unchanged', 'a\n'),
872
 
                          ('unchanged', 'b\n'),
873
 
                          ('unchanged', 'c\n'),
874
 
                          ('unchanged', 'd\n'),
875
 
                          ('new-b', 'h\n'),
876
 
                          ('unchanged', 'g\n'),
877
 
                          ('killed-b', 'h\n'),
878
 
                          ('unchanged', 'e\n'),
879
 
                          ('unchanged', 'f\n'),
880
 
                         ], plan)
881
 
        pwm = versionedfile.PlanWeaveMerge(plan)
882
 
        self.assertEqualDiff('\n'.join('abcdghef') + '\n',
883
 
                             ''.join(pwm.base_from_plan()))
884
 
        # Reversing the order reverses the merge plan, and final order of 'hg'
885
 
        # => 'gh'
886
 
        plan = list(self.plan_merge_vf.plan_merge('E', 'D'))
887
 
        self.assertEqual([
888
 
                          ('unchanged', 'a\n'),
889
 
                          ('unchanged', 'b\n'),
890
 
                          ('unchanged', 'c\n'),
891
 
                          ('unchanged', 'd\n'),
892
 
                          ('new-b', 'g\n'),
893
 
                          ('unchanged', 'h\n'),
894
 
                          ('killed-b', 'g\n'),
895
 
                          ('unchanged', 'e\n'),
896
 
                          ('unchanged', 'f\n'),
897
 
                         ], plan)
898
 
        pwm = versionedfile.PlanWeaveMerge(plan)
899
 
        self.assertEqualDiff('\n'.join('abcdhgef') + '\n',
900
 
                             ''.join(pwm.base_from_plan()))
901
 
        # This is where lca differs, in that it (fairly correctly) determines
902
 
        # that there is a conflict because both sides resolved the merge
903
 
        # differently
904
 
        plan = list(self.plan_merge_vf.plan_lca_merge('D', 'E'))
905
 
        self.assertEqual([
906
 
                          ('unchanged', 'a\n'),
907
 
                          ('unchanged', 'b\n'),
908
 
                          ('unchanged', 'c\n'),
909
 
                          ('unchanged', 'd\n'),
910
 
                          ('conflicted-b', 'h\n'),
911
 
                          ('unchanged', 'g\n'),
912
 
                          ('conflicted-a', 'h\n'),
913
 
                          ('unchanged', 'e\n'),
914
 
                          ('unchanged', 'f\n'),
915
 
                         ], plan)
916
 
        pwm = versionedfile.PlanWeaveMerge(plan)
917
 
        self.assertEqualDiff('\n'.join('abcdgef') + '\n',
918
 
                             ''.join(pwm.base_from_plan()))
919
 
        # Reversing it changes what line is doubled, but still gives a
920
 
        # double-conflict
921
 
        plan = list(self.plan_merge_vf.plan_lca_merge('E', 'D'))
922
 
        self.assertEqual([
923
 
                          ('unchanged', 'a\n'),
924
 
                          ('unchanged', 'b\n'),
925
 
                          ('unchanged', 'c\n'),
926
 
                          ('unchanged', 'd\n'),
927
 
                          ('conflicted-b', 'g\n'),
928
 
                          ('unchanged', 'h\n'),
929
 
                          ('conflicted-a', 'g\n'),
930
 
                          ('unchanged', 'e\n'),
931
 
                          ('unchanged', 'f\n'),
932
 
                         ], plan)
933
 
        pwm = versionedfile.PlanWeaveMerge(plan)
934
 
        self.assertEqualDiff('\n'.join('abcdhef') + '\n',
935
 
                             ''.join(pwm.base_from_plan()))
936
829
 
937
830
    def assertRemoveExternalReferences(self, filtered_parent_map,
938
831
                                       child_map, tails, parent_map):
1138
1031
                         ], list(plan))
1139
1032
 
1140
1033
 
 
1034
class TestMergeImplementation(object):
 
1035
 
 
1036
    def do_merge(self, target_tree, source_tree, **kwargs):
 
1037
        merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
 
1038
            target_tree, source_tree.last_revision(),
 
1039
            other_branch=source_tree.branch)
 
1040
        merger.merge_type=self.merge_type
 
1041
        for name, value in kwargs.items():
 
1042
            setattr(merger, name, value)
 
1043
        merger.do_merge()
 
1044
 
 
1045
    def test_merge_specific_file(self):
 
1046
        this_tree = self.make_branch_and_tree('this')
 
1047
        this_tree.lock_write()
 
1048
        self.addCleanup(this_tree.unlock)
 
1049
        self.build_tree_contents([
 
1050
            ('this/file1', 'a\nb\n'),
 
1051
            ('this/file2', 'a\nb\n')
 
1052
        ])
 
1053
        this_tree.add(['file1', 'file2'])
 
1054
        this_tree.commit('Added files')
 
1055
        other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
 
1056
        self.build_tree_contents([
 
1057
            ('other/file1', 'a\nb\nc\n'),
 
1058
            ('other/file2', 'a\nb\nc\n')
 
1059
        ])
 
1060
        other_tree.commit('modified both')
 
1061
        self.build_tree_contents([
 
1062
            ('this/file1', 'd\na\nb\n'),
 
1063
            ('this/file2', 'd\na\nb\n')
 
1064
        ])
 
1065
        this_tree.commit('modified both')
 
1066
        self.do_merge(this_tree, other_tree, interesting_files=['file1'])
 
1067
        self.assertFileEqual('d\na\nb\nc\n', 'this/file1')
 
1068
        self.assertFileEqual('d\na\nb\n', 'this/file2')
 
1069
 
 
1070
    def test_merge_move_and_change(self):
 
1071
        this_tree = self.make_branch_and_tree('this')
 
1072
        this_tree.lock_write()
 
1073
        self.addCleanup(this_tree.unlock)
 
1074
        self.build_tree_contents([
 
1075
            ('this/file1', 'line 1\nline 2\nline 3\nline 4\n'),
 
1076
        ])
 
1077
        this_tree.add('file1',)
 
1078
        this_tree.commit('Added file')
 
1079
        other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
 
1080
        self.build_tree_contents([
 
1081
            ('other/file1', 'line 1\nline 2 to 2.1\nline 3\nline 4\n'),
 
1082
        ])
 
1083
        other_tree.commit('Changed 2 to 2.1')
 
1084
        self.build_tree_contents([
 
1085
            ('this/file1', 'line 1\nline 3\nline 2\nline 4\n'),
 
1086
        ])
 
1087
        this_tree.commit('Swapped 2 & 3')
 
1088
        self.do_merge(this_tree, other_tree)
 
1089
        self.assertFileEqual('line 1\n'
 
1090
            '<<<<<<< TREE\n'
 
1091
            'line 3\n'
 
1092
            'line 2\n'
 
1093
            '=======\n'
 
1094
            'line 2 to 2.1\n'
 
1095
            'line 3\n'
 
1096
            '>>>>>>> MERGE-SOURCE\n'
 
1097
            'line 4\n', 'this/file1')
 
1098
 
 
1099
 
 
1100
class TestMerge3Merge(TestCaseWithTransport, TestMergeImplementation):
 
1101
 
 
1102
    merge_type = _mod_merge.Merge3Merger
 
1103
 
 
1104
 
 
1105
class TestWeaveMerge(TestCaseWithTransport, TestMergeImplementation):
 
1106
 
 
1107
    merge_type = _mod_merge.WeaveMerger
 
1108
 
 
1109
 
 
1110
class TestLCAMerge(TestCaseWithTransport, TestMergeImplementation):
 
1111
 
 
1112
    merge_type = _mod_merge.LCAMerger
 
1113
 
 
1114
    def test_merge_move_and_change(self):
 
1115
        self.expectFailure("lca merge doesn't conflict for move and change",
 
1116
            super(TestLCAMerge, self).test_merge_move_and_change)
 
1117
 
 
1118
 
1141
1119
class LoggingMerger(object):
1142
1120
    # These seem to be the required attributes
1143
1121
    requires_base = False
1198
1176
        mem_tree = memorytree.MemoryTree.create_on_branch(builder.get_branch())
1199
1177
        mem_tree.lock_write()
1200
1178
        self.addCleanup(mem_tree.unlock)
1201
 
        merger = _mod_merge.Merger.from_revision_ids(None,
 
1179
        merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
1202
1180
            mem_tree, other_revision_id)
1203
1181
        merger.set_interesting_files(interesting_files)
1204
1182
        # It seems there is no matching function for set_interesting_ids
1209
1187
 
1210
1188
class TestMergerInMemory(TestMergerBase):
1211
1189
 
1212
 
    def test_cache_trees_with_revision_ids_None(self):
1213
 
        merger = self.make_Merger(self.setup_simple_graph(), 'C-id')
1214
 
        original_cache = dict(merger._cached_trees)
1215
 
        merger.cache_trees_with_revision_ids([None])
1216
 
        self.assertEqual(original_cache, merger._cached_trees)
1217
 
 
1218
 
    def test_cache_trees_with_revision_ids_no_revision_id(self):
1219
 
        merger = self.make_Merger(self.setup_simple_graph(), 'C-id')
1220
 
        original_cache = dict(merger._cached_trees)
1221
 
        tree = self.make_branch_and_memory_tree('tree')
1222
 
        merger.cache_trees_with_revision_ids([tree])
1223
 
        self.assertEqual(original_cache, merger._cached_trees)
1224
 
 
1225
 
    def test_cache_trees_with_revision_ids_having_revision_id(self):
1226
 
        merger = self.make_Merger(self.setup_simple_graph(), 'C-id')
1227
 
        original_cache = dict(merger._cached_trees)
1228
 
        tree = merger.this_branch.repository.revision_tree('B-id')
1229
 
        original_cache['B-id'] = tree
1230
 
        merger.cache_trees_with_revision_ids([tree])
1231
 
        self.assertEqual(original_cache, merger._cached_trees)
1232
 
 
1233
1190
    def test_find_base(self):
1234
1191
        merger = self.make_Merger(self.setup_simple_graph(), 'C-id')
1235
1192
        self.assertEqual('A-id', merger.base_rev_id)
1978
1935
 
1979
1936
    def do_merge(self, builder, other_revision_id):
1980
1937
        wt = self.get_wt_from_builder(builder)
1981
 
        merger = _mod_merge.Merger.from_revision_ids(None,
 
1938
        merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
1982
1939
            wt, other_revision_id)
1983
1940
        merger.merge_type = _mod_merge.Merge3Merger
1984
1941
        return wt, merger.do_merge()
2244
2201
        wt.commit('D merges B & C', rev_id='D-id')
2245
2202
        self.assertEqual('barry', wt.id2path('foo-id'))
2246
2203
        # Check the output of the Merger object directly
2247
 
        merger = _mod_merge.Merger.from_revision_ids(None,
 
2204
        merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
2248
2205
            wt, 'F-id')
2249
2206
        merger.merge_type = _mod_merge.Merge3Merger
2250
2207
        merge_obj = merger.make_merger()
2300
2257
        wt.commit('F foo => bing', rev_id='F-id')
2301
2258
 
2302
2259
        # Check the output of the Merger object directly
2303
 
        merger = _mod_merge.Merger.from_revision_ids(None,
 
2260
        merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
2304
2261
            wt, 'E-id')
2305
2262
        merger.merge_type = _mod_merge.Merge3Merger
2306
2263
        merge_obj = merger.make_merger()
2351
2308
        list(wt.iter_changes(wt.basis_tree()))
2352
2309
        wt.commit('D merges B & C, makes it a file', rev_id='D-id')
2353
2310
 
2354
 
        merger = _mod_merge.Merger.from_revision_ids(None,
 
2311
        merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
2355
2312
            wt, 'E-id')
2356
2313
        merger.merge_type = _mod_merge.Merge3Merger
2357
2314
        merge_obj = merger.make_merger()
2566
2523
        wt.branch.set_last_revision_info(2, 'B-id')
2567
2524
        wt.commit('D', rev_id='D-id', recursive=None)
2568
2525
 
2569
 
        merger = _mod_merge.Merger.from_revision_ids(None,
 
2526
        merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
2570
2527
            wt, 'E-id')
2571
2528
        merger.merge_type = _mod_merge.Merge3Merger
2572
2529
        merge_obj = merger.make_merger()
2603
2560
        wt.branch.set_last_revision_info(2, 'B-id')
2604
2561
        wt.commit('D', rev_id='D-id', recursive=None)
2605
2562
 
2606
 
        merger = _mod_merge.Merger.from_revision_ids(None,
 
2563
        merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
2607
2564
            wt, 'E-id')
2608
2565
        merger.merge_type = _mod_merge.Merge3Merger
2609
2566
        merge_obj = merger.make_merger()
2643
2600
        wt.branch.set_last_revision_info(2, 'B-id')
2644
2601
        wt.commit('D', rev_id='D-id', recursive=None)
2645
2602
 
2646
 
        merger = _mod_merge.Merger.from_revision_ids(None,
 
2603
        merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
2647
2604
            wt, 'E-id')
2648
2605
        merger.merge_type = _mod_merge.Merge3Merger
2649
2606
        merge_obj = merger.make_merger()
2688
2645
        wt.branch.set_last_revision_info(2, 'B-id')
2689
2646
        wt.commit('D', rev_id='D-id', recursive=None)
2690
2647
 
2691
 
        merger = _mod_merge.Merger.from_revision_ids(None,
 
2648
        merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
2692
2649
            wt, 'E-id')
2693
2650
        merger.merge_type = _mod_merge.Merge3Merger
2694
2651
        merge_obj = merger.make_merger()
2830
2787
            'bval', ['lca1val', 'lca2val', 'lca2val'], 'oval', 'tval')
2831
2788
        self.assertLCAMultiWay('conflict',
2832
2789
            'bval', ['lca1val', 'lca2val', 'lca3val'], 'oval', 'tval')
2833
 
 
2834
 
 
2835
 
class TestConfigurableFileMerger(tests.TestCaseWithTransport):
2836
 
 
2837
 
    def setUp(self):
2838
 
        super(TestConfigurableFileMerger, self).setUp()
2839
 
        self.calls = []
2840
 
 
2841
 
    def get_merger_factory(self):
2842
 
        # Allows  the inner methods to access the test attributes
2843
 
        test = self
2844
 
 
2845
 
        class FooMerger(_mod_merge.ConfigurableFileMerger):
2846
 
            name_prefix = "foo"
2847
 
            default_files = ['bar']
2848
 
 
2849
 
            def merge_text(self, params):
2850
 
                test.calls.append('merge_text')
2851
 
                return ('not_applicable', None)
2852
 
 
2853
 
        def factory(merger):
2854
 
            result = FooMerger(merger)
2855
 
            # Make sure we start with a clean slate
2856
 
            self.assertEqual(None, result.affected_files)
2857
 
            # Track the original merger
2858
 
            self.merger = result
2859
 
            return result
2860
 
 
2861
 
        return factory
2862
 
 
2863
 
    def _install_hook(self, factory):
2864
 
        _mod_merge.Merger.hooks.install_named_hook('merge_file_content',
2865
 
                                                   factory, 'test factory')
2866
 
 
2867
 
    def make_builder(self):
2868
 
        builder = test_merge_core.MergeBuilder(self.test_base_dir)
2869
 
        self.addCleanup(builder.cleanup)
2870
 
        return builder
2871
 
 
2872
 
    def make_text_conflict(self, file_name='bar'):
2873
 
        factory = self.get_merger_factory()
2874
 
        self._install_hook(factory)
2875
 
        builder = self.make_builder()
2876
 
        builder.add_file('bar-id', builder.tree_root, file_name, 'text1', True)
2877
 
        builder.change_contents('bar-id', other='text4', this='text3')
2878
 
        return builder
2879
 
 
2880
 
    def make_kind_change(self):
2881
 
        factory = self.get_merger_factory()
2882
 
        self._install_hook(factory)
2883
 
        builder = self.make_builder()
2884
 
        builder.add_file('bar-id', builder.tree_root, 'bar', 'text1', True,
2885
 
                         this=False)
2886
 
        builder.add_dir('bar-dir', builder.tree_root, 'bar-id',
2887
 
                        base=False, other=False)
2888
 
        return builder
2889
 
 
2890
 
    def test_uses_this_branch(self):
2891
 
        builder = self.make_text_conflict()
2892
 
        tt = builder.make_preview_transform()
2893
 
        self.addCleanup(tt.finalize)
2894
 
 
2895
 
    def test_affected_files_cached(self):
2896
 
        """Ensures that the config variable is cached"""
2897
 
        builder = self.make_text_conflict()
2898
 
        conflicts = builder.merge()
2899
 
        # The hook should set the variable
2900
 
        self.assertEqual(['bar'], self.merger.affected_files)
2901
 
        self.assertEqual(1, len(conflicts))
2902
 
 
2903
 
    def test_hook_called_for_text_conflicts(self):
2904
 
        builder = self.make_text_conflict()
2905
 
        conflicts = builder.merge()
2906
 
        # The hook should call the merge_text() method
2907
 
        self.assertEqual(['merge_text'], self.calls)
2908
 
 
2909
 
    def test_hook_not_called_for_kind_change(self):
2910
 
        builder = self.make_kind_change()
2911
 
        conflicts = builder.merge()
2912
 
        # The hook should not call the merge_text() method
2913
 
        self.assertEqual([], self.calls)
2914
 
 
2915
 
    def test_hook_not_called_for_other_files(self):
2916
 
        builder = self.make_text_conflict('foobar')
2917
 
        conflicts = builder.merge()
2918
 
        # The hook should not call the merge_text() method
2919
 
        self.assertEqual([], self.calls)