44
44
tree.commit(message='setup')
47
def create_conflicting_branches(self):
48
"""Create two branches which have overlapping modifications.
50
:return: (tree, other_branch) Where merging other_branch causes a file
53
builder = self.make_branch_builder('branch')
54
builder.build_snapshot('rev1', None,
55
[('add', ('', 'root-id', 'directory', None)),
56
('add', ('fname', 'f-id', 'file', 'a\nb\nc\n'))])
57
builder.build_snapshot('rev2other', ['rev1'],
58
[('modify', ('f-id', 'a\nB\nD\n'))])
59
other = builder.get_branch().bzrdir.sprout('other').open_branch()
60
builder.build_snapshot('rev2this', ['rev1'],
61
[('modify', ('f-id', 'a\nB\nC\n'))])
62
tree = builder.get_branch().create_checkout('tree', lightweight=True)
65
47
def test_merge_reprocess(self):
66
48
d = BzrDir.create_standalone_workingtree('.')
119
99
self.run_bzr('merge ../b -r last:1')
120
100
self.assertEqual([a_tip], a.get_parent_ids())
122
def test_merge_defaults_to_reprocess(self):
123
tree, other = self.create_conflicting_branches()
124
# The default merge algorithm should enable 'reprocess' because
125
# 'show-base' is not set
126
self.run_bzr('merge ../other', working_dir='tree',
128
self.assertEqualDiff('a\n'
134
'>>>>>>> MERGE-SOURCE\n',
135
tree.get_file_text('f-id'))
137
def test_merge_explicit_reprocess_show_base(self):
138
tree, other = self.create_conflicting_branches()
139
# Explicitly setting --reprocess, and --show-base is an error
140
self.run_bzr_error(['Cannot do conflict reduction and show base'],
141
'merge ../other --reprocess --show-base',
144
def test_merge_override_reprocess(self):
145
tree, other = self.create_conflicting_branches()
146
# Explicitly disable reprocess
147
self.run_bzr('merge ../other --no-reprocess', working_dir='tree',
149
self.assertEqualDiff('a\n'
156
'>>>>>>> MERGE-SOURCE\n',
157
tree.get_file_text('f-id'))
159
def test_merge_override_show_base(self):
160
tree, other = self.create_conflicting_branches()
161
# Setting '--show-base' will auto-disable '--reprocess'
162
self.run_bzr('merge ../other --show-base', working_dir='tree',
164
self.assertEqualDiff('a\n'
168
'||||||| BASE-REVISION\n'
174
'>>>>>>> MERGE-SOURCE\n',
175
tree.get_file_text('f-id'))
177
102
def test_merge_with_missing_file(self):
178
103
"""Merge handles missing file conflicts"""
179
104
self.build_tree_contents([
236
161
out = self.run_bzr('merge', retcode=3)
237
162
self.assertEquals(out,
238
163
('','bzr: ERROR: No location specified or remembered\n'))
240
# test uncommitted changes
164
# test implicit --remember when no parent set, this merge conflicts
241
165
self.build_tree(['d'])
243
167
self.run_bzr_error(['Working tree ".*" has uncommitted changes'],
246
# merge should now pass and implicitly remember merge location
169
self.assertEquals(abspath(branch_b.get_parent()), abspath(parent))
170
# test implicit --remember after resolving conflict
247
171
tree_b.commit('commit d')
248
out, err = self.run_bzr('merge ../branch_a')
172
out, err = self.run_bzr('merge')
250
174
base = urlutils.local_path_from_url(branch_a.base)
251
self.assertEndsWith(err, '+N b\nAll changes applied successfully.\n')
252
self.assertEquals(abspath(branch_b.get_submit_branch()),
254
# test implicit --remember when committing new file
255
self.build_tree(['e'])
257
tree_b.commit('commit e')
258
out, err = self.run_bzr('merge')
259
self.assertStartsWith(err,
260
'Merging from remembered submit location %s\n' % (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))
261
178
# re-open tree as external run_bzr modified it
262
179
tree_b = branch_b.bzrdir.open_workingtree()
263
180
tree_b.commit('merge branch_a')
476
380
# pick 1 revision with option --changes
477
381
self.run_bzr('merge -d target -c revid:rev_d source')
478
382
self.assertDirectoryContent('target', ['.bzr', 'a', 'd'])
480
def test_merge_criss_cross(self):
481
tree_a = self.make_branch_and_tree('a')
482
tree_a.commit('', rev_id='rev1')
483
tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
484
tree_a.commit('', rev_id='rev2a')
485
tree_b.commit('', rev_id='rev2b')
486
tree_a.merge_from_branch(tree_b.branch)
487
tree_b.merge_from_branch(tree_a.branch)
488
tree_a.commit('', rev_id='rev3a')
489
tree_b.commit('', rev_id='rev3b')
490
graph = tree_a.branch.repository.get_graph(tree_b.branch.repository)
491
out, err = self.run_bzr(['merge', '-d', 'a', 'b'])
492
self.assertContainsRe(err, 'Warning: criss-cross merge encountered.')
494
def test_merge_force(self):
495
tree_a = self.make_branch_and_tree('a')
496
self.build_tree(['a/foo'])
498
tree_a.commit('add file')
499
tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
500
self.build_tree_contents([('a/foo', 'change 1')])
501
tree_a.commit('change file')
502
tree_b.merge_from_branch(tree_a.branch)
503
tree_a.commit('empty change to allow merge to run')
504
self.run_bzr(['merge', '../a', '--force'], working_dir='b')
506
def test_merge_from_submit(self):
507
tree_a = self.make_branch_and_tree('a')
508
tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
509
tree_c = tree_a.bzrdir.sprout('c').open_workingtree()
510
out, err = self.run_bzr(['merge', '-d', 'c'])
511
self.assertContainsRe(err, 'Merging from remembered parent location .*a\/')
512
tree_c.branch.set_submit_branch(tree_b.bzrdir.root_transport.base)
513
out, err = self.run_bzr(['merge', '-d', 'c'])
514
self.assertContainsRe(err, 'Merging from remembered submit location .*b\/')
516
def test_remember_sets_submit(self):
517
tree_a = self.make_branch_and_tree('a')
518
tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
519
self.assertIs(tree_b.branch.get_submit_branch(), None)
521
# Remember should not happen if using default from parent
522
out, err = self.run_bzr(['merge', '-d', 'b'])
523
self.assertIs(tree_b.branch.get_submit_branch(), None)
525
# Remember should happen if user supplies location
526
out, err = self.run_bzr(['merge', '-d', 'b', 'a'])
527
self.assertEqual(tree_b.branch.get_submit_branch(),
528
tree_a.bzrdir.root_transport.base)
530
def test_weave_cherrypick(self):
531
this_tree = self.make_branch_and_tree('this')
532
self.build_tree_contents([('this/file', "a\n")])
533
this_tree.add('file')
534
this_tree.commit('rev1')
535
other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
536
self.build_tree_contents([('other/file', "a\nb\n")])
537
other_tree.commit('rev2b')
538
self.build_tree_contents([('other/file', "c\na\nb\n")])
539
other_tree.commit('rev3b')
540
self.run_bzr('merge --weave -d this other -r -2..-1')
541
self.assertFileEqual('c\na\n', 'this/file')
543
def test_lca_merge_criss_cross(self):
544
tree_a = self.make_branch_and_tree('a')
545
self.build_tree_contents([('a/file', 'base-contents\n')])
547
tree_a.commit('', rev_id='rev1')
548
tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
549
self.build_tree_contents([('a/file',
550
'base-contents\nthis-contents\n')])
551
tree_a.commit('', rev_id='rev2a')
552
self.build_tree_contents([('b/file',
553
'base-contents\nother-contents\n')])
554
tree_b.commit('', rev_id='rev2b')
555
tree_a.merge_from_branch(tree_b.branch)
556
self.build_tree_contents([('a/file',
557
'base-contents\nthis-contents\n')])
558
tree_a.set_conflicts(ConflictList())
559
tree_b.merge_from_branch(tree_a.branch)
560
self.build_tree_contents([('b/file',
561
'base-contents\nother-contents\n')])
562
tree_b.set_conflicts(ConflictList())
563
tree_a.commit('', rev_id='rev3a')
564
tree_b.commit('', rev_id='rev3b')
565
out, err = self.run_bzr(['merge', '-d', 'a', 'b', '--lca'], retcode=1)
566
self.assertFileEqual('base-contents\n<<<<<<< TREE\nthis-contents\n'
567
'=======\nother-contents\n>>>>>>> MERGE-SOURCE\n',
570
def test_merge_preview(self):
571
this_tree = self.make_branch_and_tree('this')
572
this_tree.commit('rev1')
573
other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
574
self.build_tree_contents([('other/file', 'new line')])
575
other_tree.add('file')
576
other_tree.commit('rev2a')
577
this_tree.commit('rev2b')
578
out, err = self.run_bzr(['merge', '-d', 'this', 'other', '--preview'])
579
self.assertContainsRe(out, '\+new line')
580
self.assertNotContainsRe(err, '\+N file\n')
581
this_tree.lock_read()
582
self.addCleanup(this_tree.unlock)
584
list(this_tree.iter_changes(this_tree.basis_tree())))
586
def test_merge_missing_second_revision_spec(self):
587
"""Merge uses branch basis when the second revision is unspecified."""
588
this = self.make_branch_and_tree('this')
590
other = self.make_branch_and_tree('other')
591
self.build_tree(['other/other_file'])
592
other.add('other_file')
593
other.commit('rev1b')
594
self.run_bzr('merge -d this other -r0..')
595
self.failUnlessExists('this/other_file')