89
80
self.build_tree_contents([('a/hello', 'quuux')])
90
81
# We can't merge when there are in-tree changes
91
self.run_bzr('merge ../b', retcode=3, working_dir='a')
92
a = workingtree.WorkingTree.open('a')
83
self.run_bzr('merge ../b', retcode=3)
84
a = workingtree.WorkingTree.open('.')
93
85
a_tip = a.commit("Like an epidemic of u's")
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'])
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)
105
94
self.run_bzr_error(['Show-base is not supported for this merge type'],
106
95
'merge ../b -r last:1..last:1 --merge-type weave'
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')
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')
114
102
# Merging a branch pulls its revision into the tree
115
b = branch.Branch.open('b')
103
b = branch.Branch.open('../b')
116
104
b_tip = b.last_revision()
117
self.assertTrue(a.branch.repository.has_revision(b_tip))
105
self.failUnless(a.branch.repository.has_revision(b_tip))
118
106
self.assertEqual([a_tip, b_tip], a.get_parent_ids())
119
107
a_tree.revert(backups=False)
120
out, err = self.run_bzr('merge -r revno:1:./hello', retcode=3,
108
out, err = self.run_bzr('merge -r revno:1:./hello', retcode=3)
122
109
self.assertTrue("Not a branch" in err)
123
110
self.run_bzr('merge -r revno:%d:./..revno:%d:../b'
124
%(ancestor,b.revno()), working_dir='a')
111
%(ancestor,b.revno()))
125
112
self.assertEquals(a.get_parent_ids(),
126
113
[a.branch.last_revision(), b.last_revision()])
127
self.check_file_contents('a/goodbye', 'quux')
114
self.check_file_contents('goodbye', 'quux')
128
115
a_tree.revert(backups=False)
129
self.run_bzr('merge -r revno:%d:../b'%b.revno(), working_dir='a')
116
self.run_bzr('merge -r revno:%d:../b'%b.revno())
130
117
self.assertEquals(a.get_parent_ids(),
131
118
[a.branch.last_revision(), b.last_revision()])
132
119
a_tip = a.commit('merged')
133
self.run_bzr('merge ../b -r last:1', working_dir='a')
120
self.run_bzr('merge ../b -r last:1')
134
121
self.assertEqual([a_tip], a.get_parent_ids())
136
123
def test_merge_defaults_to_reprocess(self):
215
202
('b/b.txt', 'hello\nsomething\n'),
216
203
('b/sub/c.txt', 'hello\nsomething\n')])
217
204
b_tree.commit(message='Modified a.txt')
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')
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')
227
214
def test_conflict_leaves_base_this_other_files(self):
228
215
tree, other = self.create_conflicting_branches()
262
249
branch_b.set_parent(None)
263
250
self.assertEqual(None, branch_b.get_parent())
264
251
# test merge for failure without parent set
265
out = self.run_bzr('merge', retcode=3, working_dir='branch_b')
253
out = self.run_bzr('merge', retcode=3)
266
254
self.assertEquals(out,
267
255
('','bzr: ERROR: No location specified or remembered\n'))
269
257
# test uncommitted changes
270
self.build_tree(['branch_b/d'])
258
self.build_tree(['d'])
272
260
self.run_bzr_error(['Working tree ".*" has uncommitted changes'],
273
'merge', working_dir='branch_b')
275
263
# merge should now pass and implicitly remember merge location
276
264
tree_b.commit('commit d')
277
out, err = self.run_bzr('merge ../branch_a', working_dir='branch_b')
265
out, err = self.run_bzr('merge ../branch_a')
279
267
base = urlutils.local_path_from_url(branch_a.base)
280
268
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()
283
269
self.assertEquals(osutils.abspath(branch_b.get_submit_branch()),
284
270
osutils.abspath(parent))
285
271
# test implicit --remember when committing new file
286
self.build_tree(['branch_b/e'])
272
self.build_tree(['e'])
288
274
tree_b.commit('commit e')
289
out, err = self.run_bzr('merge', working_dir='branch_b')
290
self.assertStartsWith(
291
err, 'Merging from remembered submit location %s\n' % (base,))
275
out, err = self.run_bzr('merge')
276
self.assertStartsWith(err,
277
'Merging from remembered submit location %s\n' % (base,))
292
278
# re-open tree as external run_bzr modified it
293
279
tree_b = branch_b.bzrdir.open_workingtree()
294
280
tree_b.commit('merge branch_a')
295
281
# test explicit --remember
296
out, err = self.run_bzr('merge ../branch_c --remember',
297
working_dir='branch_b')
282
out, err = self.run_bzr('merge ../branch_c --remember')
298
283
self.assertEquals(out, '')
299
284
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()
302
285
self.assertEquals(osutils.abspath(branch_b.get_submit_branch()),
303
286
osutils.abspath(branch_c.bzrdir.root_transport.base))
304
287
# re-open tree as external run_bzr modified it
341
326
tree_a.add(['file_1', 'file_2'])
342
327
tree_a.commit('commit 1')
343
328
tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
344
self.assertPathExists('b/file_1')
329
self.failUnlessExists('b/file_1')
345
330
tree_a.rename_one('file_1', 'file_i')
346
331
tree_a.commit('commit 2')
347
332
tree_a.rename_one('file_2', 'file_ii')
348
334
self.run_bzr('merge a --uncommitted -d b')
349
self.assertPathExists('b/file_1')
350
self.assertPathExists('b/file_ii')
335
self.failUnlessExists('b/file_1')
336
self.failUnlessExists('b/file_ii')
352
338
self.run_bzr_error(('Cannot use --uncommitted and --revision',),
353
339
'merge /a --uncommitted -r1 -d b')
359
345
tree_a.bzrdir.sprout('tree_b')
360
346
self.build_tree(['tree_a/file1', 'tree_a/file2'])
361
347
tree_a.add(['file1', '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')
349
self.run_bzr(['merge', '--uncommitted', '../tree_a/file1'])
350
self.failUnlessExists('file1')
351
self.failIfExists('file2')
377
353
def pullable_branch(self):
378
354
tree_a = self.make_branch_and_tree('a')
379
self.build_tree_contents([('a/file', 'bar\n')])
355
self.build_tree(['a/file'])
380
356
tree_a.add(['file'])
381
357
self.id1 = tree_a.commit('commit 1')
383
359
tree_b = self.make_branch_and_tree('b')
384
360
tree_b.pull(tree_a.branch)
385
self.build_tree_contents([('b/file', 'foo\n')])
361
file('b/file', 'wb').write('foo')
386
362
self.id2 = tree_b.commit('commit 2')
388
364
def test_merge_pull(self):
389
365
self.pullable_branch()
390
(out, err) = self.run_bzr('merge --pull ../b', working_dir='a')
367
(out, err) = self.run_bzr('merge --pull ../b')
391
368
self.assertContainsRe(out, 'Now on revision 2\\.')
392
tree_a = workingtree.WorkingTree.open('a')
369
tree_a = workingtree.WorkingTree.open('.')
393
370
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())
410
372
def test_merge_kind_change(self):
411
373
tree_a = self.make_branch_and_tree('tree_a')
412
374
self.build_tree_contents([('tree_a/file', 'content_1')])
416
378
os.unlink('tree_a/file')
417
379
self.build_tree(['tree_a/file/'])
418
380
tree_a.commit('changed file to directory')
419
self.run_bzr('merge ../tree_a', working_dir='tree_b')
420
self.assertEqual('directory', osutils.file_kind('tree_b/file'))
382
self.run_bzr('merge ../tree_a')
383
self.assertEqual('directory', osutils.file_kind('file'))
422
self.assertEqual('file', osutils.file_kind('tree_b/file'))
423
self.build_tree_contents([('tree_b/file', 'content_2')])
385
self.assertEqual('file', osutils.file_kind('file'))
386
self.build_tree_contents([('file', 'content_2')])
424
387
tree_b.commit('content change')
425
self.run_bzr('merge ../tree_a', retcode=1, working_dir='tree_b')
388
self.run_bzr('merge ../tree_a', retcode=1)
426
389
self.assertEqual(tree_b.conflicts(),
427
390
[conflicts.ContentsConflict('file',
428
391
file_id='file-id')])
445
408
self.write_directive('directive', source.branch, 'target', 'rev2',
447
410
out, err = self.run_bzr('merge -d target directive')
448
self.assertPathDoesNotExist('target/a')
449
self.assertPathExists('target/b')
411
self.failIfExists('target/a')
412
self.failUnlessExists('target/b')
450
413
self.assertContainsRe(err, 'Performing cherrypick')
452
415
def write_directive(self, filename, source, target, revision_id,
487
450
branch_b.add('file2')
488
451
branch_b.commit('added file2', rev_id='rev2b')
489
452
branch_b.merge_from_branch(branch_a.branch)
490
self.assertPathExists('branch_b/file1')
453
self.failUnlessExists('branch_b/file1')
491
454
branch_b.commit('merged branch_a', rev_id='rev3b')
493
456
# It works if the revid has an interger revno
494
457
self.run_bzr('merge -d target -r revid:rev2a branch_a')
495
self.assertPathExists('target/file1')
496
self.assertPathDoesNotExist('target/file2')
458
self.failUnlessExists('target/file1')
459
self.failIfExists('target/file2')
499
462
# It should work if the revid has no integer revno
500
463
self.run_bzr('merge -d target -r revid:rev2a branch_b')
501
self.assertPathExists('target/file1')
502
self.assertPathDoesNotExist('target/file2')
464
self.failUnlessExists('target/file1')
465
self.failIfExists('target/file2')
504
467
def assertDirectoryContent(self, directory, entries, message=''):
505
468
"""Assert whether entries (file or directories) exist in a directory.
554
517
def test_merge_from_submit(self):
555
518
tree_a = self.make_branch_and_tree('a')
556
tree_a.commit('test')
557
519
tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
558
520
tree_c = tree_a.bzrdir.sprout('c').open_workingtree()
559
521
out, err = self.run_bzr(['merge', '-d', 'c'])
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()
522
self.assertContainsRe(err, 'Merging from remembered parent location .*a\/')
523
tree_c.branch.set_submit_branch(tree_b.bzrdir.root_transport.base)
567
524
out, err = self.run_bzr(['merge', '-d', 'c'])
568
self.assertContainsRe(err,
569
'Merging from remembered submit location .*b\/')
525
self.assertContainsRe(err, 'Merging from remembered submit location .*b\/')
571
527
def test_remember_sets_submit(self):
572
528
tree_a = self.make_branch_and_tree('a')
573
tree_a.commit('rev1')
574
529
tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
575
530
self.assertIs(tree_b.branch.get_submit_branch(), None)
577
532
# Remember should not happen if using default from parent
578
533
out, err = self.run_bzr(['merge', '-d', 'b'])
579
refreshed = workingtree.WorkingTree.open('b')
580
self.assertIs(refreshed.branch.get_submit_branch(), None)
534
self.assertIs(tree_b.branch.get_submit_branch(), None)
582
536
# Remember should happen if user supplies location
583
537
out, err = self.run_bzr(['merge', '-d', 'b', 'a'])
584
refreshed = workingtree.WorkingTree.open('b')
585
self.assertEqual(refreshed.branch.get_submit_branch(),
538
self.assertEqual(tree_b.branch.get_submit_branch(),
586
539
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())
605
541
def test_weave_cherrypick(self):
606
542
this_tree = self.make_branch_and_tree('this')
607
543
self.build_tree_contents([('this/file', "a\n")])
667
603
other.add('other_file')
668
604
other.commit('rev1b')
669
605
self.run_bzr('merge -d this other -r0..')
670
self.assertPathExists('this/other_file')
606
self.failUnlessExists('this/other_file')
672
608
def test_merge_interactive_unlocks_branch(self):
673
609
this = self.make_branch_and_tree('this')
674
this.commit('empty commit')
675
other = this.bzrdir.sprout('other').open_workingtree()
676
other.commit('empty commit 2')
610
other = self.make_branch_and_tree('other')
611
other.commit('empty commit')
677
612
self.run_bzr('merge -i -d this other')
678
613
this.lock_write()
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')
616
def test_merge_reversed_revision_range(self):
617
tree = self.make_branch_and_tree(".")
713
618
for f in ("a", "b"):
714
619
self.build_tree([f])
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
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")
736
629
class TestMergeForce(tests.TestCaseWithTransport):