~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_merge_core.py

  • Committer: Patch Queue Manager
  • Date: 2015-12-17 18:39:00 UTC
  • mfrom: (6606.1.2 fix-float)
  • Revision ID: pqm@pqm.ubuntu.com-20151217183900-0719du2uv1kwu3lc
(vila) Inline testtools private method to fix an issue in xenial (the
 private implementation has changed in an backward incompatible way).
 (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
import bzrlib
21
21
from bzrlib import (
 
22
    controldir,
22
23
    errors,
23
24
    generate_ids,
24
25
    merge_directive,
42
43
 
43
44
 
44
45
class MergeBuilder(object):
 
46
 
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()
48
50
        def wt(name):
49
51
           path = pathjoin(self.dir, name)
50
52
           os.mkdir(path)
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.
53
55
           wt.lock_write()
54
56
           wt.set_root_id(self.tree_root)
98
100
            tt.apply()
99
101
            wt.commit('branch commit')
100
102
            wt.flush()
101
 
            if len(wt.branch.revision_history()) != 2:
 
103
            if wt.branch.last_revision_info()[0] != 2:
102
104
                raise AssertionError()
103
105
        self.this.branch.fetch(self.other.branch)
104
106
        other_basis = self.other.branch.basis_tree()
542
544
        """Sucessfully merges unrelated branches with no common names"""
543
545
        wta = self.make_branch_and_tree('a')
544
546
        a = wta.branch
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')
549
551
        b = wtb.branch
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:')
558
560
        """Sucessfully merges unrelated branches with common names"""
559
561
        wta = self.make_branch_and_tree('a')
560
562
        a = wta.branch
561
 
        file('a/file', 'wb').write('contents\n')
 
563
        with file('a/file', 'wb') as f: f.write('contents\n')
562
564
        wta.add('file')
563
565
        wta.commit('a_revision', allow_pointless=False)
564
566
        wtb = self.make_branch_and_tree('b')
565
567
        b = wtb.branch
566
 
        file('b/file', 'wb').write('contents\n')
 
568
        with file('b/file', 'wb') as f: f.write('contents\n')
567
569
        wtb.add('file')
568
570
        b_rev = wtb.commit('b_revision', allow_pointless=False)
569
571
        wta.merge_from_branch(wtb.branch, b_rev, 'null:')
573
575
 
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')
577
579
        wta.add('file')
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(),
589
591
    def test_merge_metadata_vs_deletion(self):
590
592
        """Conflict deletion vs metadata change"""
591
593
        a_wt = self.make_branch_and_tree('a')
592
 
        file('a/file', 'wb').write('contents\n')
 
594
        with file('a/file', 'wb') as f: f.write('contents\n')
593
595
        a_wt.add('file')
594
596
        a_wt.commit('r0')
595
597
        self.run_bzr('branch a b')
605
607
 
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')
626
628
 
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')
630
632
        a_wt.add('file')
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')
637
639
        b_wt.add('file')
638
640
        b_wt.commit('r2')
639
641
        a_wt.merge_from_branch(b_wt.branch, b_wt.branch.last_revision(),
656
658
        $ bzr commit
657
659
        """
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')
660
662
        a_wt.add('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')
666
668
        b_wt.add('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(),
685
687
        """
686
688
        os.mkdir('a')
687
689
        a_wt = self.make_branch_and_tree('a')
688
 
        file('a/foo', 'wb').write('A/FOO')
 
690
        with file('a/foo', 'wb') as f: f.write('A/FOO')
689
691
        a_wt.add('foo')
690
692
        a_wt.commit('added foo')
691
693
        self.run_bzr('branch a b')
714
716
        """
715
717
        a_wt = self.make_branch_and_tree('a')
716
718
        os.mkdir('a/foo')
717
 
        file('a/foo/bar', 'wb').write('A/FOO/BAR')
 
719
        with file('a/foo/bar', 'wb') as f: f.write('A/FOO/BAR')
718
720
        a_wt.add('foo')
719
721
        a_wt.add('foo/bar')
720
722
        a_wt.commit('added foo/bar')
743
745
        $ bzr commit
744
746
        """
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')
748
750
        a_wt.add('foo')
749
751
        a_wt.add('bar')
750
752
        a_wt.commit('added foo and bar')