~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_merge_core.py

  • Committer: Vincent Ladeuil
  • Date: 2010-09-28 08:57:31 UTC
  • mto: (5490.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 5492.
  • Revision ID: v.ladeuil+lp@free.fr-20100928085731-8h0duqj5wf4acsgy
Add -m to search for a regexp in news entries instead of the bug number.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2012, 2016 Canonical Ltd
 
1
# Copyright (C) 2005-2010 Canonical Ltd
2
2
#
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
19
19
 
20
20
import bzrlib
21
21
from bzrlib import (
22
 
    controldir,
23
22
    errors,
24
23
    generate_ids,
25
24
    merge_directive,
26
25
    osutils,
27
26
    )
28
 
from bzrlib.conflicts import (
29
 
    ContentsConflict,
30
 
    TextConflict,
31
 
    PathConflict,
32
 
    )
 
27
from bzrlib.conflicts import ContentsConflict, TextConflict, PathConflict
33
28
from bzrlib.merge import (
34
29
    Merge3Merger,
35
30
    Diff3Merger,
37
32
    Merger,
38
33
    )
39
34
from bzrlib.osutils import getcwd, pathjoin
 
35
from bzrlib import progress
40
36
from bzrlib.transform import TreeTransform
41
37
from bzrlib.tests import TestCaseWithTransport, TestSkipped
42
38
from bzrlib.workingtree import WorkingTree
43
39
 
44
40
 
45
41
class MergeBuilder(object):
46
 
 
47
42
    def __init__(self, dir=None):
48
43
        self.dir = osutils.mkdtemp(prefix="merge-test", dir=dir)
49
44
        self.tree_root = generate_ids.gen_root_id()
50
45
        def wt(name):
51
46
           path = pathjoin(self.dir, name)
52
47
           os.mkdir(path)
53
 
           wt = controldir.ControlDir.create_standalone_workingtree(path)
 
48
           wt = bzrlib.bzrdir.BzrDir.create_standalone_workingtree(path)
54
49
           # the tests perform pulls, so need a branch that is writeable.
55
50
           wt.lock_write()
56
51
           wt.set_root_id(self.tree_root)
100
95
            tt.apply()
101
96
            wt.commit('branch commit')
102
97
            wt.flush()
103
 
            if wt.branch.last_revision_info()[0] != 2:
 
98
            if len(wt.branch.revision_history()) != 2:
104
99
                raise AssertionError()
105
100
        self.this.branch.fetch(self.other.branch)
106
101
        other_basis = self.other.branch.basis_tree()
495
490
        wtb = d_b.open_workingtree()
496
491
        wtb.commit('this revision', allow_pointless=False)
497
492
        self.assertEqual(1, wtb.merge_from_branch(wta.branch))
498
 
        self.assertPathExists('b/file.THIS')
499
 
        self.assertPathExists('b/file.BASE')
500
 
        self.assertPathExists('b/file.OTHER')
 
493
        self.failUnlessExists('b/file.THIS')
 
494
        self.failUnlessExists('b/file.BASE')
 
495
        self.failUnlessExists('b/file.OTHER')
501
496
        wtb.revert()
502
497
        self.assertEqual(1, wtb.merge_from_branch(wta.branch,
503
498
                                                  merge_type=WeaveMerger))
504
 
        self.assertPathExists('b/file')
505
 
        self.assertPathExists('b/file.THIS')
506
 
        self.assertPathExists('b/file.BASE')
507
 
        self.assertPathExists('b/file.OTHER')
 
499
        self.failUnlessExists('b/file')
 
500
        self.failUnlessExists('b/file.THIS')
 
501
        self.failUnlessExists('b/file.BASE')
 
502
        self.failUnlessExists('b/file.OTHER')
508
503
 
509
504
    def test_weave_conflicts_not_in_base(self):
510
505
        builder = self.make_branch_builder('source')
534
529
        self.assertEqual(1, tree.merge_from_branch(tree.branch,
535
530
                                                   to_revision='D-id',
536
531
                                                   merge_type=WeaveMerger))
537
 
        self.assertPathExists('tree/foo.THIS')
538
 
        self.assertPathExists('tree/foo.OTHER')
 
532
        self.failUnlessExists('tree/foo.THIS')
 
533
        self.failUnlessExists('tree/foo.OTHER')
539
534
        self.expectFailure('fail to create .BASE in some criss-cross merges',
540
 
            self.assertPathExists, 'tree/foo.BASE')
541
 
        self.assertPathExists('tree/foo.BASE')
 
535
            self.failUnlessExists, 'tree/foo.BASE')
 
536
        self.failUnlessExists('tree/foo.BASE')
542
537
 
543
538
    def test_merge_unrelated(self):
544
539
        """Sucessfully merges unrelated branches with no common names"""
545
540
        wta = self.make_branch_and_tree('a')
546
541
        a = wta.branch
547
 
        with file('a/a_file', 'wb') as f: f.write('contents\n')
 
542
        file('a/a_file', 'wb').write('contents\n')
548
543
        wta.add('a_file')
549
544
        wta.commit('a_revision', allow_pointless=False)
550
545
        wtb = self.make_branch_and_tree('b')
551
546
        b = wtb.branch
552
 
        with file('b/b_file', 'wb') as f: f.write('contents\n')
 
547
        file('b/b_file', 'wb').write('contents\n')
553
548
        wtb.add('b_file')
554
549
        b_rev = wtb.commit('b_revision', allow_pointless=False)
555
550
        wta.merge_from_branch(wtb.branch, b_rev, 'null:')
556
 
        self.assertTrue(os.path.lexists('a/b_file'))
 
551
        self.assert_(os.path.lexists('a/b_file'))
557
552
        self.assertEqual([b_rev], wta.get_parent_ids()[1:])
558
553
 
559
554
    def test_merge_unrelated_conflicting(self):
560
555
        """Sucessfully merges unrelated branches with common names"""
561
556
        wta = self.make_branch_and_tree('a')
562
557
        a = wta.branch
563
 
        with file('a/file', 'wb') as f: f.write('contents\n')
 
558
        file('a/file', 'wb').write('contents\n')
564
559
        wta.add('file')
565
560
        wta.commit('a_revision', allow_pointless=False)
566
561
        wtb = self.make_branch_and_tree('b')
567
562
        b = wtb.branch
568
 
        with file('b/file', 'wb') as f: f.write('contents\n')
 
563
        file('b/file', 'wb').write('contents\n')
569
564
        wtb.add('file')
570
565
        b_rev = wtb.commit('b_revision', allow_pointless=False)
571
566
        wta.merge_from_branch(wtb.branch, b_rev, 'null:')
572
 
        self.assertTrue(os.path.lexists('a/file'))
573
 
        self.assertTrue(os.path.lexists('a/file.moved'))
 
567
        self.assert_(os.path.lexists('a/file'))
 
568
        self.assert_(os.path.lexists('a/file.moved'))
574
569
        self.assertEqual([b_rev], wta.get_parent_ids()[1:])
575
570
 
576
571
    def test_merge_deleted_conflicts(self):
577
572
        wta = self.make_branch_and_tree('a')
578
 
        with file('a/file', 'wb') as f: f.write('contents\n')
 
573
        file('a/file', 'wb').write('contents\n')
579
574
        wta.add('file')
580
575
        wta.commit('a_revision', allow_pointless=False)
581
576
        self.run_bzr('branch a b')
582
577
        os.remove('a/file')
583
578
        wta.commit('removed file', allow_pointless=False)
584
 
        with file('b/file', 'wb') as f: f.write('changed contents\n')
 
579
        file('b/file', 'wb').write('changed contents\n')
585
580
        wtb = WorkingTree.open('b')
586
581
        wtb.commit('changed file', allow_pointless=False)
587
582
        wtb.merge_from_branch(wta.branch, wta.branch.last_revision(),
588
583
                              wta.branch.get_rev_id(1))
589
 
        self.assertFalse(os.path.lexists('b/file'))
 
584
        self.failIf(os.path.lexists('b/file'))
590
585
 
591
586
    def test_merge_metadata_vs_deletion(self):
592
587
        """Conflict deletion vs metadata change"""
593
588
        a_wt = self.make_branch_and_tree('a')
594
 
        with file('a/file', 'wb') as f: f.write('contents\n')
 
589
        file('a/file', 'wb').write('contents\n')
595
590
        a_wt.add('file')
596
591
        a_wt.commit('r0')
597
592
        self.run_bzr('branch a b')
603
598
        self.assertFalse(os.path.exists('a/file'))
604
599
        b_wt.commit('exec a')
605
600
        a_wt.merge_from_branch(b_wt.branch, b_wt.last_revision(), 'null:')
606
 
        self.assertTrue(os.path.exists('a/file'))
 
601
        self.assert_(os.path.exists('a/file'))
607
602
 
608
603
    def test_merge_swapping_renames(self):
609
604
        a_wt = self.make_branch_and_tree('a')
610
 
        with file('a/un','wb') as f: f.write('UN')
611
 
        with file('a/deux','wb') as f: f.write('DEUX')
 
605
        file('a/un','wb').write('UN')
 
606
        file('a/deux','wb').write('DEUX')
612
607
        a_wt.add('un', 'un-id')
613
608
        a_wt.add('deux', 'deux-id')
614
609
        a_wt.commit('r0', rev_id='r0')
620
615
        b_wt.commit('r1', rev_id='r1')
621
616
        self.assertEqual(0, a_wt.merge_from_branch(b_wt.branch,
622
617
            b_wt.branch.last_revision(), b_wt.branch.get_rev_id(1)))
623
 
        self.assertPathExists('a/un')
624
 
        self.assertTrue('a/deux')
 
618
        self.failUnlessExists('a/un')
 
619
        self.failUnless('a/deux')
625
620
        self.assertFalse(os.path.exists('a/tmp'))
626
621
        self.assertEqual(file('a/un').read(),'DEUX')
627
622
        self.assertEqual(file('a/deux').read(),'UN')
628
623
 
629
624
    def test_merge_delete_and_add_same(self):
630
625
        a_wt = self.make_branch_and_tree('a')
631
 
        with file('a/file', 'wb') as f: f.write('THIS')
 
626
        file('a/file', 'wb').write('THIS')
632
627
        a_wt.add('file')
633
628
        a_wt.commit('r0')
634
629
        self.run_bzr('branch a b')
635
630
        b_wt = WorkingTree.open('b')
636
631
        os.remove('b/file')
637
632
        b_wt.commit('r1')
638
 
        with file('b/file', 'wb') as f: f.write('THAT')
 
633
        file('b/file', 'wb').write('THAT')
639
634
        b_wt.add('file')
640
635
        b_wt.commit('r2')
641
636
        a_wt.merge_from_branch(b_wt.branch, b_wt.branch.last_revision(),
642
637
                               b_wt.branch.get_rev_id(1))
643
 
        self.assertTrue(os.path.exists('a/file'))
 
638
        self.assert_(os.path.exists('a/file'))
644
639
        self.assertEqual(file('a/file').read(),'THAT')
645
640
 
646
641
    def test_merge_rename_before_create(self):
658
653
        $ bzr commit
659
654
        """
660
655
        a_wt = self.make_branch_and_tree('a')
661
 
        with file('a/foo', 'wb') as f: f.write('A/FOO')
 
656
        file('a/foo', 'wb').write('A/FOO')
662
657
        a_wt.add('foo')
663
658
        a_wt.commit('added foo')
664
659
        self.run_bzr('branch a b')
665
660
        b_wt = WorkingTree.open('b')
666
661
        b_wt.rename_one('foo', 'bar')
667
 
        with file('b/foo', 'wb') as f: f.write('B/FOO')
 
662
        file('b/foo', 'wb').write('B/FOO')
668
663
        b_wt.add('foo')
669
664
        b_wt.commit('moved foo to bar, added new foo')
670
665
        a_wt.merge_from_branch(b_wt.branch, b_wt.branch.last_revision(),
687
682
        """
688
683
        os.mkdir('a')
689
684
        a_wt = self.make_branch_and_tree('a')
690
 
        with file('a/foo', 'wb') as f: f.write('A/FOO')
 
685
        file('a/foo', 'wb').write('A/FOO')
691
686
        a_wt.add('foo')
692
687
        a_wt.commit('added foo')
693
688
        self.run_bzr('branch a b')
716
711
        """
717
712
        a_wt = self.make_branch_and_tree('a')
718
713
        os.mkdir('a/foo')
719
 
        with file('a/foo/bar', 'wb') as f: f.write('A/FOO/BAR')
 
714
        file('a/foo/bar', 'wb').write('A/FOO/BAR')
720
715
        a_wt.add('foo')
721
716
        a_wt.add('foo/bar')
722
717
        a_wt.commit('added foo/bar')
745
740
        $ bzr commit
746
741
        """
747
742
        a_wt = self.make_branch_and_tree('a')
748
 
        with file('a/foo', 'wb') as f: f.write('A/FOO')
749
 
        with file('a/bar', 'wb') as f: f.write('A/BAR')
 
743
        file('a/foo', 'wb').write('A/FOO')
 
744
        file('a/bar', 'wb').write('A/BAR')
750
745
        a_wt.add('foo')
751
746
        a_wt.add('bar')
752
747
        a_wt.commit('added foo and bar')