~bzr-pqm/bzr/bzr.dev

2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2006 Canonical Ltd
1908.5.2 by Robert Collins
Create and test set_parent_trees.
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.7.7 by Robert Collins
Deprecated WorkingTree.pending_merges.
21
from bzrlib import errors, symbol_versioning
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):
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
29
        """Check that the parents found are as expected.
30
31
        This test helper also checks that they are consistent with
32
        the pre-get_parent_ids() api - which is now deprecated.
33
        """
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.
34
        self.assertEqual(expected, tree.get_parent_ids())
35
        if expected == []:
1908.7.11 by Robert Collins
Merge bzr.dev and undeprecated WorkingTree.last_revision as per review feedback.
36
            self.assertEqual(None, tree.last_revision())
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.
37
        else:
1908.7.11 by Robert Collins
Merge bzr.dev and undeprecated WorkingTree.last_revision as per review feedback.
38
            self.assertEqual(expected[0], tree.last_revision())
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
39
        self.assertEqual(expected[1:],
1908.7.8 by Robert Collins
Merge improved test deprecation helpers, simplifying handling of deprecated WorkingTree function tests.
40
            self.applyDeprecated(symbol_versioning.zero_eleven,
41
                tree.pending_merges))
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.
42
43
44
class TestSetParents(TestParents):
1908.5.2 by Robert Collins
Create and test set_parent_trees.
45
46
    def test_set_no_parents(self):
47
        t = self.make_branch_and_tree('.')
48
        t.set_parent_trees([])
49
        self.assertEqual([], t.get_parent_ids())
50
        # now give it a real parent, and then set it to no parents again.
51
        t.commit('first post')
52
        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.
53
        self.assertConsistentParents([], t)
1908.5.2 by Robert Collins
Create and test set_parent_trees.
54
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.
55
    def test_set_one_ghost_parent_rejects(self):
56
        t = self.make_branch_and_tree('.')
1908.5.12 by Robert Collins
Apply review feedback - paired with Martin.
57
        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.
58
            t.set_parent_trees, [('missing-revision-id', None)])
59
60
    def test_set_one_ghost_parent_force(self):
61
        t = self.make_branch_and_tree('.')
62
        t.set_parent_trees([('missing-revision-id', None)],
63
            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.
64
        self.assertConsistentParents(['missing-revision-id'], t)
1908.5.2 by Robert Collins
Create and test set_parent_trees.
65
66
    def test_set_two_parents_one_ghost(self):
67
        t = self.make_branch_and_tree('.')
68
        revision_in_repo = t.commit('first post')
69
        # remove the tree's history
70
        uncommit(t.branch, tree=t)
71
        rev_tree = t.branch.repository.revision_tree(revision_in_repo)
72
        t.set_parent_trees([(revision_in_repo, rev_tree),
73
            ('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.
74
        self.assertConsistentParents([revision_in_repo, 'another-missing'], t)
1908.5.2 by Robert Collins
Create and test set_parent_trees.
75
76
    def test_set_three_parents(self):
77
        t = self.make_branch_and_tree('.')
78
        first_revision = t.commit('first post')
79
        uncommit(t.branch, tree=t)
80
        second_revision = t.commit('second post')
81
        uncommit(t.branch, tree=t)
82
        third_revision = t.commit('third post')
83
        uncommit(t.branch, tree=t)
84
        rev_tree1 = t.branch.repository.revision_tree(first_revision)
85
        rev_tree2 = t.branch.repository.revision_tree(second_revision)
86
        rev_tree3 = t.branch.repository.revision_tree(third_revision)
87
        t.set_parent_trees([(first_revision, rev_tree1),
88
            (second_revision, rev_tree2),
89
            (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.
90
        self.assertConsistentParents(
91
            [first_revision, second_revision, third_revision], t)
1908.5.4 by Robert Collins
Add add_parent_tree_id WorkingTree helper api.
92
1908.5.5 by Robert Collins
Add WorkingTree.set_parent_ids.
93
    def test_set_no_parents_ids(self):
94
        t = self.make_branch_and_tree('.')
95
        t.set_parent_ids([])
96
        self.assertEqual([], t.get_parent_ids())
97
        # now give it a real parent, and then set it to no parents again.
98
        t.commit('first post')
99
        t.set_parent_ids([])
100
        self.assertConsistentParents([], t)
101
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.
102
    def test_set_one_ghost_parent_ids_rejects(self):
103
        t = self.make_branch_and_tree('.')
1908.5.12 by Robert Collins
Apply review feedback - paired with Martin.
104
        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.
105
            t.set_parent_ids, ['missing-revision-id'])
106
107
    def test_set_one_ghost_parent_ids_force(self):
108
        t = self.make_branch_and_tree('.')
109
        t.set_parent_ids(['missing-revision-id'],
110
            allow_leftmost_as_ghost=True)
1908.5.5 by Robert Collins
Add WorkingTree.set_parent_ids.
111
        self.assertConsistentParents(['missing-revision-id'], t)
112
113
    def test_set_two_parents_one_ghost_ids(self):
114
        t = self.make_branch_and_tree('.')
115
        revision_in_repo = t.commit('first post')
116
        # remove the tree's history
117
        uncommit(t.branch, tree=t)
118
        rev_tree = t.branch.repository.revision_tree(revision_in_repo)
119
        t.set_parent_ids([revision_in_repo, 'another-missing'])
120
        self.assertConsistentParents([revision_in_repo, 'another-missing'], t)
121
122
    def test_set_three_parents_ids(self):
123
        t = self.make_branch_and_tree('.')
124
        first_revision = t.commit('first post')
125
        uncommit(t.branch, tree=t)
126
        second_revision = t.commit('second post')
127
        uncommit(t.branch, tree=t)
128
        third_revision = t.commit('third post')
129
        uncommit(t.branch, tree=t)
130
        rev_tree1 = t.branch.repository.revision_tree(first_revision)
131
        rev_tree2 = t.branch.repository.revision_tree(second_revision)
132
        rev_tree3 = t.branch.repository.revision_tree(third_revision)
133
        t.set_parent_ids([first_revision, second_revision, third_revision])
134
        self.assertConsistentParents(
135
            [first_revision, second_revision, third_revision], t)
136
1908.5.4 by Robert Collins
Add add_parent_tree_id WorkingTree helper api.
137
1908.5.6 by Robert Collins
Add add_parent_tree to WorkingTree.
138
class TestAddParent(TestParents):
1908.5.4 by Robert Collins
Add add_parent_tree_id WorkingTree helper api.
139
140
    def test_add_first_parent_id(self):
141
        """Test adding the first parent id"""
142
        tree = self.make_branch_and_tree('.')
143
        first_revision = tree.commit('first post')
144
        uncommit(tree.branch, tree=tree)
145
        tree.add_parent_tree_id(first_revision)
146
        self.assertConsistentParents([first_revision], tree)
147
        
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.
148
    def test_add_first_parent_id_ghost_rejects(self):
149
        """Test adding the first parent id - as a ghost"""
150
        tree = self.make_branch_and_tree('.')
1908.5.12 by Robert Collins
Apply review feedback - paired with Martin.
151
        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.
152
            tree.add_parent_tree_id, 'first-revision')
153
        
154
    def test_add_first_parent_id_ghost_force(self):
155
        """Test adding the first parent id - as a ghost"""
156
        tree = self.make_branch_and_tree('.')
157
        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.
158
        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.
159
160
    def test_add_second_parent_id_with_ghost_first(self):
161
        """Test adding the second parent when the first is a ghost."""
162
        tree = self.make_branch_and_tree('.')
163
        tree.add_parent_tree_id('first-revision', allow_leftmost_as_ghost=True)
164
        tree.add_parent_tree_id('second')
165
        self.assertConsistentParents(['first-revision', 'second'], tree)
1908.5.4 by Robert Collins
Add add_parent_tree_id WorkingTree helper api.
166
        
167
    def test_add_second_parent_id(self):
168
        """Test adding the second parent id"""
169
        tree = self.make_branch_and_tree('.')
170
        first_revision = tree.commit('first post')
171
        uncommit(tree.branch, tree=tree)
172
        second_revision = tree.commit('second post')
173
        tree.add_parent_tree_id(first_revision)
174
        self.assertConsistentParents([second_revision, first_revision], tree)
175
        
176
    def test_add_second_parent_id_ghost(self):
177
        """Test adding the second parent id - as a ghost"""
178
        tree = self.make_branch_and_tree('.')
179
        first_revision = tree.commit('first post')
180
        tree.add_parent_tree_id('second')
181
        self.assertConsistentParents([first_revision, 'second'], tree)
1908.5.6 by Robert Collins
Add add_parent_tree to WorkingTree.
182
        
183
    def test_add_first_parent_tree(self):
184
        """Test adding the first parent id"""
185
        tree = self.make_branch_and_tree('.')
186
        first_revision = tree.commit('first post')
187
        uncommit(tree.branch, tree=tree)
188
        tree.add_parent_tree((first_revision,
189
            tree.branch.repository.revision_tree(first_revision)))
190
        self.assertConsistentParents([first_revision], tree)
191
        
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.
192
    def test_add_first_parent_tree_ghost_rejects(self):
193
        """Test adding the first parent id - as a ghost"""
194
        tree = self.make_branch_and_tree('.')
1908.5.12 by Robert Collins
Apply review feedback - paired with Martin.
195
        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.
196
            tree.add_parent_tree, ('first-revision', None))
197
        
198
    def test_add_first_parent_tree_ghost_force(self):
199
        """Test adding the first parent id - as a ghost"""
200
        tree = self.make_branch_and_tree('.')
201
        tree.add_parent_tree(('first-revision', None),
202
            allow_leftmost_as_ghost=True)
1908.5.6 by Robert Collins
Add add_parent_tree to WorkingTree.
203
        self.assertConsistentParents(['first-revision'], tree)
204
        
205
    def test_add_second_parent_tree(self):
206
        """Test adding the second parent id"""
207
        tree = self.make_branch_and_tree('.')
208
        first_revision = tree.commit('first post')
209
        uncommit(tree.branch, tree=tree)
210
        second_revision = tree.commit('second post')
211
        tree.add_parent_tree((first_revision,
212
            tree.branch.repository.revision_tree(first_revision)))
213
        self.assertConsistentParents([second_revision, first_revision], tree)
214
        
215
    def test_add_second_parent_tree_ghost(self):
216
        """Test adding the second parent id - as a ghost"""
217
        tree = self.make_branch_and_tree('.')
218
        first_revision = tree.commit('first post')
219
        tree.add_parent_tree(('second', None))
220
        self.assertConsistentParents([first_revision, 'second'], tree)