169
167
self.run_bzr_error(['Working tree ".*" has uncommitted changes'],
170
168
'merge ../branch_a')
171
self.assertEquals(abspath(branch_b.get_submit_branch()),
169
self.assertEquals(abspath(branch_b.get_parent()), abspath(parent))
173
170
# test implicit --remember after resolving conflict
174
171
tree_b.commit('commit d')
175
172
out, err = self.run_bzr('merge')
177
174
base = urlutils.local_path_from_url(branch_a.base)
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()),
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))
183
178
# re-open tree as external run_bzr modified it
184
179
tree_b = branch_b.bzrdir.open_workingtree()
185
180
tree_b.commit('merge branch_a')
398
380
# pick 1 revision with option --changes
399
381
self.run_bzr('merge -d target -c revid:rev_d source')
400
382
self.assertDirectoryContent('target', ['.bzr', 'a', 'd'])
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.')
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\/')
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)
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)
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)
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')
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')])
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',
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)
494
list(this_tree.iter_changes(this_tree.basis_tree())))