~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_merge.py

Move working tree initialisation out from  Branch.initialize, deprecated Branch.initialize to Branch.create.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
from bzrlib.branch import Branch
4
4
from bzrlib.commit import commit
5
 
from bzrlib.tests import TestCaseInTempDir
 
5
from bzrlib.tests import TestCaseWithTransport
6
6
from bzrlib.merge import merge, transform_tree
7
7
from bzrlib.errors import UnrelatedBranches, NoCommits, BzrCommandError
8
8
from bzrlib.revision import common_ancestor
9
9
from bzrlib.fetch import fetch
10
10
from bzrlib.osutils import pathjoin
11
 
 
12
 
 
13
 
class TestMerge(TestCaseInTempDir):
 
11
from bzrlib.workingtree import WorkingTree
 
12
 
 
13
 
 
14
class TestMerge(TestCaseWithTransport):
14
15
    """Test appending more than one revision"""
 
16
 
15
17
    def test_pending(self):
16
 
        br = Branch.initialize(u".")
17
 
        commit(br, "lala!")
18
 
        self.assertEquals(len(br.working_tree().pending_merges()), 0)
 
18
        wt = self.make_branch_and_tree('.')
 
19
        wt.commit("lala!")
 
20
        self.assertEquals(len(wt.pending_merges()), 0)
19
21
        merge([u'.', -1], [None, None])
20
 
        self.assertEquals(len(br.working_tree().pending_merges()), 0)
 
22
        self.assertEquals(len(wt.pending_merges()), 0)
21
23
 
22
24
    def test_nocommits(self):
23
25
        self.test_pending()
24
 
        os.mkdir('branch2')
25
 
        br2 = Branch.initialize('branch2')
 
26
        wt2 = self.make_branch_and_tree('branch2')
26
27
        self.assertRaises(NoCommits, merge, ['branch2', -1], 
27
28
                          [None, None])
28
 
        return br2
 
29
        return wt2
29
30
 
30
31
    def test_unrelated(self):
31
 
        br2 = self.test_nocommits()
32
 
        commit(br2, "blah")
 
32
        wt2 = self.test_nocommits()
 
33
        wt2.commit("blah")
33
34
        self.assertRaises(UnrelatedBranches, merge, ['branch2', -1], 
34
35
                          [None, None])
35
 
        return br2
 
36
        return wt2
36
37
 
37
38
    def test_pending_with_null(self):
38
39
        """When base is forced to revno 0, pending_merges is set"""
39
 
        br2 = self.test_unrelated()
40
 
        br1 = Branch.open(u'.')
41
 
        fetch(from_branch=br2, to_branch=br1)
 
40
        wt2 = self.test_unrelated()
 
41
        wt1 = WorkingTree('.')
 
42
        br1 = wt1.branch
 
43
        fetch(from_branch=wt2.branch, to_branch=br1)
42
44
        # merge all of branch 2 into branch 1 even though they 
43
45
        # are not related.
44
46
        self.assertRaises(BzrCommandError, merge, ['branch2', -1], 
45
47
                          ['branch2', 0], reprocess=True, show_base=True)
46
48
        merge(['branch2', -1], ['branch2', 0], reprocess=True)
47
 
        self.assertEquals(len(br1.working_tree().pending_merges()), 1)
48
 
        return (br1, br2)
 
49
        self.assertEquals(len(wt1.pending_merges()), 1)
 
50
        return (wt1, wt2.branch)
49
51
 
50
52
    def test_two_roots(self):
51
53
        """Merge base is sane when two unrelated branches are merged"""
52
 
        br1, br2 = self.test_pending_with_null()
53
 
        commit(br1, "blah")
54
 
        last = br1.last_revision()
55
 
        self.assertEquals(common_ancestor(last, last, br1), last)
 
54
        wt1, br2 = self.test_pending_with_null()
 
55
        wt1.commit("blah")
 
56
        last = wt1.branch.last_revision()
 
57
        self.assertEquals(common_ancestor(last, last, wt1.branch), last)
56
58
 
57
59
    def test_create_rename(self):
58
60
        """Rename an inventory entry while creating the file"""
59
 
        b = Branch.initialize(u'.')
 
61
        tree =self.make_branch_and_tree('.')
60
62
        file('name1', 'wb').write('Hello')
61
 
        tree = b.working_tree()
62
63
        tree.add('name1')
63
64
        tree.commit(message="hello")
64
65
        tree.rename_one('name1', 'name2')
65
66
        os.unlink('name2')
66
 
        transform_tree(tree, b.basis_tree())
 
67
        transform_tree(tree, tree.branch.basis_tree())
67
68
 
68
69
    def test_layered_rename(self):
69
70
        """Rename both child and parent at same time"""
70
 
        b = Branch.initialize(u'.')
71
 
        tree = b.working_tree()
 
71
        tree =self.make_branch_and_tree('.')
72
72
        os.mkdir('dirname1')
73
73
        tree.add('dirname1')
74
74
        filename = pathjoin('dirname1', 'name1')
78
78
        filename2 = pathjoin('dirname1', 'name2')
79
79
        tree.rename_one(filename, filename2)
80
80
        tree.rename_one('dirname1', 'dirname2')
81
 
        transform_tree(tree, b.basis_tree())
 
81
        transform_tree(tree, tree.branch.basis_tree())