~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_merge.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-12-18 10:52:13 UTC
  • mfrom: (4869.2.9 merge-minor-refactoring)
  • Revision ID: pqm@pqm.ubuntu.com-20091218105213-3amdsy9oq337u387
(andrew) Add bzrlib.tests.per_merger, and tidy some nits.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
    transform,
30
30
    versionedfile,
31
31
    )
32
 
from bzrlib.branch import Branch
33
32
from bzrlib.conflicts import ConflictList, TextConflict
34
 
from bzrlib.errors import UnrelatedBranches, NoCommits, BzrCommandError
 
33
from bzrlib.errors import UnrelatedBranches, NoCommits
35
34
from bzrlib.merge import transform_tree, merge_inner, _PlanMerge
36
35
from bzrlib.osutils import pathjoin, file_kind
37
36
from bzrlib.tests import TestCaseWithTransport, TestCaseWithMemoryTransport
38
37
from bzrlib.workingtree import WorkingTree
39
 
from bzrlib.transform import TreeTransform
40
38
 
41
39
 
42
40
class TestMerge(TestCaseWithTransport):
1144
1142
                         ], list(plan))
1145
1143
 
1146
1144
 
1147
 
class TestMergeImplementation(object):
1148
 
 
1149
 
    def do_merge(self, target_tree, source_tree, **kwargs):
1150
 
        merger = _mod_merge.Merger.from_revision_ids(progress.DummyProgress(),
1151
 
            target_tree, source_tree.last_revision(),
1152
 
            other_branch=source_tree.branch)
1153
 
        merger.merge_type=self.merge_type
1154
 
        for name, value in kwargs.items():
1155
 
            setattr(merger, name, value)
1156
 
        merger.do_merge()
1157
 
 
1158
 
    def test_merge_specific_file(self):
1159
 
        this_tree = self.make_branch_and_tree('this')
1160
 
        this_tree.lock_write()
1161
 
        self.addCleanup(this_tree.unlock)
1162
 
        self.build_tree_contents([
1163
 
            ('this/file1', 'a\nb\n'),
1164
 
            ('this/file2', 'a\nb\n')
1165
 
        ])
1166
 
        this_tree.add(['file1', 'file2'])
1167
 
        this_tree.commit('Added files')
1168
 
        other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
1169
 
        self.build_tree_contents([
1170
 
            ('other/file1', 'a\nb\nc\n'),
1171
 
            ('other/file2', 'a\nb\nc\n')
1172
 
        ])
1173
 
        other_tree.commit('modified both')
1174
 
        self.build_tree_contents([
1175
 
            ('this/file1', 'd\na\nb\n'),
1176
 
            ('this/file2', 'd\na\nb\n')
1177
 
        ])
1178
 
        this_tree.commit('modified both')
1179
 
        self.do_merge(this_tree, other_tree, interesting_files=['file1'])
1180
 
        self.assertFileEqual('d\na\nb\nc\n', 'this/file1')
1181
 
        self.assertFileEqual('d\na\nb\n', 'this/file2')
1182
 
 
1183
 
    def test_merge_move_and_change(self):
1184
 
        this_tree = self.make_branch_and_tree('this')
1185
 
        this_tree.lock_write()
1186
 
        self.addCleanup(this_tree.unlock)
1187
 
        self.build_tree_contents([
1188
 
            ('this/file1', 'line 1\nline 2\nline 3\nline 4\n'),
1189
 
        ])
1190
 
        this_tree.add('file1',)
1191
 
        this_tree.commit('Added file')
1192
 
        other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
1193
 
        self.build_tree_contents([
1194
 
            ('other/file1', 'line 1\nline 2 to 2.1\nline 3\nline 4\n'),
1195
 
        ])
1196
 
        other_tree.commit('Changed 2 to 2.1')
1197
 
        self.build_tree_contents([
1198
 
            ('this/file1', 'line 1\nline 3\nline 2\nline 4\n'),
1199
 
        ])
1200
 
        this_tree.commit('Swapped 2 & 3')
1201
 
        self.do_merge(this_tree, other_tree)
1202
 
        self.assertFileEqual('line 1\n'
1203
 
            '<<<<<<< TREE\n'
1204
 
            'line 3\n'
1205
 
            'line 2\n'
1206
 
            '=======\n'
1207
 
            'line 2 to 2.1\n'
1208
 
            'line 3\n'
1209
 
            '>>>>>>> MERGE-SOURCE\n'
1210
 
            'line 4\n', 'this/file1')
1211
 
 
1212
 
    def test_modify_conflicts_with_delete(self):
1213
 
        # If one side deletes a line, and the other modifies that line, then
1214
 
        # the modification should be considered a conflict
1215
 
        builder = self.make_branch_builder('test')
1216
 
        builder.start_series()
1217
 
        builder.build_snapshot('BASE-id', None,
1218
 
            [('add', ('', None, 'directory', None)),
1219
 
             ('add', ('foo', 'foo-id', 'file', 'a\nb\nc\nd\ne\n')),
1220
 
            ])
1221
 
        # Delete 'b\n'
1222
 
        builder.build_snapshot('OTHER-id', ['BASE-id'],
1223
 
            [('modify', ('foo-id', 'a\nc\nd\ne\n'))])
1224
 
        # Modify 'b\n', add 'X\n'
1225
 
        builder.build_snapshot('THIS-id', ['BASE-id'],
1226
 
            [('modify', ('foo-id', 'a\nb2\nc\nd\nX\ne\n'))])
1227
 
        builder.finish_series()
1228
 
        branch = builder.get_branch()
1229
 
        this_tree = branch.bzrdir.create_workingtree()
1230
 
        this_tree.lock_write()
1231
 
        self.addCleanup(this_tree.unlock)
1232
 
        other_tree = this_tree.bzrdir.sprout('other', 'OTHER-id').open_workingtree()
1233
 
        self.do_merge(this_tree, other_tree)
1234
 
        if self.merge_type is _mod_merge.LCAMerger:
1235
 
            self.expectFailure("lca merge doesn't track deleted lines",
1236
 
                self.assertFileEqual,
1237
 
                    'a\n'
1238
 
                    '<<<<<<< TREE\n'
1239
 
                    'b2\n'
1240
 
                    '=======\n'
1241
 
                    '>>>>>>> MERGE-SOURCE\n'
1242
 
                    'c\n'
1243
 
                    'd\n'
1244
 
                    'X\n'
1245
 
                    'e\n', 'test/foo')
1246
 
        else:
1247
 
            self.assertFileEqual(
1248
 
                'a\n'
1249
 
                '<<<<<<< TREE\n'
1250
 
                'b2\n'
1251
 
                '=======\n'
1252
 
                '>>>>>>> MERGE-SOURCE\n'
1253
 
                'c\n'
1254
 
                'd\n'
1255
 
                'X\n'
1256
 
                'e\n', 'test/foo')
1257
 
 
1258
 
    def get_limbodir_deletiondir(self, wt):
1259
 
        transform = TreeTransform(wt)
1260
 
        limbodir = transform._limbodir
1261
 
        deletiondir = transform._deletiondir
1262
 
        transform.finalize()
1263
 
        return (limbodir, deletiondir)
1264
 
    
1265
 
    def test_merge_with_existing_limbo(self):
1266
 
        wt = self.make_branch_and_tree('this')
1267
 
        (limbodir, deletiondir) =  self.get_limbodir_deletiondir(wt)
1268
 
        os.mkdir(limbodir)
1269
 
        self.assertRaises(errors.ExistingLimbo, self.do_merge, wt, wt)
1270
 
        self.assertRaises(errors.LockError, wt.unlock)
1271
 
 
1272
 
    def test_merge_with_pending_deletion(self):
1273
 
        wt = self.make_branch_and_tree('this')
1274
 
        (limbodir, deletiondir) =  self.get_limbodir_deletiondir(wt)
1275
 
        os.mkdir(deletiondir)
1276
 
        self.assertRaises(errors.ExistingPendingDeletion, self.do_merge, wt, wt)
1277
 
        self.assertRaises(errors.LockError, wt.unlock)
1278
 
 
1279
 
 
1280
 
class TestMerge3Merge(TestCaseWithTransport, TestMergeImplementation):
1281
 
 
1282
 
    merge_type = _mod_merge.Merge3Merger
1283
 
 
1284
 
 
1285
 
class TestWeaveMerge(TestCaseWithTransport, TestMergeImplementation):
1286
 
 
1287
 
    merge_type = _mod_merge.WeaveMerger
1288
 
 
1289
 
 
1290
 
class TestLCAMerge(TestCaseWithTransport, TestMergeImplementation):
1291
 
 
1292
 
    merge_type = _mod_merge.LCAMerger
1293
 
 
1294
 
    def test_merge_move_and_change(self):
1295
 
        self.expectFailure("lca merge doesn't conflict for move and change",
1296
 
            super(TestLCAMerge, self).test_merge_move_and_change)
1297
 
 
1298
 
 
1299
1145
class LoggingMerger(object):
1300
1146
    # These seem to be the required attributes
1301
1147
    requires_base = False