/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: Jelmer Vernooij
  • Date: 2019-06-02 02:35:46 UTC
  • mfrom: (7309 work)
  • mto: This revision was merged to the branch mainline in revision 7319.
  • Revision ID: jelmer@jelmer.uk-20190602023546-lqco868tnv26d8ow
merge trunk.

Show diffs side-by-side

added added

removed removed

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