~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-05-17 08:50:40 UTC
  • mfrom: (1704.2.18 bzr.mbp.integration)
  • Revision ID: pqm@pqm.ubuntu.com-20060517085040-ee6e33957c557fba
(mbp) merge 0.8 fixes; fix #32587

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_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(), [])
 
64
 
 
65
    def test_pending_with_null(self):
 
66
        """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)
 
71
        # merge all of branch 2 into branch 1 even though they 
 
72
        # 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)
 
78
 
 
79
    def test_two_roots(self):
 
80
        """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)