/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_merge_core.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-11-16 18:59:44 UTC
  • mfrom: (7143.15.15 more-cleanups)
  • Revision ID: breezy.the.bot@gmail.com-20181116185944-biefv1sub37qfybm
Sprinkle some PEP8iness.

Merged from https://code.launchpad.net/~jelmer/brz/more-cleanups/+merge/358611

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
    def __init__(self, dir=None):
48
48
        self.dir = osutils.mkdtemp(prefix="merge-test", dir=dir)
49
49
        self.tree_root = generate_ids.gen_root_id()
 
50
 
50
51
        def wt(name):
51
 
           path = pathjoin(self.dir, name)
52
 
           os.mkdir(path)
53
 
           wt = controldir.ControlDir.create_standalone_workingtree(path)
54
 
           # the tests perform pulls, so need a branch that is writeable.
55
 
           wt.lock_write()
56
 
           wt.set_root_id(self.tree_root)
57
 
           wt.flush()
58
 
           tt = TreeTransform(wt)
59
 
           return wt, tt
 
52
            path = pathjoin(self.dir, name)
 
53
            os.mkdir(path)
 
54
            wt = controldir.ControlDir.create_standalone_workingtree(path)
 
55
            # the tests perform pulls, so need a branch that is writeable.
 
56
            wt.lock_write()
 
57
            wt.set_root_id(self.tree_root)
 
58
            wt.flush()
 
59
            tt = TreeTransform(wt)
 
60
            return wt, tt
60
61
        self.base, self.base_tt = wt('base')
61
62
        self.this, self.this_tt = wt('this')
62
63
        self.other, self.other_tt = wt('other')
87
88
        return merger.make_preview_transform()
88
89
 
89
90
    def make_merger(self, merge_type, interesting_files,
90
 
            this_revision_tree=False, **kwargs):
 
91
                    this_revision_tree=False, **kwargs):
91
92
        self.base_tt.apply()
92
93
        self.base.commit('base commit')
93
94
        for tt, wt in ((self.this_tt, self.this), (self.other_tt, self.other)):
152
153
 
153
154
    def change_parent(self, file_id, base=None, this=None, other=None):
154
155
        for parent, tt in self.selected_transforms(this, base, other):
155
 
            trans_id  = tt.trans_id_file_id(file_id)
 
156
            trans_id = tt.trans_id_file_id(file_id)
156
157
            parent_id = tt.trans_id_file_id(parent)
157
158
            tt.adjust_path(tt.final_name(trans_id), parent_id, trans_id)
158
159
 
252
253
        builder.add_file(b"2", builder.tree_root, "name2", b"hello1", True)
253
254
        builder.change_contents(b"2", other=b"text4")
254
255
        builder.merge(interesting_files=["name1"])
255
 
        self.assertEqual(builder.this.get_file("name1").read(), b"text4" )
256
 
        self.assertEqual(builder.this.get_file("name2").read(), b"hello1" )
 
256
        self.assertEqual(builder.this.get_file("name1").read(), b"text4")
 
257
        self.assertEqual(builder.this.get_file("name2").read(), b"hello1")
257
258
        builder.cleanup()
258
259
 
259
260
    def test_file_moves(self):
304
305
        # Reprocess works on weaves, and behaves as expected
305
306
        builder = MergeBuilder(getcwd())
306
307
        builder.add_file(b'a', builder.tree_root, 'blah', b'a', False)
307
 
        builder.change_contents(b'a', this=b'b\nc\nd\ne\n', other=b'z\nc\nd\ny\n')
 
308
        builder.change_contents(
 
309
            b'a', this=b'b\nc\nd\ne\n', other=b'z\nc\nd\ny\n')
308
310
        builder.merge(WeaveMerger, reprocess=True)
309
311
        expected = b"""<<<<<<< TREE
310
312
b
320
322
>>>>>>> MERGE-SOURCE
321
323
"""
322
324
        self.assertEqualDiff(
323
 
                builder.this.get_file(builder.this.id2path(b"a")).read(),
324
 
                expected)
 
325
            builder.this.get_file(builder.this.id2path(b"a")).read(),
 
326
            expected)
325
327
        builder.cleanup()
326
328
 
327
329
    def do_contents_test(self, merge_factory):
342
344
        builder.add_file(b"5", builder.tree_root, "name7", b"a\nb\nc\nd\ne\nf\n",
343
345
                         True)
344
346
        builder.change_contents(b"5", other=b"a\nz\nc\nd\ne\nf\n",
345
 
                                     this=b"a\nb\nc\nd\ne\nz\n")
 
347
                                this=b"a\nb\nc\nd\ne\nz\n")
346
348
        conflicts = builder.merge(merge_factory)
347
349
        try:
348
350
            self.assertEqual([], conflicts)
396
398
            builder.change_target(b"2", base=b"target2")
397
399
            builder.change_target(b"3", other=b"target2")
398
400
            builder.merge()
399
 
            self.assertEqual(builder.this.get_symlink_target("name1"), "target2")
400
 
            self.assertEqual(builder.this.get_symlink_target("name2"), "target1")
401
 
            self.assertEqual(builder.this.get_symlink_target("name3"), "target2")
 
401
            self.assertEqual(
 
402
                builder.this.get_symlink_target("name1"), "target2")
 
403
            self.assertEqual(
 
404
                builder.this.get_symlink_target("name2"), "target1")
 
405
            self.assertEqual(
 
406
                builder.this.get_symlink_target("name3"), "target2")
402
407
            builder.cleanup()
403
408
 
404
409
    def test_no_passive_add(self):
423
428
        self.assertIs(builder.this.is_executable("name1"), False)
424
429
        self.assertIs(builder.this.is_executable("name2"), True)
425
430
        self.assertIs(builder.this.is_executable("name3"), False)
426
 
        builder.cleanup();
 
431
        builder.cleanup()
427
432
 
428
433
    def test_new_suffix(self):
429
434
        builder = MergeBuilder(getcwd())
544
549
        self.assertPathExists('tree/foo.THIS')
545
550
        self.assertPathExists('tree/foo.OTHER')
546
551
        self.expectFailure('fail to create .BASE in some criss-cross merges',
547
 
            self.assertPathExists, 'tree/foo.BASE')
 
552
                           self.assertPathExists, 'tree/foo.BASE')
548
553
        self.assertPathExists('tree/foo.BASE')
549
554
 
550
555
    def test_merge_unrelated(self):
551
556
        """Sucessfully merges unrelated branches with no common names"""
552
557
        wta = self.make_branch_and_tree('a')
553
558
        a = wta.branch
554
 
        with open('a/a_file', 'wb') as f: f.write(b'contents\n')
 
559
        with open('a/a_file', 'wb') as f:
 
560
            f.write(b'contents\n')
555
561
        wta.add('a_file')
556
562
        wta.commit('a_revision', allow_pointless=False)
557
563
        wtb = self.make_branch_and_tree('b')
558
564
        b = wtb.branch
559
 
        with open('b/b_file', 'wb') as f: f.write(b'contents\n')
 
565
        with open('b/b_file', 'wb') as f:
 
566
            f.write(b'contents\n')
560
567
        wtb.add('b_file')
561
568
        b_rev = wtb.commit('b_revision', allow_pointless=False)
562
569
        wta.merge_from_branch(wtb.branch, b_rev, b'null:')
567
574
        """Sucessfully merges unrelated branches with common names"""
568
575
        wta = self.make_branch_and_tree('a')
569
576
        a = wta.branch
570
 
        with open('a/file', 'wb') as f: f.write(b'contents\n')
 
577
        with open('a/file', 'wb') as f:
 
578
            f.write(b'contents\n')
571
579
        wta.add('file')
572
580
        wta.commit('a_revision', allow_pointless=False)
573
581
        wtb = self.make_branch_and_tree('b')
574
582
        b = wtb.branch
575
 
        with open('b/file', 'wb') as f: f.write(b'contents\n')
 
583
        with open('b/file', 'wb') as f:
 
584
            f.write(b'contents\n')
576
585
        wtb.add('file')
577
586
        b_rev = wtb.commit('b_revision', allow_pointless=False)
578
587
        wta.merge_from_branch(wtb.branch, b_rev, b'null:')
582
591
 
583
592
    def test_merge_deleted_conflicts(self):
584
593
        wta = self.make_branch_and_tree('a')
585
 
        with open('a/file', 'wb') as f: f.write(b'contents\n')
 
594
        with open('a/file', 'wb') as f:
 
595
            f.write(b'contents\n')
586
596
        wta.add('file')
587
597
        wta.commit('a_revision', allow_pointless=False)
588
598
        self.run_bzr('branch a b')
589
599
        os.remove('a/file')
590
600
        wta.commit('removed file', allow_pointless=False)
591
 
        with open('b/file', 'wb') as f: f.write(b'changed contents\n')
 
601
        with open('b/file', 'wb') as f:
 
602
            f.write(b'changed contents\n')
592
603
        wtb = WorkingTree.open('b')
593
604
        wtb.commit('changed file', allow_pointless=False)
594
605
        wtb.merge_from_branch(wta.branch, wta.branch.last_revision(),
598
609
    def test_merge_metadata_vs_deletion(self):
599
610
        """Conflict deletion vs metadata change"""
600
611
        a_wt = self.make_branch_and_tree('a')
601
 
        with open('a/file', 'wb') as f: f.write(b'contents\n')
 
612
        with open('a/file', 'wb') as f:
 
613
            f.write(b'contents\n')
602
614
        a_wt.add('file')
603
615
        a_wt.commit('r0')
604
616
        self.run_bzr('branch a b')
614
626
 
615
627
    def test_merge_swapping_renames(self):
616
628
        a_wt = self.make_branch_and_tree('a')
617
 
        with open('a/un', 'wb') as f: f.write(b'UN')
618
 
        with open('a/deux', 'wb') as f: f.write(b'DEUX')
 
629
        with open('a/un', 'wb') as f:
 
630
            f.write(b'UN')
 
631
        with open('a/deux', 'wb') as f:
 
632
            f.write(b'DEUX')
619
633
        a_wt.add('un', b'un-id')
620
634
        a_wt.add('deux', b'deux-id')
621
635
        a_wt.commit('r0', rev_id=b'r0')
626
640
        b_wt.rename_one('tmp', 'deux')
627
641
        b_wt.commit('r1', rev_id=b'r1')
628
642
        self.assertEqual(0, a_wt.merge_from_branch(b_wt.branch,
629
 
            b_wt.branch.last_revision(), b_wt.branch.get_rev_id(1)))
 
643
                                                   b_wt.branch.last_revision(), b_wt.branch.get_rev_id(1)))
630
644
        self.assertPathExists('a/un')
631
645
        self.assertTrue('a/deux')
632
646
        self.assertFalse(os.path.exists('a/tmp'))
637
651
 
638
652
    def test_merge_delete_and_add_same(self):
639
653
        a_wt = self.make_branch_and_tree('a')
640
 
        with open('a/file', 'wb') as f: f.write(b'THIS')
 
654
        with open('a/file', 'wb') as f:
 
655
            f.write(b'THIS')
641
656
        a_wt.add('file')
642
657
        a_wt.commit('r0')
643
658
        self.run_bzr('branch a b')
644
659
        b_wt = WorkingTree.open('b')
645
660
        os.remove('b/file')
646
661
        b_wt.commit('r1')
647
 
        with open('b/file', 'wb') as f: f.write(b'THAT')
 
662
        with open('b/file', 'wb') as f:
 
663
            f.write(b'THAT')
648
664
        b_wt.add('file')
649
665
        b_wt.commit('r2')
650
666
        a_wt.merge_from_branch(b_wt.branch, b_wt.branch.last_revision(),
668
684
        $ bzr commit
669
685
        """
670
686
        a_wt = self.make_branch_and_tree('a')
671
 
        with open('a/foo', 'wb') as f: f.write(b'A/FOO')
 
687
        with open('a/foo', 'wb') as f:
 
688
            f.write(b'A/FOO')
672
689
        a_wt.add('foo')
673
690
        a_wt.commit('added foo')
674
691
        self.run_bzr('branch a b')
698
715
        """
699
716
        os.mkdir('a')
700
717
        a_wt = self.make_branch_and_tree('a')
701
 
        with open('a/foo', 'wb') as f: f.write(b'A/FOO')
 
718
        with open('a/foo', 'wb') as f:
 
719
            f.write(b'A/FOO')
702
720
        a_wt.add('foo')
703
721
        a_wt.commit('added foo')
704
722
        self.run_bzr('branch a b')
727
745
        """
728
746
        a_wt = self.make_branch_and_tree('a')
729
747
        os.mkdir('a/foo')
730
 
        with open('a/foo/bar', 'wb') as f: f.write(b'A/FOO/BAR')
 
748
        with open('a/foo/bar', 'wb') as f:
 
749
            f.write(b'A/FOO/BAR')
731
750
        a_wt.add('foo')
732
751
        a_wt.add('foo/bar')
733
752
        a_wt.commit('added foo/bar')
756
775
        $ bzr commit
757
776
        """
758
777
        a_wt = self.make_branch_and_tree('a')
759
 
        with open('a/foo', 'wb') as f: f.write(b'A/FOO')
760
 
        with open('a/bar', 'wb') as f: f.write(b'A/BAR')
 
778
        with open('a/foo', 'wb') as f:
 
779
            f.write(b'A/FOO')
 
780
        with open('a/bar', 'wb') as f:
 
781
            f.write(b'A/BAR')
761
782
        a_wt.add('foo')
762
783
        a_wt.add('bar')
763
784
        a_wt.commit('added foo and bar')
788
809
        this.lock_write()
789
810
        self.addCleanup(this.unlock)
790
811
        merger = Merger.from_revision_ids(this,
791
 
            b'rev2b', other_branch=other.branch)
 
812
                                          b'rev2b', other_branch=other.branch)
792
813
        self.assertEqual(b'rev2b', merger.other_rev_id)
793
814
        self.assertEqual(b'rev1', merger.base_rev_id)
794
815
        merger = Merger.from_revision_ids(this,
795
 
            b'rev2b', b'rev2a', other_branch=other.branch)
 
816
                                          b'rev2b', b'rev2a', other_branch=other.branch)
796
817
        self.assertEqual(b'rev2a', merger.base_rev_id)
797
818
 
798
819
    def test_from_uncommitted(self):