~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_merge.py

  • Committer: John Arbash Meinel
  • Author(s): Mark Hammond
  • Date: 2008-09-09 17:02:21 UTC
  • mto: This revision was merged to the branch mainline in revision 3697.
  • Revision ID: john@arbash-meinel.com-20080909170221-svim3jw2mrz0amp3
An updated transparent icon for bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
        a_tree.revert(backups=False)
71
71
        self.run_bzr('merge ../b -r last:1..last:1 --merge-type weave')
72
72
        a_tree.revert(backups=False)
 
73
        self.run_bzr('merge ../b -r last:1..last:1 --merge-type lca')
 
74
        a_tree.revert(backups=False)
73
75
        self.run_bzr_error(['Show-base is not supported for this merge type'],
74
76
                           'merge ../b -r last:1..last:1 --merge-type weave'
75
77
                           ' --show-base')
136
138
        self.failUnlessExists('sub/a.txt.BASE')
137
139
 
138
140
    def test_merge_remember(self):
139
 
        """Merge changes from one branch to another and test parent location."""
 
141
        """Merge changes from one branch to another, test submit location."""
140
142
        tree_a = self.make_branch_and_tree('branch_a')
141
143
        branch_a = tree_a.branch
142
144
        self.build_tree(['branch_a/a'])
166
168
        tree_b.add('d')
167
169
        self.run_bzr_error(['Working tree ".*" has uncommitted changes'],
168
170
                           'merge ../branch_a')
169
 
        self.assertEquals(abspath(branch_b.get_parent()), abspath(parent))
 
171
        self.assertEquals(abspath(branch_b.get_submit_branch()),
 
172
                          abspath(parent))
170
173
        # test implicit --remember after resolving conflict
171
174
        tree_b.commit('commit d')
172
175
        out, err = self.run_bzr('merge')
173
176
        
174
177
        base = urlutils.local_path_from_url(branch_a.base)
175
 
        self.assertEquals(out, 'Merging from remembered location %s\n' % (base,))
176
 
        self.assertEquals(err, '+N  b\nAll changes applied successfully.\n')
177
 
        self.assertEquals(abspath(branch_b.get_parent()), abspath(parent))
 
178
        self.assertStartsWith(err,
 
179
                          'Merging from remembered submit location %s\n' % (base,))
 
180
        self.assertEndsWith(err, '+N  b\nAll changes applied successfully.\n')
 
181
        self.assertEquals(abspath(branch_b.get_submit_branch()),
 
182
                          abspath(parent))
178
183
        # re-open tree as external run_bzr modified it
179
184
        tree_b = branch_b.bzrdir.open_workingtree()
180
185
        tree_b.commit('merge branch_a')
182
187
        out, err = self.run_bzr('merge ../branch_c --remember')
183
188
        self.assertEquals(out, '')
184
189
        self.assertEquals(err, '+N  c\nAll changes applied successfully.\n')
185
 
        self.assertEquals(abspath(branch_b.get_parent()),
 
190
        self.assertEquals(abspath(branch_b.get_submit_branch()),
186
191
                          abspath(branch_c.bzrdir.root_transport.base))
187
192
        # re-open tree as external run_bzr modified it
188
193
        tree_b = branch_b.bzrdir.open_workingtree()
238
243
        self.run_bzr_error(('Cannot use --uncommitted and --revision',),
239
244
                           'merge /a --uncommitted -r1 -d b')
240
245
 
 
246
    def test_merge_uncommitted_file(self):
 
247
        """It should be possible to merge changes from a single file."""
 
248
        tree_a = self.make_branch_and_tree('tree_a')
 
249
        tree_a.commit('initial commit')
 
250
        tree_a.bzrdir.sprout('tree_b')
 
251
        self.build_tree(['tree_a/file1', 'tree_a/file2'])
 
252
        tree_a.add(['file1', 'file2'])
 
253
        os.chdir('tree_b')
 
254
        self.run_bzr(['merge', '--uncommitted', '../tree_a/file1'])
 
255
        self.failUnlessExists('file1')
 
256
        self.failIfExists('file2')
 
257
 
241
258
    def pullable_branch(self):
242
259
        tree_a = self.make_branch_and_tree('a')
243
260
        self.build_tree(['a/file'])
289
306
        target.commit('empty commit')
290
307
        self.write_directive('directive', source.branch, 'target', 'rev2',
291
308
                             'rev1')
292
 
        self.run_bzr('merge -d target directive')
 
309
        out, err = self.run_bzr('merge -d target directive')
293
310
        self.failIfExists('target/a')
294
311
        self.failUnlessExists('target/b')
 
312
        self.assertContainsRe(err, 'Performing cherrypick')
295
313
 
296
314
    def write_directive(self, filename, source, target, revision_id,
297
315
                        base_revision_id=None, mangle_patch=False):
380
398
        # pick 1 revision with option --changes
381
399
        self.run_bzr('merge -d target -c revid:rev_d source')
382
400
        self.assertDirectoryContent('target', ['.bzr', 'a', 'd'])
 
401
 
 
402
    def test_merge_criss_cross(self):
 
403
        tree_a = self.make_branch_and_tree('a')
 
404
        tree_a.commit('', rev_id='rev1')
 
405
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
 
406
        tree_a.commit('', rev_id='rev2a')
 
407
        tree_b.commit('', rev_id='rev2b')
 
408
        tree_a.merge_from_branch(tree_b.branch)
 
409
        tree_b.merge_from_branch(tree_a.branch)
 
410
        tree_a.commit('', rev_id='rev3a')
 
411
        tree_b.commit('', rev_id='rev3b')
 
412
        graph = tree_a.branch.repository.get_graph(tree_b.branch.repository)
 
413
        out, err = self.run_bzr(['merge', '-d', 'a', 'b'])
 
414
        self.assertContainsRe(err, 'Warning: criss-cross merge encountered.')
 
415
 
 
416
    def test_merge_from_submit(self):
 
417
        tree_a = self.make_branch_and_tree('a')
 
418
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
 
419
        tree_c = tree_a.bzrdir.sprout('c').open_workingtree()
 
420
        out, err = self.run_bzr(['merge', '-d', 'c'])
 
421
        self.assertContainsRe(err, 'Merging from remembered parent location .*a\/')
 
422
        tree_c.branch.set_submit_branch(tree_b.bzrdir.root_transport.base)
 
423
        out, err = self.run_bzr(['merge', '-d', 'c'])
 
424
        self.assertContainsRe(err, 'Merging from remembered submit location .*b\/')
 
425
 
 
426
    def test_remember_sets_submit(self):
 
427
        tree_a = self.make_branch_and_tree('a')
 
428
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
 
429
        self.assertIs(tree_b.branch.get_submit_branch(), None)
 
430
 
 
431
        # Remember should not happen if using default from parent
 
432
        out, err = self.run_bzr(['merge', '-d', 'b'])
 
433
        self.assertIs(tree_b.branch.get_submit_branch(), None)
 
434
 
 
435
        # Remember should happen if user supplies location
 
436
        out, err = self.run_bzr(['merge', '-d', 'b', 'a'])
 
437
        self.assertEqual(tree_b.branch.get_submit_branch(),
 
438
                         tree_a.bzrdir.root_transport.base)
 
439
 
 
440
    def test_weave_cherrypick(self):
 
441
        this_tree = self.make_branch_and_tree('this')
 
442
        self.build_tree_contents([('this/file', "a\n")])
 
443
        this_tree.add('file')
 
444
        this_tree.commit('rev1')
 
445
        other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
 
446
        self.build_tree_contents([('other/file', "a\nb\n")])
 
447
        other_tree.commit('rev2b')
 
448
        self.build_tree_contents([('other/file', "c\na\nb\n")])
 
449
        other_tree.commit('rev3b')
 
450
        self.run_bzr('merge --weave -d this other -r -2..-1')
 
451
        self.assertFileEqual('c\na\n', 'this/file')
 
452
 
 
453
    def test_lca_merge_criss_cross(self):
 
454
        tree_a = self.make_branch_and_tree('a')
 
455
        self.build_tree_contents([('a/file', 'base-contents\n')])
 
456
        tree_a.add('file')
 
457
        tree_a.commit('', rev_id='rev1')
 
458
        tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
 
459
        self.build_tree_contents([('a/file',
 
460
                                   'base-contents\nthis-contents\n')])
 
461
        tree_a.commit('', rev_id='rev2a')
 
462
        self.build_tree_contents([('b/file',
 
463
                                   'base-contents\nother-contents\n')])
 
464
        tree_b.commit('', rev_id='rev2b')
 
465
        tree_a.merge_from_branch(tree_b.branch)
 
466
        self.build_tree_contents([('a/file',
 
467
                                   'base-contents\nthis-contents\n')])
 
468
        tree_a.set_conflicts(ConflictList())
 
469
        tree_b.merge_from_branch(tree_a.branch)
 
470
        self.build_tree_contents([('b/file',
 
471
                                   'base-contents\nother-contents\n')])
 
472
        tree_b.set_conflicts(ConflictList())
 
473
        tree_a.commit('', rev_id='rev3a')
 
474
        tree_b.commit('', rev_id='rev3b')
 
475
        out, err = self.run_bzr(['merge', '-d', 'a', 'b', '--lca'], retcode=1)
 
476
        self.assertFileEqual('base-contents\n<<<<<<< TREE\nthis-contents\n'
 
477
                             '=======\nother-contents\n>>>>>>> MERGE-SOURCE\n',
 
478
                             'a/file')
 
479
 
 
480
    def test_merge_preview(self):
 
481
        this_tree = self.make_branch_and_tree('this')
 
482
        this_tree.commit('rev1')
 
483
        other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
 
484
        self.build_tree_contents([('other/file', 'new line')])
 
485
        other_tree.add('file')
 
486
        other_tree.commit('rev2a')
 
487
        this_tree.commit('rev2b')
 
488
        out, err = self.run_bzr(['merge', '-d', 'this', 'other', '--preview'])
 
489
        self.assertContainsRe(out, '\+new line')
 
490
        self.assertNotContainsRe(err, '\+N  file\n')
 
491
        this_tree.lock_read()
 
492
        self.addCleanup(this_tree.unlock)
 
493
        self.assertEqual([],
 
494
                         list(this_tree.iter_changes(this_tree.basis_tree())))