~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_merge.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-03-28 19:04:55 UTC
  • mfrom: (1626.1.1 bzr.mbp.integration)
  • Revision ID: pqm@pqm.ubuntu.com-20060328190455-9eab3a4045b61c4a
(mbp) disable break-lock until fixed properly

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os
 
2
from StringIO import StringIO
 
3
 
 
4
from bzrlib.branch import Branch
 
5
from bzrlib.builtins import merge
 
6
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
 
10
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):
 
17
    """Test appending more than one revision"""
 
18
 
 
19
    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])
 
32
 
 
33
    def test_nocommits(self):
 
34
        self.test_pending()
 
35
        wt2 = self.make_branch_and_tree('branch2')
 
36
        self.assertRaises(NoCommits, merge, ['branch2', -1], 
 
37
                          [None, None])
 
38
        return wt2
 
39
 
 
40
    def test_unrelated(self):
 
41
        wt2 = self.test_nocommits()
 
42
        wt2.commit("blah")
 
43
        self.assertRaises(UnrelatedBranches, merge, ['branch2', -1], 
 
44
                          [None, None])
 
45
        return wt2
 
46
 
 
47
    def test_pending_with_null(self):
 
48
        """When base is forced to revno 0, pending_merges is set"""
 
49
        wt2 = self.test_unrelated()
 
50
        wt1 = WorkingTree.open('.')
 
51
        br1 = wt1.branch
 
52
        br1.fetch(wt2.branch)
 
53
        # merge all of branch 2 into branch 1 even though they 
 
54
        # are not related.
 
55
        self.assertRaises(BzrCommandError, merge, ['branch2', -1], 
 
56
                          ['branch2', 0], reprocess=True, show_base=True)
 
57
        merge(['branch2', -1], ['branch2', 0], reprocess=True)
 
58
        self.assertEquals(len(wt1.pending_merges()), 1)
 
59
        return (wt1, wt2.branch)
 
60
 
 
61
    def test_two_roots(self):
 
62
        """Merge base is sane when two unrelated branches are merged"""
 
63
        wt1, br2 = self.test_pending_with_null()
 
64
        wt1.commit("blah")
 
65
        last = wt1.branch.last_revision()
 
66
        self.assertEquals(common_ancestor(last, last, wt1.branch.repository), last)
 
67
 
 
68
    def test_create_rename(self):
 
69
        """Rename an inventory entry while creating the file"""
 
70
        tree =self.make_branch_and_tree('.')
 
71
        file('name1', 'wb').write('Hello')
 
72
        tree.add('name1')
 
73
        tree.commit(message="hello")
 
74
        tree.rename_one('name1', 'name2')
 
75
        os.unlink('name2')
 
76
        transform_tree(tree, tree.branch.basis_tree())
 
77
 
 
78
    def test_layered_rename(self):
 
79
        """Rename both child and parent at same time"""
 
80
        tree =self.make_branch_and_tree('.')
 
81
        os.mkdir('dirname1')
 
82
        tree.add('dirname1')
 
83
        filename = pathjoin('dirname1', 'name1')
 
84
        file(filename, 'wb').write('Hello')
 
85
        tree.add(filename)
 
86
        tree.commit(message="hello")
 
87
        filename2 = pathjoin('dirname1', 'name2')
 
88
        tree.rename_one(filename, filename2)
 
89
        tree.rename_one('dirname1', 'dirname2')
 
90
        transform_tree(tree, tree.branch.basis_tree())
 
91
 
 
92
    def test_ignore_zero_merge_inner(self):
 
93
        # Test that merge_inner's ignore zero paramter is effective
 
94
        tree_a =self.make_branch_and_tree('a')
 
95
        tree_a.commit(message="hello")
 
96
        dir_b = tree_a.bzrdir.sprout('b')
 
97
        tree_b = dir_b.open_workingtree()
 
98
        tree_a.commit(message="hello again")
 
99
        log = StringIO()
 
100
        merge_inner(tree_b.branch, tree_a, tree_b.basis_tree(), 
 
101
                    this_tree=tree_b, ignore_zero=True)
 
102
        log = self._get_log()
 
103
        self.failUnless('All changes applied successfully.\n' not in log)
 
104
        tree_b.revert([])
 
105
        merge_inner(tree_b.branch, tree_a, tree_b.basis_tree(), 
 
106
                    this_tree=tree_b, ignore_zero=False)
 
107
        log = self._get_log()
 
108
        self.failUnless('All changes applied successfully.\n' in log)