80
89
self.build_tree_contents([('a/hello', 'quuux')])
81
90
# We can't merge when there are in-tree changes
83
self.run_bzr('merge ../b', retcode=3)
84
a = workingtree.WorkingTree.open('.')
91
self.run_bzr('merge ../b', retcode=3, working_dir='a')
92
a = workingtree.WorkingTree.open('a')
85
93
a_tip = a.commit("Like an epidemic of u's")
86
self.run_bzr('merge ../b -r last:1..last:1 --merge-type blooof',
88
self.run_bzr('merge ../b -r last:1..last:1 --merge-type merge3')
89
a_tree.revert(backups=False)
90
self.run_bzr('merge ../b -r last:1..last:1 --merge-type weave')
91
a_tree.revert(backups=False)
92
self.run_bzr('merge ../b -r last:1..last:1 --merge-type lca')
93
a_tree.revert(backups=False)
95
def run_merge_then_revert(args, retcode=None, working_dir='a'):
96
self.run_bzr(['merge', '../b', '-r', 'last:1..last:1'] + args,
97
retcode=retcode, working_dir=working_dir)
99
a_tree.revert(backups=False)
101
run_merge_then_revert(['--merge-type', 'bloof'], retcode=3)
102
run_merge_then_revert(['--merge-type', 'merge3'])
103
run_merge_then_revert(['--merge-type', 'weave'])
104
run_merge_then_revert(['--merge-type', 'lca'])
94
105
self.run_bzr_error(['Show-base is not supported for this merge type'],
95
106
'merge ../b -r last:1..last:1 --merge-type weave'
97
a_tree.revert(backups=False)
98
self.run_bzr('merge ../b -r last:1..last:1 --reprocess')
99
a_tree.revert(backups=False)
100
self.run_bzr('merge ../b -r last:1')
101
self.check_file_contents('goodbye', 'quux')
107
' --show-base', working_dir='a')
108
a_tree.revert(backups=False)
109
self.run_bzr('merge ../b -r last:1..last:1 --reprocess',
111
a_tree.revert(backups=False)
112
self.run_bzr('merge ../b -r last:1', working_dir='a')
113
self.check_file_contents('a/goodbye', 'quux')
102
114
# Merging a branch pulls its revision into the tree
103
b = branch.Branch.open('../b')
115
b = branch.Branch.open('b')
104
116
b_tip = b.last_revision()
105
self.failUnless(a.branch.repository.has_revision(b_tip))
117
self.assertTrue(a.branch.repository.has_revision(b_tip))
106
118
self.assertEqual([a_tip, b_tip], a.get_parent_ids())
107
119
a_tree.revert(backups=False)
108
out, err = self.run_bzr('merge -r revno:1:./hello', retcode=3)
120
out, err = self.run_bzr('merge -r revno:1:./hello', retcode=3,
109
122
self.assertTrue("Not a branch" in err)
110
123
self.run_bzr('merge -r revno:%d:./..revno:%d:../b'
111
%(ancestor,b.revno()))
124
%(ancestor,b.revno()), working_dir='a')
112
125
self.assertEquals(a.get_parent_ids(),
113
126
[a.branch.last_revision(), b.last_revision()])
114
self.check_file_contents('goodbye', 'quux')
127
self.check_file_contents('a/goodbye', 'quux')
115
128
a_tree.revert(backups=False)
116
self.run_bzr('merge -r revno:%d:../b'%b.revno())
129
self.run_bzr('merge -r revno:%d:../b'%b.revno(), working_dir='a')
117
130
self.assertEquals(a.get_parent_ids(),
118
131
[a.branch.last_revision(), b.last_revision()])
119
132
a_tip = a.commit('merged')
120
self.run_bzr('merge ../b -r last:1')
133
self.run_bzr('merge ../b -r last:1', working_dir='a')
121
134
self.assertEqual([a_tip], a.get_parent_ids())
123
136
def test_merge_defaults_to_reprocess(self):
202
215
('b/b.txt', 'hello\nsomething\n'),
203
216
('b/sub/c.txt', 'hello\nsomething\n')])
204
217
b_tree.commit(message='Modified a.txt')
206
self.run_bzr('merge ../a/', retcode=1)
207
self.failUnlessExists('sub/a.txt.THIS')
208
self.failUnlessExists('sub/a.txt.BASE')
210
self.run_bzr('merge ../b/', retcode=1)
211
self.failUnlessExists('sub/a.txt.OTHER')
212
self.failUnlessExists('sub/a.txt.BASE')
219
self.run_bzr('merge ../a/', retcode=1, working_dir='b')
220
self.assertPathExists('b/sub/a.txt.THIS')
221
self.assertPathExists('b/sub/a.txt.BASE')
223
self.run_bzr('merge ../b/', retcode=1, working_dir='a')
224
self.assertPathExists('a/sub/a.txt.OTHER')
225
self.assertPathExists('a/sub/a.txt.BASE')
214
227
def test_conflict_leaves_base_this_other_files(self):
215
228
tree, other = self.create_conflicting_branches()
249
262
branch_b.set_parent(None)
250
263
self.assertEqual(None, branch_b.get_parent())
251
264
# test merge for failure without parent set
253
out = self.run_bzr('merge', retcode=3)
265
out = self.run_bzr('merge', retcode=3, working_dir='branch_b')
254
266
self.assertEquals(out,
255
267
('','bzr: ERROR: No location specified or remembered\n'))
257
269
# test uncommitted changes
258
self.build_tree(['d'])
270
self.build_tree(['branch_b/d'])
260
272
self.run_bzr_error(['Working tree ".*" has uncommitted changes'],
273
'merge', working_dir='branch_b')
263
275
# merge should now pass and implicitly remember merge location
264
276
tree_b.commit('commit d')
265
out, err = self.run_bzr('merge ../branch_a')
277
out, err = self.run_bzr('merge ../branch_a', working_dir='branch_b')
267
279
base = urlutils.local_path_from_url(branch_a.base)
268
280
self.assertEndsWith(err, '+N b\nAll changes applied successfully.\n')
281
# re-open branch as external run_bzr modified it
282
branch_b = branch_b.bzrdir.open_branch()
269
283
self.assertEquals(osutils.abspath(branch_b.get_submit_branch()),
270
284
osutils.abspath(parent))
271
285
# test implicit --remember when committing new file
272
self.build_tree(['e'])
286
self.build_tree(['branch_b/e'])
274
288
tree_b.commit('commit e')
275
out, err = self.run_bzr('merge')
276
self.assertStartsWith(err,
277
'Merging from remembered submit location %s\n' % (base,))
289
out, err = self.run_bzr('merge', working_dir='branch_b')
290
self.assertStartsWith(
291
err, 'Merging from remembered submit location %s\n' % (base,))
278
292
# re-open tree as external run_bzr modified it
279
293
tree_b = branch_b.bzrdir.open_workingtree()
280
294
tree_b.commit('merge branch_a')
281
295
# test explicit --remember
282
out, err = self.run_bzr('merge ../branch_c --remember')
296
out, err = self.run_bzr('merge ../branch_c --remember',
297
working_dir='branch_b')
283
298
self.assertEquals(out, '')
284
299
self.assertEquals(err, '+N c\nAll changes applied successfully.\n')
300
# re-open branch as external run_bzr modified it
301
branch_b = branch_b.bzrdir.open_branch()
285
302
self.assertEquals(osutils.abspath(branch_b.get_submit_branch()),
286
303
osutils.abspath(branch_c.bzrdir.root_transport.base))
287
304
# re-open tree as external run_bzr modified it
326
341
tree_a.add(['file_1', 'file_2'])
327
342
tree_a.commit('commit 1')
328
343
tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
329
self.failUnlessExists('b/file_1')
344
self.assertPathExists('b/file_1')
330
345
tree_a.rename_one('file_1', 'file_i')
331
346
tree_a.commit('commit 2')
332
347
tree_a.rename_one('file_2', 'file_ii')
334
348
self.run_bzr('merge a --uncommitted -d b')
335
self.failUnlessExists('b/file_1')
336
self.failUnlessExists('b/file_ii')
349
self.assertPathExists('b/file_1')
350
self.assertPathExists('b/file_ii')
338
352
self.run_bzr_error(('Cannot use --uncommitted and --revision',),
339
353
'merge /a --uncommitted -r1 -d b')
345
359
tree_a.bzrdir.sprout('tree_b')
346
360
self.build_tree(['tree_a/file1', 'tree_a/file2'])
347
361
tree_a.add(['file1', 'file2'])
349
self.run_bzr(['merge', '--uncommitted', '../tree_a/file1'])
350
self.failUnlessExists('file1')
351
self.failIfExists('file2')
362
self.run_bzr(['merge', '--uncommitted', '../tree_a/file1'],
363
working_dir='tree_b')
364
self.assertPathExists('tree_b/file1')
365
self.assertPathDoesNotExist('tree_b/file2')
367
def test_merge_nonexistent_file(self):
368
"""It should not be possible to merge changes from a file which
370
tree_a = self.make_branch_and_tree('tree_a')
371
self.build_tree_contents([('tree_a/file', 'bar\n')])
373
tree_a.commit('commit 1')
374
self.run_bzr_error(('Path\(s\) do not exist: non/existing',),
375
['merge', 'non/existing'], working_dir='tree_a')
353
377
def pullable_branch(self):
354
378
tree_a = self.make_branch_and_tree('a')
355
self.build_tree(['a/file'])
379
self.build_tree_contents([('a/file', 'bar\n')])
356
380
tree_a.add(['file'])
357
381
self.id1 = tree_a.commit('commit 1')
359
383
tree_b = self.make_branch_and_tree('b')
360
384
tree_b.pull(tree_a.branch)
361
file('b/file', 'wb').write('foo')
385
self.build_tree_contents([('b/file', 'foo\n')])
362
386
self.id2 = tree_b.commit('commit 2')
364
388
def test_merge_pull(self):
365
389
self.pullable_branch()
367
(out, err) = self.run_bzr('merge --pull ../b')
390
(out, err) = self.run_bzr('merge --pull ../b', working_dir='a')
368
391
self.assertContainsRe(out, 'Now on revision 2\\.')
369
tree_a = workingtree.WorkingTree.open('.')
392
tree_a = workingtree.WorkingTree.open('a')
370
393
self.assertEqual([self.id2], tree_a.get_parent_ids())
395
def test_merge_pull_preview(self):
396
self.pullable_branch()
397
(out, err) = self.run_bzr('merge --pull --preview -d a b')
398
self.assertThat(out, matchers.DocTestMatches(
399
"""=== modified file 'file'
406
""", doctest.ELLIPSIS | doctest.REPORT_UDIFF))
407
tree_a = workingtree.WorkingTree.open('a')
408
self.assertEqual([self.id1], tree_a.get_parent_ids())
372
410
def test_merge_kind_change(self):
373
411
tree_a = self.make_branch_and_tree('tree_a')
374
412
self.build_tree_contents([('tree_a/file', 'content_1')])
378
416
os.unlink('tree_a/file')
379
417
self.build_tree(['tree_a/file/'])
380
418
tree_a.commit('changed file to directory')
382
self.run_bzr('merge ../tree_a')
383
self.assertEqual('directory', osutils.file_kind('file'))
419
self.run_bzr('merge ../tree_a', working_dir='tree_b')
420
self.assertEqual('directory', osutils.file_kind('tree_b/file'))
385
self.assertEqual('file', osutils.file_kind('file'))
386
self.build_tree_contents([('file', 'content_2')])
422
self.assertEqual('file', osutils.file_kind('tree_b/file'))
423
self.build_tree_contents([('tree_b/file', 'content_2')])
387
424
tree_b.commit('content change')
388
self.run_bzr('merge ../tree_a', retcode=1)
425
self.run_bzr('merge ../tree_a', retcode=1, working_dir='tree_b')
389
426
self.assertEqual(tree_b.conflicts(),
390
427
[conflicts.ContentsConflict('file',
391
428
file_id='file-id')])
408
445
self.write_directive('directive', source.branch, 'target', 'rev2',
410
447
out, err = self.run_bzr('merge -d target directive')
411
self.failIfExists('target/a')
412
self.failUnlessExists('target/b')
448
self.assertPathDoesNotExist('target/a')
449
self.assertPathExists('target/b')
413
450
self.assertContainsRe(err, 'Performing cherrypick')
415
452
def write_directive(self, filename, source, target, revision_id,
450
487
branch_b.add('file2')
451
488
branch_b.commit('added file2', rev_id='rev2b')
452
489
branch_b.merge_from_branch(branch_a.branch)
453
self.failUnlessExists('branch_b/file1')
490
self.assertPathExists('branch_b/file1')
454
491
branch_b.commit('merged branch_a', rev_id='rev3b')
456
493
# It works if the revid has an interger revno
457
494
self.run_bzr('merge -d target -r revid:rev2a branch_a')
458
self.failUnlessExists('target/file1')
459
self.failIfExists('target/file2')
495
self.assertPathExists('target/file1')
496
self.assertPathDoesNotExist('target/file2')
462
499
# It should work if the revid has no integer revno
463
500
self.run_bzr('merge -d target -r revid:rev2a branch_b')
464
self.failUnlessExists('target/file1')
465
self.failIfExists('target/file2')
501
self.assertPathExists('target/file1')
502
self.assertPathDoesNotExist('target/file2')
467
504
def assertDirectoryContent(self, directory, entries, message=''):
468
505
"""Assert whether entries (file or directories) exist in a directory.
517
554
def test_merge_from_submit(self):
518
555
tree_a = self.make_branch_and_tree('a')
556
tree_a.commit('test')
519
557
tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
520
558
tree_c = tree_a.bzrdir.sprout('c').open_workingtree()
521
559
out, err = self.run_bzr(['merge', '-d', 'c'])
522
self.assertContainsRe(err, 'Merging from remembered parent location .*a\/')
523
tree_c.branch.set_submit_branch(tree_b.bzrdir.root_transport.base)
560
self.assertContainsRe(err,
561
'Merging from remembered parent location .*a\/')
562
tree_c.branch.lock_write()
564
tree_c.branch.set_submit_branch(tree_b.bzrdir.root_transport.base)
566
tree_c.branch.unlock()
524
567
out, err = self.run_bzr(['merge', '-d', 'c'])
525
self.assertContainsRe(err, 'Merging from remembered submit location .*b\/')
568
self.assertContainsRe(err,
569
'Merging from remembered submit location .*b\/')
527
571
def test_remember_sets_submit(self):
528
572
tree_a = self.make_branch_and_tree('a')
573
tree_a.commit('rev1')
529
574
tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
530
575
self.assertIs(tree_b.branch.get_submit_branch(), None)
532
577
# Remember should not happen if using default from parent
533
578
out, err = self.run_bzr(['merge', '-d', 'b'])
534
self.assertIs(tree_b.branch.get_submit_branch(), None)
579
refreshed = workingtree.WorkingTree.open('b')
580
self.assertIs(refreshed.branch.get_submit_branch(), None)
536
582
# Remember should happen if user supplies location
537
583
out, err = self.run_bzr(['merge', '-d', 'b', 'a'])
538
self.assertEqual(tree_b.branch.get_submit_branch(),
584
refreshed = workingtree.WorkingTree.open('b')
585
self.assertEqual(refreshed.branch.get_submit_branch(),
539
586
tree_a.bzrdir.root_transport.base)
588
def test_no_remember_dont_set_submit(self):
589
tree_a = self.make_branch_and_tree('a')
590
self.build_tree_contents([('a/file', "a\n")])
592
tree_a.commit('rev1')
593
tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
594
self.assertIs(tree_b.branch.get_submit_branch(), None)
596
# Remember should not happen if using default from parent
597
out, err = self.run_bzr(['merge', '-d', 'b', '--no-remember'])
598
self.assertEquals(None, tree_b.branch.get_submit_branch())
600
# Remember should not happen if user supplies location but ask for not
602
out, err = self.run_bzr(['merge', '-d', 'b', '--no-remember', 'a'])
603
self.assertEqual(None, tree_b.branch.get_submit_branch())
541
605
def test_weave_cherrypick(self):
542
606
this_tree = self.make_branch_and_tree('this')
543
607
self.build_tree_contents([('this/file', "a\n")])
603
667
other.add('other_file')
604
668
other.commit('rev1b')
605
669
self.run_bzr('merge -d this other -r0..')
606
self.failUnlessExists('this/other_file')
670
self.assertPathExists('this/other_file')
608
672
def test_merge_interactive_unlocks_branch(self):
609
673
this = self.make_branch_and_tree('this')
610
other = self.make_branch_and_tree('other')
611
other.commit('empty commit')
674
this.commit('empty commit')
675
other = this.bzrdir.sprout('other').open_workingtree()
676
other.commit('empty commit 2')
612
677
self.run_bzr('merge -i -d this other')
613
678
this.lock_write()
616
def test_merge_reversed_revision_range(self):
617
tree = self.make_branch_and_tree(".")
681
def test_merge_fetches_tags(self):
682
"""Tags are updated by merge, and revisions named in those tags are
685
# Make a source, sprout a target off it
686
builder = self.make_branch_builder('source')
687
builder.build_commit(message="Rev 1", rev_id='rev-1')
688
source = builder.get_branch()
689
target_bzrdir = source.bzrdir.sprout('target')
690
# Add a non-ancestry tag to source
691
builder.build_commit(message="Rev 2a", rev_id='rev-2a')
692
source.tags.set_tag('tag-a', 'rev-2a')
693
source.set_last_revision_info(1, 'rev-1')
694
source.get_config_stack().set('branch.fetch_tags', True)
695
builder.build_commit(message="Rev 2b", rev_id='rev-2b')
697
self.run_bzr('merge -d target source')
698
target = target_bzrdir.open_branch()
699
# The tag is present, and so is its revision.
700
self.assertEqual('rev-2a', target.tags.lookup_tag('tag-a'))
701
target.repository.get_revision('rev-2a')
704
class TestMergeRevisionRange(tests.TestCaseWithTransport):
706
scenarios = (('whole-tree', dict(context='.')),
707
('file-only', dict(context='a')))
710
super(TestMergeRevisionRange, self).setUp()
711
self.tree = self.make_branch_and_tree(".")
712
self.tree.commit('initial commit')
618
713
for f in ("a", "b"):
619
714
self.build_tree([f])
621
tree.commit("added "+f)
622
for context in (".", "", "a"):
623
self.run_bzr("merge -r 1..0 " + context)
624
self.failIfExists("a")
626
self.failUnlessExists("a")
716
self.tree.commit("added " + f)
718
def test_merge_reversed_revision_range(self):
719
self.run_bzr("merge -r 2..1 " + self.context)
720
self.assertPathDoesNotExist("a")
721
self.assertPathExists("b")
724
class TestMergeScript(script.TestCaseWithTransportAndScript):
725
def test_merge_empty_branch(self):
726
source = self.make_branch_and_tree('source')
727
self.build_tree(['source/a'])
729
source.commit('Added a', rev_id='rev1')
730
target = self.make_branch_and_tree('target')
732
$ bzr merge -d target source
733
2>bzr: ERROR: Merging into empty branches not currently supported, https://bugs.launchpad.net/bzr/+bug/308562
629
736
class TestMergeForce(tests.TestCaseWithTransport):