1
# Copyright (C) 2006-2011 Canonical Ltd
1
# Copyright (C) 2006-2010 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
111
101
# Merging a branch pulls its revision into the tree
112
102
b = branch.Branch.open('../b')
113
103
b_tip = b.last_revision()
114
self.assertTrue(a.branch.repository.has_revision(b_tip))
104
self.failUnless(a.branch.repository.has_revision(b_tip))
115
105
self.assertEqual([a_tip, b_tip], a.get_parent_ids())
116
106
a_tree.revert(backups=False)
117
107
out, err = self.run_bzr('merge -r revno:1:./hello', retcode=3)
213
203
b_tree.commit(message='Modified a.txt')
215
205
self.run_bzr('merge ../a/', retcode=1)
216
self.assertPathExists('sub/a.txt.THIS')
217
self.assertPathExists('sub/a.txt.BASE')
206
self.failUnlessExists('sub/a.txt.THIS')
207
self.failUnlessExists('sub/a.txt.BASE')
219
209
self.run_bzr('merge ../b/', retcode=1)
220
self.assertPathExists('sub/a.txt.OTHER')
221
self.assertPathExists('sub/a.txt.BASE')
210
self.failUnlessExists('sub/a.txt.OTHER')
211
self.failUnlessExists('sub/a.txt.BASE')
223
213
def test_conflict_leaves_base_this_other_files(self):
224
214
tree, other = self.create_conflicting_branches()
335
325
tree_a.add(['file_1', 'file_2'])
336
326
tree_a.commit('commit 1')
337
327
tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
338
self.assertPathExists('b/file_1')
328
self.failUnlessExists('b/file_1')
339
329
tree_a.rename_one('file_1', 'file_i')
340
330
tree_a.commit('commit 2')
341
331
tree_a.rename_one('file_2', 'file_ii')
343
333
self.run_bzr('merge a --uncommitted -d b')
344
self.assertPathExists('b/file_1')
345
self.assertPathExists('b/file_ii')
334
self.failUnlessExists('b/file_1')
335
self.failUnlessExists('b/file_ii')
347
337
self.run_bzr_error(('Cannot use --uncommitted and --revision',),
348
338
'merge /a --uncommitted -r1 -d b')
356
346
tree_a.add(['file1', 'file2'])
357
347
os.chdir('tree_b')
358
348
self.run_bzr(['merge', '--uncommitted', '../tree_a/file1'])
359
self.assertPathExists('file1')
360
self.assertPathDoesNotExist('file2')
362
def test_merge_nonexistent_file(self):
363
"""It should not be possible to merge changes from a file which
365
tree_a = self.make_branch_and_tree('tree_a')
366
self.build_tree_contents([('tree_a/file', 'bar\n')])
368
tree_a.commit('commit 1')
370
self.run_bzr_error(('Path\(s\) do not exist: non/existing',),
371
['merge', 'non/existing'])
349
self.failUnlessExists('file1')
350
self.failIfExists('file2')
373
352
def pullable_branch(self):
374
353
tree_a = self.make_branch_and_tree('a')
375
self.build_tree_contents([('a/file', 'bar\n')])
354
self.build_tree(['a/file'])
376
355
tree_a.add(['file'])
377
356
self.id1 = tree_a.commit('commit 1')
379
358
tree_b = self.make_branch_and_tree('b')
380
359
tree_b.pull(tree_a.branch)
381
self.build_tree_contents([('b/file', 'foo\n')])
360
file('b/file', 'wb').write('foo')
382
361
self.id2 = tree_b.commit('commit 2')
384
363
def test_merge_pull(self):
389
368
tree_a = workingtree.WorkingTree.open('.')
390
369
self.assertEqual([self.id2], tree_a.get_parent_ids())
392
def test_merge_pull_preview(self):
393
self.pullable_branch()
394
(out, err) = self.run_bzr('merge --pull --preview -d a b')
395
self.assertThat(out, matchers.DocTestMatches(
396
"""=== modified file 'file'
403
""", doctest.ELLIPSIS | doctest.REPORT_UDIFF))
404
tree_a = workingtree.WorkingTree.open('a')
405
self.assertEqual([self.id1], tree_a.get_parent_ids())
407
371
def test_merge_kind_change(self):
408
372
tree_a = self.make_branch_and_tree('tree_a')
409
373
self.build_tree_contents([('tree_a/file', 'content_1')])
443
407
self.write_directive('directive', source.branch, 'target', 'rev2',
445
409
out, err = self.run_bzr('merge -d target directive')
446
self.assertPathDoesNotExist('target/a')
447
self.assertPathExists('target/b')
410
self.failIfExists('target/a')
411
self.failUnlessExists('target/b')
448
412
self.assertContainsRe(err, 'Performing cherrypick')
450
414
def write_directive(self, filename, source, target, revision_id,
485
449
branch_b.add('file2')
486
450
branch_b.commit('added file2', rev_id='rev2b')
487
451
branch_b.merge_from_branch(branch_a.branch)
488
self.assertPathExists('branch_b/file1')
452
self.failUnlessExists('branch_b/file1')
489
453
branch_b.commit('merged branch_a', rev_id='rev3b')
491
455
# It works if the revid has an interger revno
492
456
self.run_bzr('merge -d target -r revid:rev2a branch_a')
493
self.assertPathExists('target/file1')
494
self.assertPathDoesNotExist('target/file2')
457
self.failUnlessExists('target/file1')
458
self.failIfExists('target/file2')
497
461
# It should work if the revid has no integer revno
498
462
self.run_bzr('merge -d target -r revid:rev2a branch_b')
499
self.assertPathExists('target/file1')
500
self.assertPathDoesNotExist('target/file2')
463
self.failUnlessExists('target/file1')
464
self.failIfExists('target/file2')
502
466
def assertDirectoryContent(self, directory, entries, message=''):
503
467
"""Assert whether entries (file or directories) exist in a directory.
552
516
def test_merge_from_submit(self):
553
517
tree_a = self.make_branch_and_tree('a')
554
tree_a.commit('test')
555
518
tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
556
519
tree_c = tree_a.bzrdir.sprout('c').open_workingtree()
557
520
out, err = self.run_bzr(['merge', '-d', 'c'])
563
526
def test_remember_sets_submit(self):
564
527
tree_a = self.make_branch_and_tree('a')
565
tree_a.commit('rev1')
566
528
tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
567
529
self.assertIs(tree_b.branch.get_submit_branch(), None)
575
537
self.assertEqual(tree_b.branch.get_submit_branch(),
576
538
tree_a.bzrdir.root_transport.base)
578
def test_no_remember_dont_set_submit(self):
579
tree_a = self.make_branch_and_tree('a')
580
self.build_tree_contents([('a/file', "a\n")])
582
tree_a.commit('rev1')
583
tree_b = tree_a.bzrdir.sprout('b').open_workingtree()
584
self.assertIs(tree_b.branch.get_submit_branch(), None)
586
# Remember should not happen if using default from parent
587
out, err = self.run_bzr(['merge', '-d', 'b', '--no-remember'])
588
self.assertEquals(None, tree_b.branch.get_submit_branch())
590
# Remember should not happen if user supplies location but ask for not
592
out, err = self.run_bzr(['merge', '-d', 'b', '--no-remember', 'a'])
593
self.assertEqual(None, tree_b.branch.get_submit_branch())
595
540
def test_weave_cherrypick(self):
596
541
this_tree = self.make_branch_and_tree('this')
597
542
self.build_tree_contents([('this/file', "a\n")])
657
602
other.add('other_file')
658
603
other.commit('rev1b')
659
604
self.run_bzr('merge -d this other -r0..')
660
self.assertPathExists('this/other_file')
605
self.failUnlessExists('this/other_file')
662
607
def test_merge_interactive_unlocks_branch(self):
663
608
this = self.make_branch_and_tree('this')
664
this.commit('empty commit')
665
other = this.bzrdir.sprout('other').open_workingtree()
666
other.commit('empty commit 2')
609
other = self.make_branch_and_tree('other')
610
other.commit('empty commit')
667
611
self.run_bzr('merge -i -d this other')
668
612
this.lock_write()
615
def test_merge_reversed_revision_range(self):
616
tree = self.make_branch_and_tree(".")
620
tree.commit("added "+f)
621
for context in (".", "", "a"):
622
self.run_bzr("merge -r 1..0 " + context)
623
self.failIfExists("a")
625
self.failUnlessExists("a")
671
627
def test_merge_fetches_tags(self):
672
628
"""Tags are updated by merge, and revisions named in those tags are
681
637
builder.build_commit(message="Rev 2a", rev_id='rev-2a')
682
638
source.tags.set_tag('tag-a', 'rev-2a')
683
639
source.set_last_revision_info(1, 'rev-1')
684
source.get_config().set_user_option('branch.fetch_tags', 'True')
685
640
builder.build_commit(message="Rev 2b", rev_id='rev-2b')
686
641
# Merge from source
687
642
self.run_bzr('merge -d target source')
691
646
target.repository.get_revision('rev-2a')
694
class TestMergeRevisionRange(tests.TestCaseWithTransport):
696
scenarios = (('whole-tree', dict(context='.')),
697
('file-only', dict(context='a')))
700
super(TestMergeRevisionRange, self).setUp()
701
self.tree = self.make_branch_and_tree(".")
702
self.tree.commit('initial commit')
706
self.tree.commit("added " + f)
708
def test_merge_reversed_revision_range(self):
709
self.run_bzr("merge -r 2..1 " + self.context)
710
self.assertPathDoesNotExist("a")
711
self.assertPathExists("b")
714
class TestMergeScript(script.TestCaseWithTransportAndScript):
715
def test_merge_empty_branch(self):
716
source = self.make_branch_and_tree('source')
717
self.build_tree(['source/a'])
719
source.commit('Added a', rev_id='rev1')
720
target = self.make_branch_and_tree('target')
722
$ bzr merge -d target source
723
2>bzr: ERROR: Merging into empty branches not currently supported, https://bugs.launchpad.net/bzr/+bug/308562
726
649
class TestMergeForce(tests.TestCaseWithTransport):