~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testmerge.py

  • Committer: Robert Collins
  • Date: 2005-10-18 05:26:22 UTC
  • mto: This revision was merged to the branch mainline in revision 1463.
  • Revision ID: robertc@robertcollins.net-20051018052622-653d638c9e26fde4
fix broken tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import os
2
 
from StringIO import StringIO
3
2
 
4
3
from bzrlib.branch import Branch
5
 
from bzrlib.builtins import merge
6
4
from bzrlib.commit import commit
7
 
from bzrlib.errors import UnrelatedBranches, NoCommits, BzrCommandError
8
 
from bzrlib.merge import transform_tree, merge_inner
9
 
from bzrlib.osutils import pathjoin
 
5
from bzrlib.selftest import TestCaseInTempDir
 
6
from bzrlib.merge import merge
 
7
from bzrlib.errors import UnrelatedBranches, NoCommits
10
8
from bzrlib.revision import common_ancestor
11
 
from bzrlib.tests import TestCaseWithTransport
12
 
from bzrlib.trace import (enable_test_log, disable_test_log)
13
 
from bzrlib.workingtree import WorkingTree
14
 
 
15
 
 
16
 
class TestMerge(TestCaseWithTransport):
 
9
from bzrlib.fetch import fetch
 
10
 
 
11
 
 
12
class TestMerge(TestCaseInTempDir):
17
13
    """Test appending more than one revision"""
18
 
 
19
14
    def test_pending(self):
20
 
        wt = self.make_branch_and_tree('.')
21
 
        wt.commit("lala!")
22
 
        self.assertEquals(len(wt.pending_merges()), 0)
23
 
        merge([u'.', -1], [None, None])
24
 
        self.assertEquals(len(wt.pending_merges()), 0)
25
 
 
26
 
    def test_undo(self):
27
 
        wt = self.make_branch_and_tree('.')
28
 
        wt.commit("lala!")
29
 
        wt.commit("haha!")
30
 
        wt.commit("blabla!")
31
 
        merge([u'.', 2], [u'.', 1])
 
15
        br = Branch.initialize(".")
 
16
        commit(br, "lala!")
 
17
        self.assertEquals(len(br.pending_merges()), 0)
 
18
        merge(['.', -1], [None, None])
 
19
        self.assertEquals(len(br.pending_merges()), 0)
32
20
 
33
21
    def test_nocommits(self):
34
22
        self.test_pending()
35
 
        wt2 = self.make_branch_and_tree('branch2')
 
23
        os.mkdir('branch2')
 
24
        br2 = Branch.initialize('branch2')
36
25
        self.assertRaises(NoCommits, merge, ['branch2', -1], 
37
26
                          [None, None])
38
 
        return wt2
 
27
        return br2
39
28
 
40
29
    def test_unrelated(self):
41
 
        wt2 = self.test_nocommits()
42
 
        wt2.commit("blah")
 
30
        br2 = self.test_nocommits()
 
31
        commit(br2, "blah")
43
32
        self.assertRaises(UnrelatedBranches, merge, ['branch2', -1], 
44
33
                          [None, None])
45
 
        return wt2
46
 
 
47
 
    def test_merge_one(self):
48
 
        wt1 = self.make_branch_and_tree('branch1')
49
 
        wt1.commit('empty commit')
50
 
        wt2 = self.make_branch_and_tree('branch2')
51
 
        wt2.pull(wt1.branch)
52
 
        file('branch1/foo', 'wb').write('foo')
53
 
        file('branch1/bar', 'wb').write('bar')
54
 
        wt1.add('foo')
55
 
        wt1.add('bar')
56
 
        wt1.commit('add foobar')
57
 
        os.chdir('branch2')
58
 
        self.run_bzr('merge', '../branch1/baz', retcode=3)
59
 
        self.run_bzr('merge', '../branch1/foo')
60
 
        self.failUnlessExists('foo')
61
 
        self.failIfExists('bar')
62
 
        wt2 = WorkingTree.open_containing('branch2')[0]
63
 
        self.assertEqual(wt2.pending_merges(), [])
 
34
        return br2
64
35
 
65
36
    def test_pending_with_null(self):
66
37
        """When base is forced to revno 0, pending_merges is set"""
67
 
        wt2 = self.test_unrelated()
68
 
        wt1 = WorkingTree.open('.')
69
 
        br1 = wt1.branch
70
 
        br1.fetch(wt2.branch)
 
38
        br2 = self.test_unrelated()
 
39
        br1 = Branch.open('.')
 
40
        fetch(from_branch=br2, to_branch=br1)
71
41
        # merge all of branch 2 into branch 1 even though they 
72
42
        # are not related.
73
 
        self.assertRaises(BzrCommandError, merge, ['branch2', -1], 
74
 
                          ['branch2', 0], reprocess=True, show_base=True)
75
 
        merge(['branch2', -1], ['branch2', 0], reprocess=True)
76
 
        self.assertEquals(len(wt1.pending_merges()), 1)
77
 
        return (wt1, wt2.branch)
 
43
        merge(['branch2', -1], ['branch2', 0])
 
44
        self.assertEquals(len(br1.pending_merges()), 1)
 
45
        return (br1, br2)
78
46
 
79
47
    def test_two_roots(self):
80
48
        """Merge base is sane when two unrelated branches are merged"""
81
 
        wt1, br2 = self.test_pending_with_null()
82
 
        wt1.commit("blah")
83
 
        last = wt1.branch.last_revision()
84
 
        self.assertEquals(common_ancestor(last, last, wt1.branch.repository), last)
85
 
 
86
 
    def test_create_rename(self):
87
 
        """Rename an inventory entry while creating the file"""
88
 
        tree =self.make_branch_and_tree('.')
89
 
        file('name1', 'wb').write('Hello')
90
 
        tree.add('name1')
91
 
        tree.commit(message="hello")
92
 
        tree.rename_one('name1', 'name2')
93
 
        os.unlink('name2')
94
 
        transform_tree(tree, tree.branch.basis_tree())
95
 
 
96
 
    def test_layered_rename(self):
97
 
        """Rename both child and parent at same time"""
98
 
        tree =self.make_branch_and_tree('.')
99
 
        os.mkdir('dirname1')
100
 
        tree.add('dirname1')
101
 
        filename = pathjoin('dirname1', 'name1')
102
 
        file(filename, 'wb').write('Hello')
103
 
        tree.add(filename)
104
 
        tree.commit(message="hello")
105
 
        filename2 = pathjoin('dirname1', 'name2')
106
 
        tree.rename_one(filename, filename2)
107
 
        tree.rename_one('dirname1', 'dirname2')
108
 
        transform_tree(tree, tree.branch.basis_tree())
109
 
 
110
 
    def test_ignore_zero_merge_inner(self):
111
 
        # Test that merge_inner's ignore zero paramter is effective
112
 
        tree_a =self.make_branch_and_tree('a')
113
 
        tree_a.commit(message="hello")
114
 
        dir_b = tree_a.bzrdir.sprout('b')
115
 
        tree_b = dir_b.open_workingtree()
116
 
        tree_a.commit(message="hello again")
117
 
        log = StringIO()
118
 
        merge_inner(tree_b.branch, tree_a, tree_b.basis_tree(), 
119
 
                    this_tree=tree_b, ignore_zero=True)
120
 
        log = self._get_log()
121
 
        self.failUnless('All changes applied successfully.\n' not in log)
122
 
        tree_b.revert([])
123
 
        merge_inner(tree_b.branch, tree_a, tree_b.basis_tree(), 
124
 
                    this_tree=tree_b, ignore_zero=False)
125
 
        log = self._get_log()
126
 
        self.failUnless('All changes applied successfully.\n' in log)
 
49
        br1, br2 = self.test_pending_with_null()
 
50
        commit(br1, "blah")
 
51
        last = br1.last_revision()
 
52
        self.assertEquals(common_ancestor(last, last, br1), last)