44
45
class MergeBuilder(object):
45
47
def __init__(self, dir=None):
46
48
self.dir = osutils.mkdtemp(prefix="merge-test", dir=dir)
47
49
self.tree_root = generate_ids.gen_root_id()
49
51
path = pathjoin(self.dir, name)
51
wt = bzrlib.bzrdir.BzrDir.create_standalone_workingtree(path)
53
wt = controldir.ControlDir.create_standalone_workingtree(path)
52
54
# the tests perform pulls, so need a branch that is writeable.
54
56
wt.set_root_id(self.tree_root)
542
544
"""Sucessfully merges unrelated branches with no common names"""
543
545
wta = self.make_branch_and_tree('a')
545
file('a/a_file', 'wb').write('contents\n')
547
with file('a/a_file', 'wb') as f: f.write('contents\n')
546
548
wta.add('a_file')
547
549
wta.commit('a_revision', allow_pointless=False)
548
550
wtb = self.make_branch_and_tree('b')
550
file('b/b_file', 'wb').write('contents\n')
552
with file('b/b_file', 'wb') as f: f.write('contents\n')
551
553
wtb.add('b_file')
552
554
b_rev = wtb.commit('b_revision', allow_pointless=False)
553
555
wta.merge_from_branch(wtb.branch, b_rev, 'null:')
554
self.assert_(os.path.lexists('a/b_file'))
556
self.assertTrue(os.path.lexists('a/b_file'))
555
557
self.assertEqual([b_rev], wta.get_parent_ids()[1:])
557
559
def test_merge_unrelated_conflicting(self):
558
560
"""Sucessfully merges unrelated branches with common names"""
559
561
wta = self.make_branch_and_tree('a')
561
file('a/file', 'wb').write('contents\n')
563
with file('a/file', 'wb') as f: f.write('contents\n')
563
565
wta.commit('a_revision', allow_pointless=False)
564
566
wtb = self.make_branch_and_tree('b')
566
file('b/file', 'wb').write('contents\n')
568
with file('b/file', 'wb') as f: f.write('contents\n')
568
570
b_rev = wtb.commit('b_revision', allow_pointless=False)
569
571
wta.merge_from_branch(wtb.branch, b_rev, 'null:')
570
self.assert_(os.path.lexists('a/file'))
571
self.assert_(os.path.lexists('a/file.moved'))
572
self.assertTrue(os.path.lexists('a/file'))
573
self.assertTrue(os.path.lexists('a/file.moved'))
572
574
self.assertEqual([b_rev], wta.get_parent_ids()[1:])
574
576
def test_merge_deleted_conflicts(self):
575
577
wta = self.make_branch_and_tree('a')
576
file('a/file', 'wb').write('contents\n')
578
with file('a/file', 'wb') as f: f.write('contents\n')
578
580
wta.commit('a_revision', allow_pointless=False)
579
581
self.run_bzr('branch a b')
580
582
os.remove('a/file')
581
583
wta.commit('removed file', allow_pointless=False)
582
file('b/file', 'wb').write('changed contents\n')
584
with file('b/file', 'wb') as f: f.write('changed contents\n')
583
585
wtb = WorkingTree.open('b')
584
586
wtb.commit('changed file', allow_pointless=False)
585
587
wtb.merge_from_branch(wta.branch, wta.branch.last_revision(),
601
603
self.assertFalse(os.path.exists('a/file'))
602
604
b_wt.commit('exec a')
603
605
a_wt.merge_from_branch(b_wt.branch, b_wt.last_revision(), 'null:')
604
self.assert_(os.path.exists('a/file'))
606
self.assertTrue(os.path.exists('a/file'))
606
608
def test_merge_swapping_renames(self):
607
609
a_wt = self.make_branch_and_tree('a')
608
file('a/un','wb').write('UN')
609
file('a/deux','wb').write('DEUX')
610
with file('a/un','wb') as f: f.write('UN')
611
with file('a/deux','wb') as f: f.write('DEUX')
610
612
a_wt.add('un', 'un-id')
611
613
a_wt.add('deux', 'deux-id')
612
614
a_wt.commit('r0', rev_id='r0')
627
629
def test_merge_delete_and_add_same(self):
628
630
a_wt = self.make_branch_and_tree('a')
629
file('a/file', 'wb').write('THIS')
631
with file('a/file', 'wb') as f: f.write('THIS')
631
633
a_wt.commit('r0')
632
634
self.run_bzr('branch a b')
633
635
b_wt = WorkingTree.open('b')
634
636
os.remove('b/file')
635
637
b_wt.commit('r1')
636
file('b/file', 'wb').write('THAT')
638
with file('b/file', 'wb') as f: f.write('THAT')
638
640
b_wt.commit('r2')
639
641
a_wt.merge_from_branch(b_wt.branch, b_wt.branch.last_revision(),
640
642
b_wt.branch.get_rev_id(1))
641
self.assert_(os.path.exists('a/file'))
643
self.assertTrue(os.path.exists('a/file'))
642
644
self.assertEqual(file('a/file').read(),'THAT')
644
646
def test_merge_rename_before_create(self):
658
660
a_wt = self.make_branch_and_tree('a')
659
file('a/foo', 'wb').write('A/FOO')
661
with file('a/foo', 'wb') as f: f.write('A/FOO')
661
663
a_wt.commit('added foo')
662
664
self.run_bzr('branch a b')
663
665
b_wt = WorkingTree.open('b')
664
666
b_wt.rename_one('foo', 'bar')
665
file('b/foo', 'wb').write('B/FOO')
667
with file('b/foo', 'wb') as f: f.write('B/FOO')
667
669
b_wt.commit('moved foo to bar, added new foo')
668
670
a_wt.merge_from_branch(b_wt.branch, b_wt.branch.last_revision(),
745
747
a_wt = self.make_branch_and_tree('a')
746
file('a/foo', 'wb').write('A/FOO')
747
file('a/bar', 'wb').write('A/BAR')
748
with file('a/foo', 'wb') as f: f.write('A/FOO')
749
with file('a/bar', 'wb') as f: f.write('A/BAR')
750
752
a_wt.commit('added foo and bar')