/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1908.5.2 by Robert Collins
Create and test set_parent_trees.
1
# Copyright (C) 2006 by Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
1908.5.3 by Robert Collins
Rename the tree.set_parents tests to tree.parents - preparing to add related function tests. Also remove duplication within the tests by factoring out a helper assert.
17
"""Tests of the parent related functions of WorkingTrees."""
18
1908.5.2 by Robert Collins
Create and test set_parent_trees.
19
import os
20
1908.5.9 by Robert Collins
Add a guard against setting the tree last-revision value to a ghost in the new tree parent management api.
21
from bzrlib import errors
1908.5.2 by Robert Collins
Create and test set_parent_trees.
22
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
23
from bzrlib.uncommit import uncommit
24
25
1908.5.3 by Robert Collins
Rename the tree.set_parents tests to tree.parents - preparing to add related function tests. Also remove duplication within the tests by factoring out a helper assert.
26
class TestParents(TestCaseWithWorkingTree):
27
28
    def assertConsistentParents(self, expected, tree):
29
        self.assertEqual(expected, tree.get_parent_ids())
30
        if expected == []:
31
            self.assertEqual(None, tree.last_revision())
32
        else:
33
            self.assertEqual(expected[0], tree.last_revision())
34
        self.assertEqual(expected[1:], tree.pending_merges())
35
36
37
class TestSetParents(TestParents):
1908.5.2 by Robert Collins
Create and test set_parent_trees.
38
39
    def test_set_no_parents(self):
40
        t = self.make_branch_and_tree('.')
41
        t.set_parent_trees([])
42
        self.assertEqual([], t.get_parent_ids())
43
        # now give it a real parent, and then set it to no parents again.
44
        t.commit('first post')
45
        t.set_parent_trees([])
1908.5.3 by Robert Collins
Rename the tree.set_parents tests to tree.parents - preparing to add related function tests. Also remove duplication within the tests by factoring out a helper assert.
46
        self.assertConsistentParents([], t)
1908.5.2 by Robert Collins
Create and test set_parent_trees.
47
1908.5.9 by Robert Collins
Add a guard against setting the tree last-revision value to a ghost in the new tree parent management api.
48
    def test_set_one_ghost_parent_rejects(self):
49
        t = self.make_branch_and_tree('.')
1908.5.12 by Robert Collins
Apply review feedback - paired with Martin.
50
        self.assertRaises(errors.GhostRevisionUnusableHere,
1908.5.9 by Robert Collins
Add a guard against setting the tree last-revision value to a ghost in the new tree parent management api.
51
            t.set_parent_trees, [('missing-revision-id', None)])
52
53
    def test_set_one_ghost_parent_force(self):
54
        t = self.make_branch_and_tree('.')
55
        t.set_parent_trees([('missing-revision-id', None)],
56
            allow_leftmost_as_ghost=True)
1908.5.3 by Robert Collins
Rename the tree.set_parents tests to tree.parents - preparing to add related function tests. Also remove duplication within the tests by factoring out a helper assert.
57
        self.assertConsistentParents(['missing-revision-id'], t)
1908.5.2 by Robert Collins
Create and test set_parent_trees.
58
59
    def test_set_two_parents_one_ghost(self):
60
        t = self.make_branch_and_tree('.')
61
        revision_in_repo = t.commit('first post')
62
        # remove the tree's history
63
        uncommit(t.branch, tree=t)
64
        rev_tree = t.branch.repository.revision_tree(revision_in_repo)
65
        t.set_parent_trees([(revision_in_repo, rev_tree),
66
            ('another-missing', None)])
1908.5.3 by Robert Collins
Rename the tree.set_parents tests to tree.parents - preparing to add related function tests. Also remove duplication within the tests by factoring out a helper assert.
67
        self.assertConsistentParents([revision_in_repo, 'another-missing'], t)
1908.5.2 by Robert Collins
Create and test set_parent_trees.
68
69
    def test_set_three_parents(self):
70
        t = self.make_branch_and_tree('.')
71
        first_revision = t.commit('first post')
72
        uncommit(t.branch, tree=t)
73
        second_revision = t.commit('second post')
74
        uncommit(t.branch, tree=t)
75
        third_revision = t.commit('third post')
76
        uncommit(t.branch, tree=t)
77
        rev_tree1 = t.branch.repository.revision_tree(first_revision)
78
        rev_tree2 = t.branch.repository.revision_tree(second_revision)
79
        rev_tree3 = t.branch.repository.revision_tree(third_revision)
80
        t.set_parent_trees([(first_revision, rev_tree1),
81
            (second_revision, rev_tree2),
82
            (third_revision, rev_tree3)])
1908.5.3 by Robert Collins
Rename the tree.set_parents tests to tree.parents - preparing to add related function tests. Also remove duplication within the tests by factoring out a helper assert.
83
        self.assertConsistentParents(
84
            [first_revision, second_revision, third_revision], t)
1908.5.4 by Robert Collins
Add add_parent_tree_id WorkingTree helper api.
85
1908.5.5 by Robert Collins
Add WorkingTree.set_parent_ids.
86
    def test_set_no_parents_ids(self):
87
        t = self.make_branch_and_tree('.')
88
        t.set_parent_ids([])
89
        self.assertEqual([], t.get_parent_ids())
90
        # now give it a real parent, and then set it to no parents again.
91
        t.commit('first post')
92
        t.set_parent_ids([])
93
        self.assertConsistentParents([], t)
94
1908.5.9 by Robert Collins
Add a guard against setting the tree last-revision value to a ghost in the new tree parent management api.
95
    def test_set_one_ghost_parent_ids_rejects(self):
96
        t = self.make_branch_and_tree('.')
1908.5.12 by Robert Collins
Apply review feedback - paired with Martin.
97
        self.assertRaises(errors.GhostRevisionUnusableHere,
1908.5.9 by Robert Collins
Add a guard against setting the tree last-revision value to a ghost in the new tree parent management api.
98
            t.set_parent_ids, ['missing-revision-id'])
99
100
    def test_set_one_ghost_parent_ids_force(self):
101
        t = self.make_branch_and_tree('.')
102
        t.set_parent_ids(['missing-revision-id'],
103
            allow_leftmost_as_ghost=True)
1908.5.5 by Robert Collins
Add WorkingTree.set_parent_ids.
104
        self.assertConsistentParents(['missing-revision-id'], t)
105
106
    def test_set_two_parents_one_ghost_ids(self):
107
        t = self.make_branch_and_tree('.')
108
        revision_in_repo = t.commit('first post')
109
        # remove the tree's history
110
        uncommit(t.branch, tree=t)
111
        rev_tree = t.branch.repository.revision_tree(revision_in_repo)
112
        t.set_parent_ids([revision_in_repo, 'another-missing'])
113
        self.assertConsistentParents([revision_in_repo, 'another-missing'], t)
114
115
    def test_set_three_parents_ids(self):
116
        t = self.make_branch_and_tree('.')
117
        first_revision = t.commit('first post')
118
        uncommit(t.branch, tree=t)
119
        second_revision = t.commit('second post')
120
        uncommit(t.branch, tree=t)
121
        third_revision = t.commit('third post')
122
        uncommit(t.branch, tree=t)
123
        rev_tree1 = t.branch.repository.revision_tree(first_revision)
124
        rev_tree2 = t.branch.repository.revision_tree(second_revision)
125
        rev_tree3 = t.branch.repository.revision_tree(third_revision)
126
        t.set_parent_ids([first_revision, second_revision, third_revision])
127
        self.assertConsistentParents(
128
            [first_revision, second_revision, third_revision], t)
129
1908.5.4 by Robert Collins
Add add_parent_tree_id WorkingTree helper api.
130
1908.5.6 by Robert Collins
Add add_parent_tree to WorkingTree.
131
class TestAddParent(TestParents):
1908.5.4 by Robert Collins
Add add_parent_tree_id WorkingTree helper api.
132
133
    def test_add_first_parent_id(self):
134
        """Test adding the first parent id"""
135
        tree = self.make_branch_and_tree('.')
136
        first_revision = tree.commit('first post')
137
        uncommit(tree.branch, tree=tree)
138
        tree.add_parent_tree_id(first_revision)
139
        self.assertConsistentParents([first_revision], tree)
140
        
1908.5.9 by Robert Collins
Add a guard against setting the tree last-revision value to a ghost in the new tree parent management api.
141
    def test_add_first_parent_id_ghost_rejects(self):
142
        """Test adding the first parent id - as a ghost"""
143
        tree = self.make_branch_and_tree('.')
1908.5.12 by Robert Collins
Apply review feedback - paired with Martin.
144
        self.assertRaises(errors.GhostRevisionUnusableHere,
1908.5.9 by Robert Collins
Add a guard against setting the tree last-revision value to a ghost in the new tree parent management api.
145
            tree.add_parent_tree_id, 'first-revision')
146
        
147
    def test_add_first_parent_id_ghost_force(self):
148
        """Test adding the first parent id - as a ghost"""
149
        tree = self.make_branch_and_tree('.')
150
        tree.add_parent_tree_id('first-revision', allow_leftmost_as_ghost=True)
1908.5.4 by Robert Collins
Add add_parent_tree_id WorkingTree helper api.
151
        self.assertConsistentParents(['first-revision'], tree)
1908.5.13 by Robert Collins
Adding a parent when the first is a ghost already should not require forcing it.
152
153
    def test_add_second_parent_id_with_ghost_first(self):
154
        """Test adding the second parent when the first is a ghost."""
155
        tree = self.make_branch_and_tree('.')
156
        tree.add_parent_tree_id('first-revision', allow_leftmost_as_ghost=True)
157
        tree.add_parent_tree_id('second')
158
        self.assertConsistentParents(['first-revision', 'second'], tree)
1908.5.4 by Robert Collins
Add add_parent_tree_id WorkingTree helper api.
159
        
160
    def test_add_second_parent_id(self):
161
        """Test adding the second parent id"""
162
        tree = self.make_branch_and_tree('.')
163
        first_revision = tree.commit('first post')
164
        uncommit(tree.branch, tree=tree)
165
        second_revision = tree.commit('second post')
166
        tree.add_parent_tree_id(first_revision)
167
        self.assertConsistentParents([second_revision, first_revision], tree)
168
        
169
    def test_add_second_parent_id_ghost(self):
170
        """Test adding the second parent id - as a ghost"""
171
        tree = self.make_branch_and_tree('.')
172
        first_revision = tree.commit('first post')
173
        tree.add_parent_tree_id('second')
174
        self.assertConsistentParents([first_revision, 'second'], tree)
1908.5.6 by Robert Collins
Add add_parent_tree to WorkingTree.
175
        
176
    def test_add_first_parent_tree(self):
177
        """Test adding the first parent id"""
178
        tree = self.make_branch_and_tree('.')
179
        first_revision = tree.commit('first post')
180
        uncommit(tree.branch, tree=tree)
181
        tree.add_parent_tree((first_revision,
182
            tree.branch.repository.revision_tree(first_revision)))
183
        self.assertConsistentParents([first_revision], tree)
184
        
1908.5.9 by Robert Collins
Add a guard against setting the tree last-revision value to a ghost in the new tree parent management api.
185
    def test_add_first_parent_tree_ghost_rejects(self):
186
        """Test adding the first parent id - as a ghost"""
187
        tree = self.make_branch_and_tree('.')
1908.5.12 by Robert Collins
Apply review feedback - paired with Martin.
188
        self.assertRaises(errors.GhostRevisionUnusableHere,
1908.5.9 by Robert Collins
Add a guard against setting the tree last-revision value to a ghost in the new tree parent management api.
189
            tree.add_parent_tree, ('first-revision', None))
190
        
191
    def test_add_first_parent_tree_ghost_force(self):
192
        """Test adding the first parent id - as a ghost"""
193
        tree = self.make_branch_and_tree('.')
194
        tree.add_parent_tree(('first-revision', None),
195
            allow_leftmost_as_ghost=True)
1908.5.6 by Robert Collins
Add add_parent_tree to WorkingTree.
196
        self.assertConsistentParents(['first-revision'], tree)
197
        
198
    def test_add_second_parent_tree(self):
199
        """Test adding the second parent id"""
200
        tree = self.make_branch_and_tree('.')
201
        first_revision = tree.commit('first post')
202
        uncommit(tree.branch, tree=tree)
203
        second_revision = tree.commit('second post')
204
        tree.add_parent_tree((first_revision,
205
            tree.branch.repository.revision_tree(first_revision)))
206
        self.assertConsistentParents([second_revision, first_revision], tree)
207
        
208
    def test_add_second_parent_tree_ghost(self):
209
        """Test adding the second parent id - as a ghost"""
210
        tree = self.make_branch_and_tree('.')
211
        first_revision = tree.commit('first post')
212
        tree.add_parent_tree(('second', None))
213
        self.assertConsistentParents([first_revision, 'second'], tree)