/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1908.5.2 by Robert Collins
Create and test set_parent_trees.
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
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
21
from ... import (
2598.5.2 by Aaron Bentley
Got all tests passing with Branch returning 'null:' for null revision
22
    errors,
23
    revision as _mod_revision,
24
    )
6670.4.3 by Jelmer Vernooij
Fix more imports.
25
from ...bzr.inventory import (
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
26
    Inventory,
27
    InventoryFile,
28
    InventoryDirectory,
29
    InventoryLink,
30
    )
6913.4.2 by Jelmer Vernooij
Skip parents tests against non-inventory trees.
31
from ...bzr.inventorytree import (
32
    InventoryRevisionTree,
33
    InventoryTree,
34
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
35
from ...sixish import (
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
36
    BytesIO,
37
    )
6913.4.2 by Jelmer Vernooij
Skip parents tests against non-inventory trees.
38
from ...tests import TestNotApplicable
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
39
from ..per_workingtree import TestCaseWithWorkingTree
40
from .. import (
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
41
    features,
42
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
43
from ...uncommit import uncommit
1908.5.2 by Robert Collins
Create and test set_parent_trees.
44
45
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
class TestParents(TestCaseWithWorkingTree):
47
48
    def assertConsistentParents(self, expected, tree):
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
49
        """Check that the parents found are as expected.
50
51
        This test helper also checks that they are consistent with
52
        the pre-get_parent_ids() api - which is now deprecated.
53
        """
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.
54
        self.assertEqual(expected, tree.get_parent_ids())
55
        if expected == []:
2598.5.7 by Aaron Bentley
Updates from review
56
            self.assertEqual(_mod_revision.NULL_REVISION,
57
                             _mod_revision.ensure_null(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.
58
        else:
1908.7.11 by Robert Collins
Merge bzr.dev and undeprecated WorkingTree.last_revision as per review feedback.
59
            self.assertEqual(expected[0], 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.
60
61
2598.5.2 by Aaron Bentley
Got all tests passing with Branch returning 'null:' for null revision
62
class TestGetParents(TestParents):
63
64
    def test_get_parents(self):
65
        t = self.make_branch_and_tree('.')
66
        self.assertEqual([], t.get_parent_ids())
67
68
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.
69
class TestSetParents(TestParents):
1908.5.2 by Robert Collins
Create and test set_parent_trees.
70
71
    def test_set_no_parents(self):
72
        t = self.make_branch_and_tree('.')
73
        t.set_parent_trees([])
74
        self.assertEqual([], t.get_parent_ids())
75
        # now give it a real parent, and then set it to no parents again.
76
        t.commit('first post')
77
        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.
78
        self.assertConsistentParents([], t)
1908.5.2 by Robert Collins
Create and test set_parent_trees.
79
2598.5.2 by Aaron Bentley
Got all tests passing with Branch returning 'null:' for null revision
80
    def test_set_null_parent(self):
81
        t = self.make_branch_and_tree('.')
6973.11.7 by Jelmer Vernooij
Fix more tests.
82
        self.assertRaises(errors.ReservedId, t.set_parent_ids, [b'null:'],
2598.5.2 by Aaron Bentley
Got all tests passing with Branch returning 'null:' for null revision
83
                          allow_leftmost_as_ghost=True)
84
        self.assertRaises(errors.ReservedId, t.set_parent_trees,
6973.11.7 by Jelmer Vernooij
Fix more tests.
85
                          [(b'null:', None)], allow_leftmost_as_ghost=True)
2598.5.2 by Aaron Bentley
Got all tests passing with Branch returning 'null:' for null revision
86
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.
87
    def test_set_one_ghost_parent_rejects(self):
88
        t = self.make_branch_and_tree('.')
1908.5.12 by Robert Collins
Apply review feedback - paired with Martin.
89
        self.assertRaises(errors.GhostRevisionUnusableHere,
7143.15.2 by Jelmer Vernooij
Run autopep8.
90
                          t.set_parent_trees, [(b'missing-revision-id', None)])
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.
91
92
    def test_set_one_ghost_parent_force(self):
93
        t = self.make_branch_and_tree('.')
6844.1.2 by Jelmer Vernooij
Add supports_leftmost_parent_id_as_ghost.
94
        if t._format.supports_leftmost_parent_id_as_ghost:
6973.11.7 by Jelmer Vernooij
Fix more tests.
95
            t.set_parent_trees([(b'missing-revision-id', None)],
7143.15.2 by Jelmer Vernooij
Run autopep8.
96
                               allow_leftmost_as_ghost=True)
6973.11.7 by Jelmer Vernooij
Fix more tests.
97
            self.assertConsistentParents([b'missing-revision-id'], t)
6844.1.1 by Jelmer Vernooij
Many more foreign branch fixes.
98
        else:
99
            self.assertRaises(errors.GhostRevisionUnusableHere,
7143.15.2 by Jelmer Vernooij
Run autopep8.
100
                              t.set_parent_trees, [(b'missing-revision-id', None)])
6844.1.1 by Jelmer Vernooij
Many more foreign branch fixes.
101
            self.assertConsistentParents([], t)
1908.5.2 by Robert Collins
Create and test set_parent_trees.
102
103
    def test_set_two_parents_one_ghost(self):
104
        t = self.make_branch_and_tree('.')
105
        revision_in_repo = t.commit('first post')
106
        # remove the tree's history
107
        uncommit(t.branch, tree=t)
108
        rev_tree = t.branch.repository.revision_tree(revision_in_repo)
6861.5.1 by Jelmer Vernooij
Add supports_righthand_parent_id_as_ghost flag.
109
        if t._format.supports_righthand_parent_id_as_ghost:
110
            t.set_parent_trees([(revision_in_repo, rev_tree),
7143.15.2 by Jelmer Vernooij
Run autopep8.
111
                                (b'another-missing', None)])
112
            self.assertConsistentParents(
113
                [revision_in_repo, b'another-missing'], t)
6861.5.1 by Jelmer Vernooij
Add supports_righthand_parent_id_as_ghost flag.
114
        else:
115
            self.assertRaises(errors.GhostRevisionUnusableHere,
7143.15.2 by Jelmer Vernooij
Run autopep8.
116
                              t.set_parent_trees, [(revision_in_repo, rev_tree),
117
                                                   (b'another-missing', None)])
1908.5.2 by Robert Collins
Create and test set_parent_trees.
118
119
    def test_set_three_parents(self):
120
        t = self.make_branch_and_tree('.')
121
        first_revision = t.commit('first post')
122
        uncommit(t.branch, tree=t)
123
        second_revision = t.commit('second post')
124
        uncommit(t.branch, tree=t)
125
        third_revision = t.commit('third post')
126
        uncommit(t.branch, tree=t)
127
        rev_tree1 = t.branch.repository.revision_tree(first_revision)
128
        rev_tree2 = t.branch.repository.revision_tree(second_revision)
129
        rev_tree3 = t.branch.repository.revision_tree(third_revision)
130
        t.set_parent_trees([(first_revision, rev_tree1),
7143.15.2 by Jelmer Vernooij
Run autopep8.
131
                            (second_revision, rev_tree2),
132
                            (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.
133
        self.assertConsistentParents(
134
            [first_revision, second_revision, third_revision], t)
1908.5.4 by Robert Collins
Add add_parent_tree_id WorkingTree helper api.
135
1908.5.5 by Robert Collins
Add WorkingTree.set_parent_ids.
136
    def test_set_no_parents_ids(self):
137
        t = self.make_branch_and_tree('.')
138
        t.set_parent_ids([])
139
        self.assertEqual([], t.get_parent_ids())
140
        # now give it a real parent, and then set it to no parents again.
141
        t.commit('first post')
142
        t.set_parent_ids([])
143
        self.assertConsistentParents([], t)
144
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
    def test_set_one_ghost_parent_ids_rejects(self):
146
        t = self.make_branch_and_tree('.')
1908.5.12 by Robert Collins
Apply review feedback - paired with Martin.
147
        self.assertRaises(errors.GhostRevisionUnusableHere,
7143.15.2 by Jelmer Vernooij
Run autopep8.
148
                          t.set_parent_ids, [b'missing-revision-id'])
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.
149
150
    def test_set_one_ghost_parent_ids_force(self):
151
        t = self.make_branch_and_tree('.')
6844.1.2 by Jelmer Vernooij
Add supports_leftmost_parent_id_as_ghost.
152
        if t._format.supports_leftmost_parent_id_as_ghost:
6973.10.6 by Jelmer Vernooij
Fix tests.
153
            t.set_parent_ids([b'missing-revision-id'],
7143.15.2 by Jelmer Vernooij
Run autopep8.
154
                             allow_leftmost_as_ghost=True)
6973.10.6 by Jelmer Vernooij
Fix tests.
155
            self.assertConsistentParents([b'missing-revision-id'], t)
6844.1.1 by Jelmer Vernooij
Many more foreign branch fixes.
156
        else:
157
            self.assertRaises(
158
                errors.GhostRevisionUnusableHere, t.set_parent_ids,
6973.10.6 by Jelmer Vernooij
Fix tests.
159
                [b'missing-revision-id'], allow_leftmost_as_ghost=True)
1908.5.5 by Robert Collins
Add WorkingTree.set_parent_ids.
160
161
    def test_set_two_parents_one_ghost_ids(self):
162
        t = self.make_branch_and_tree('.')
163
        revision_in_repo = t.commit('first post')
164
        # remove the tree's history
165
        uncommit(t.branch, tree=t)
166
        rev_tree = t.branch.repository.revision_tree(revision_in_repo)
6861.5.1 by Jelmer Vernooij
Add supports_righthand_parent_id_as_ghost flag.
167
        if t._format.supports_righthand_parent_id_as_ghost:
6973.10.6 by Jelmer Vernooij
Fix tests.
168
            t.set_parent_ids([revision_in_repo, b'another-missing'])
7143.15.2 by Jelmer Vernooij
Run autopep8.
169
            self.assertConsistentParents(
170
                [revision_in_repo, b'another-missing'], t)
6861.5.1 by Jelmer Vernooij
Add supports_righthand_parent_id_as_ghost flag.
171
        else:
172
            self.assertRaises(errors.GhostRevisionUnusableHere,
7143.15.2 by Jelmer Vernooij
Run autopep8.
173
                              t.set_parent_ids, [revision_in_repo, b'another-missing'])
1908.5.5 by Robert Collins
Add WorkingTree.set_parent_ids.
174
175
    def test_set_three_parents_ids(self):
176
        t = self.make_branch_and_tree('.')
177
        first_revision = t.commit('first post')
178
        uncommit(t.branch, tree=t)
179
        second_revision = t.commit('second post')
180
        uncommit(t.branch, tree=t)
181
        third_revision = t.commit('third post')
182
        uncommit(t.branch, tree=t)
183
        rev_tree1 = t.branch.repository.revision_tree(first_revision)
184
        rev_tree2 = t.branch.repository.revision_tree(second_revision)
185
        rev_tree3 = t.branch.repository.revision_tree(third_revision)
186
        t.set_parent_ids([first_revision, second_revision, third_revision])
187
        self.assertConsistentParents(
188
            [first_revision, second_revision, third_revision], t)
189
3462.1.2 by John Arbash Meinel
Change WT.set_parent_(ids/trees) to filter out ancestors.
190
    def test_set_duplicate_parent_ids(self):
191
        t = self.make_branch_and_tree('.')
192
        rev1 = t.commit('first post')
193
        uncommit(t.branch, tree=t)
194
        rev2 = t.commit('second post')
195
        uncommit(t.branch, tree=t)
196
        rev3 = t.commit('third post')
197
        uncommit(t.branch, tree=t)
198
        t.set_parent_ids([rev1, rev2, rev2, rev3])
199
        # We strip the duplicate, but preserve the ordering
200
        self.assertConsistentParents([rev1, rev2, rev3], t)
201
202
    def test_set_duplicate_parent_trees(self):
203
        t = self.make_branch_and_tree('.')
204
        rev1 = t.commit('first post')
205
        uncommit(t.branch, tree=t)
206
        rev2 = t.commit('second post')
207
        uncommit(t.branch, tree=t)
208
        rev3 = t.commit('third post')
209
        uncommit(t.branch, tree=t)
210
        rev_tree1 = t.branch.repository.revision_tree(rev1)
211
        rev_tree2 = t.branch.repository.revision_tree(rev2)
212
        rev_tree3 = t.branch.repository.revision_tree(rev3)
213
        t.set_parent_trees([(rev1, rev_tree1), (rev2, rev_tree2),
214
                            (rev2, rev_tree2), (rev3, rev_tree3)])
215
        # We strip the duplicate, but preserve the ordering
216
        self.assertConsistentParents([rev1, rev2, rev3], t)
217
218
    def test_set_parent_ids_in_ancestry(self):
219
        t = self.make_branch_and_tree('.')
220
        rev1 = t.commit('first post')
221
        rev2 = t.commit('second post')
222
        rev3 = t.commit('third post')
223
        # Reset the tree, back to rev1
224
        t.set_parent_ids([rev1])
225
        t.branch.set_last_revision_info(1, rev1)
226
        self.assertConsistentParents([rev1], t)
227
        t.set_parent_ids([rev1, rev2, rev3])
228
        # rev2 is in the ancestry of rev3, so it will be filtered out
229
        self.assertConsistentParents([rev1, rev3], t)
230
        # Order should be preserved, and the first revision should always be
231
        # kept
232
        t.set_parent_ids([rev2, rev3, rev1])
233
        self.assertConsistentParents([rev2, rev3], t)
234
235
    def test_set_parent_trees_in_ancestry(self):
236
        t = self.make_branch_and_tree('.')
237
        rev1 = t.commit('first post')
238
        rev2 = t.commit('second post')
239
        rev3 = t.commit('third post')
240
        # Reset the tree, back to rev1
241
        t.set_parent_ids([rev1])
242
        t.branch.set_last_revision_info(1, rev1)
243
        self.assertConsistentParents([rev1], t)
244
        rev_tree1 = t.branch.repository.revision_tree(rev1)
245
        rev_tree2 = t.branch.repository.revision_tree(rev2)
246
        rev_tree3 = t.branch.repository.revision_tree(rev3)
247
        t.set_parent_trees([(rev1, rev_tree1), (rev2, rev_tree2),
248
                            (rev3, rev_tree3)])
249
        # rev2 is in the ancestry of rev3, so it will be filtered out
250
        self.assertConsistentParents([rev1, rev3], t)
251
        # Order should be preserved, and the first revision should always be
252
        # kept
253
        t.set_parent_trees([(rev2, rev_tree2), (rev1, rev_tree1),
254
                            (rev3, rev_tree3)])
255
        self.assertConsistentParents([rev2, rev3], t)
256
3763.9.7 by Daniel Clemente
Tested Unicode target rather than always trying to create it in UTF-8. Test renamed
257
    def test_unicode_symlink(self):
3763.9.1 by Daniel Clemente
New testcase for bug 272444 (support symlinks to non-ASCII files)
258
        # this tests bug #272444
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
259
        self.requireFeature(features.SymlinkFeature)
260
        self.requireFeature(features.UnicodeFilenameFeature)
3763.9.1 by Daniel Clemente
New testcase for bug 272444 (support symlinks to non-ASCII files)
261
3763.9.3 by Daniel Clemente
Clearer test with better names and just one parent
262
        tree = self.make_branch_and_tree('tree1')
3763.9.2 by Daniel Clemente
Adapted test to use set_parent_ids and raise KnownFailure
263
3763.9.9 by Daniel Clemente
Used a greek omega instead of an accented 'o' to avoid combining characters
264
        # The link points to a file whose name is an omega
265
        # U+03A9 GREEK CAPITAL LETTER OMEGA
266
        # UTF-8: ce a9  UTF-16BE: 03a9  Decimal: Ω
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
267
        target = u'\u03a9'
268
        link_name = u'\N{Euro Sign}link'
269
        os.symlink(target, 'tree1/' + link_name)
6844.1.1 by Jelmer Vernooij
Many more foreign branch fixes.
270
        tree.add([link_name])
3763.9.2 by Daniel Clemente
Adapted test to use set_parent_ids and raise KnownFailure
271
4095.3.1 by Vincent Ladeuil
Fix #339055 and #277444 by handling non ascii symlink targets.
272
        revision1 = tree.commit('added a link to a Unicode target')
273
        revision2 = tree.commit('this revision will be discarded')
274
        tree.set_parent_ids([revision1])
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
275
        tree.lock_read()
276
        self.addCleanup(tree.unlock)
277
        # Check that the symlink target is safely round-tripped in the trees.
6809.4.7 by Jelmer Vernooij
Swap arguments for get_symlink_target and kind/stored_kind.
278
        self.assertEqual(target, tree.get_symlink_target(link_name))
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
279
        basis = tree.basis_tree()
6809.4.7 by Jelmer Vernooij
Swap arguments for get_symlink_target and kind/stored_kind.
280
        self.assertEqual(target, basis.get_symlink_target(link_name))
3763.9.1 by Daniel Clemente
New testcase for bug 272444 (support symlinks to non-ASCII files)
281
1908.5.4 by Robert Collins
Add add_parent_tree_id WorkingTree helper api.
282
1908.5.6 by Robert Collins
Add add_parent_tree to WorkingTree.
283
class TestAddParent(TestParents):
1908.5.4 by Robert Collins
Add add_parent_tree_id WorkingTree helper api.
284
285
    def test_add_first_parent_id(self):
286
        """Test adding the first parent id"""
287
        tree = self.make_branch_and_tree('.')
288
        first_revision = tree.commit('first post')
289
        uncommit(tree.branch, tree=tree)
290
        tree.add_parent_tree_id(first_revision)
291
        self.assertConsistentParents([first_revision], tree)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
292
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.
293
    def test_add_first_parent_id_ghost_rejects(self):
294
        """Test adding the first parent id - as a ghost"""
295
        tree = self.make_branch_and_tree('.')
1908.5.12 by Robert Collins
Apply review feedback - paired with Martin.
296
        self.assertRaises(errors.GhostRevisionUnusableHere,
7143.15.2 by Jelmer Vernooij
Run autopep8.
297
                          tree.add_parent_tree_id, b'first-revision')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
298
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.
299
    def test_add_first_parent_id_ghost_force(self):
300
        """Test adding the first parent id - as a ghost"""
301
        tree = self.make_branch_and_tree('.')
6844.1.1 by Jelmer Vernooij
Many more foreign branch fixes.
302
        try:
7143.15.2 by Jelmer Vernooij
Run autopep8.
303
            tree.add_parent_tree_id(
304
                b'first-revision', allow_leftmost_as_ghost=True)
6844.1.1 by Jelmer Vernooij
Many more foreign branch fixes.
305
        except errors.GhostRevisionUnusableHere:
6844.1.2 by Jelmer Vernooij
Add supports_leftmost_parent_id_as_ghost.
306
            self.assertFalse(tree._format.supports_leftmost_parent_id_as_ghost)
6844.1.1 by Jelmer Vernooij
Many more foreign branch fixes.
307
        else:
6844.1.2 by Jelmer Vernooij
Add supports_leftmost_parent_id_as_ghost.
308
            self.assertTrue(tree._format.supports_leftmost_parent_id_as_ghost)
6973.10.4 by Jelmer Vernooij
Update python3.passing.
309
            self.assertConsistentParents([b'first-revision'], tree)
1908.5.13 by Robert Collins
Adding a parent when the first is a ghost already should not require forcing it.
310
311
    def test_add_second_parent_id_with_ghost_first(self):
312
        """Test adding the second parent when the first is a ghost."""
313
        tree = self.make_branch_and_tree('.')
6844.1.1 by Jelmer Vernooij
Many more foreign branch fixes.
314
        try:
7143.15.2 by Jelmer Vernooij
Run autopep8.
315
            tree.add_parent_tree_id(
316
                b'first-revision', allow_leftmost_as_ghost=True)
6844.1.1 by Jelmer Vernooij
Many more foreign branch fixes.
317
        except errors.GhostRevisionUnusableHere:
6844.1.2 by Jelmer Vernooij
Add supports_leftmost_parent_id_as_ghost.
318
            self.assertFalse(tree._format.supports_leftmost_parent_id_as_ghost)
6844.1.1 by Jelmer Vernooij
Many more foreign branch fixes.
319
        else:
6973.10.4 by Jelmer Vernooij
Update python3.passing.
320
            tree.add_parent_tree_id(b'second')
321
            self.assertConsistentParents([b'first-revision', b'second'], tree)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
322
1908.5.4 by Robert Collins
Add add_parent_tree_id WorkingTree helper api.
323
    def test_add_second_parent_id(self):
324
        """Test adding the second parent id"""
325
        tree = self.make_branch_and_tree('.')
326
        first_revision = tree.commit('first post')
327
        uncommit(tree.branch, tree=tree)
328
        second_revision = tree.commit('second post')
329
        tree.add_parent_tree_id(first_revision)
330
        self.assertConsistentParents([second_revision, first_revision], tree)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
331
1908.5.4 by Robert Collins
Add add_parent_tree_id WorkingTree helper api.
332
    def test_add_second_parent_id_ghost(self):
333
        """Test adding the second parent id - as a ghost"""
334
        tree = self.make_branch_and_tree('.')
335
        first_revision = tree.commit('first post')
6861.5.1 by Jelmer Vernooij
Add supports_righthand_parent_id_as_ghost flag.
336
        if tree._format.supports_righthand_parent_id_as_ghost:
6973.10.4 by Jelmer Vernooij
Update python3.passing.
337
            tree.add_parent_tree_id(b'second')
338
            self.assertConsistentParents([first_revision, b'second'], tree)
6861.5.1 by Jelmer Vernooij
Add supports_righthand_parent_id_as_ghost flag.
339
        else:
340
            self.assertRaises(errors.GhostRevisionUnusableHere,
7143.15.2 by Jelmer Vernooij
Run autopep8.
341
                              tree.add_parent_tree_id, b'second')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
342
1908.5.6 by Robert Collins
Add add_parent_tree to WorkingTree.
343
    def test_add_first_parent_tree(self):
344
        """Test adding the first parent id"""
345
        tree = self.make_branch_and_tree('.')
346
        first_revision = tree.commit('first post')
347
        uncommit(tree.branch, tree=tree)
348
        tree.add_parent_tree((first_revision,
7143.15.2 by Jelmer Vernooij
Run autopep8.
349
                              tree.branch.repository.revision_tree(first_revision)))
1908.5.6 by Robert Collins
Add add_parent_tree to WorkingTree.
350
        self.assertConsistentParents([first_revision], tree)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
351
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.
352
    def test_add_first_parent_tree_ghost_rejects(self):
353
        """Test adding the first parent id - as a ghost"""
354
        tree = self.make_branch_and_tree('.')
1908.5.12 by Robert Collins
Apply review feedback - paired with Martin.
355
        self.assertRaises(errors.GhostRevisionUnusableHere,
7143.15.2 by Jelmer Vernooij
Run autopep8.
356
                          tree.add_parent_tree, (b'first-revision', None))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
357
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.
358
    def test_add_first_parent_tree_ghost_force(self):
359
        """Test adding the first parent id - as a ghost"""
360
        tree = self.make_branch_and_tree('.')
6844.1.1 by Jelmer Vernooij
Many more foreign branch fixes.
361
        try:
7045.4.1 by Jelmer Vernooij
Some brz-git fixes.
362
            tree.add_parent_tree((b'first-revision', None),
7143.15.2 by Jelmer Vernooij
Run autopep8.
363
                                 allow_leftmost_as_ghost=True)
6844.1.1 by Jelmer Vernooij
Many more foreign branch fixes.
364
        except errors.GhostRevisionUnusableHere:
6844.1.2 by Jelmer Vernooij
Add supports_leftmost_parent_id_as_ghost.
365
            self.assertFalse(tree._format.supports_leftmost_parent_id_as_ghost)
6844.1.1 by Jelmer Vernooij
Many more foreign branch fixes.
366
        else:
6844.1.2 by Jelmer Vernooij
Add supports_leftmost_parent_id_as_ghost.
367
            self.assertTrue(tree._format.supports_leftmost_parent_id_as_ghost)
7045.4.1 by Jelmer Vernooij
Some brz-git fixes.
368
            self.assertConsistentParents([b'first-revision'], tree)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
369
1908.5.6 by Robert Collins
Add add_parent_tree to WorkingTree.
370
    def test_add_second_parent_tree(self):
371
        """Test adding the second parent id"""
372
        tree = self.make_branch_and_tree('.')
373
        first_revision = tree.commit('first post')
374
        uncommit(tree.branch, tree=tree)
375
        second_revision = tree.commit('second post')
376
        tree.add_parent_tree((first_revision,
7143.15.2 by Jelmer Vernooij
Run autopep8.
377
                              tree.branch.repository.revision_tree(first_revision)))
1908.5.6 by Robert Collins
Add add_parent_tree to WorkingTree.
378
        self.assertConsistentParents([second_revision, first_revision], tree)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
379
1908.5.6 by Robert Collins
Add add_parent_tree to WorkingTree.
380
    def test_add_second_parent_tree_ghost(self):
381
        """Test adding the second parent id - as a ghost"""
382
        tree = self.make_branch_and_tree('.')
383
        first_revision = tree.commit('first post')
6861.5.1 by Jelmer Vernooij
Add supports_righthand_parent_id_as_ghost flag.
384
        if tree._format.supports_righthand_parent_id_as_ghost:
7045.4.1 by Jelmer Vernooij
Some brz-git fixes.
385
            tree.add_parent_tree((b'second', None))
386
            self.assertConsistentParents([first_revision, b'second'], tree)
6861.5.1 by Jelmer Vernooij
Add supports_righthand_parent_id_as_ghost flag.
387
        else:
388
            self.assertRaises(errors.GhostRevisionUnusableHere,
7143.15.2 by Jelmer Vernooij
Run autopep8.
389
                              tree.add_parent_tree, (b'second', None))
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
390
391
3253.2.1 by John Arbash Meinel
Fix moving directories to root nodes.
392
class UpdateToOneParentViaDeltaTests(TestCaseWithWorkingTree):
2903.2.7 by Martin Pool
Rename update_to_one_parent_via_delta to more wieldy update_basis_by_delta
393
    """Tests for the update_basis_by_delta call.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
394
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
395
    This is intuitively defined as 'apply an inventory delta to the basis and
396
    discard other parents', but for trees that have an inventory that is not
397
    managed as a tree-by-id, the implementation requires roughly duplicated
398
    tests with those for apply_inventory_delta on the main tree.
399
    """
400
401
    def assertDeltaApplicationResultsInExpectedBasis(self, tree, revid, delta,
7143.15.2 by Jelmer Vernooij
Run autopep8.
402
                                                     expected_inventory):
6913.4.2 by Jelmer Vernooij
Skip parents tests against non-inventory trees.
403
        with tree.lock_write():
2929.2.1 by Robert Collins
* Commit updates the state of the working tree via a delta rather than
404
            tree.update_basis_by_delta(revid, delta)
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
405
        # check the last revision was adjusted to rev_id
406
        self.assertEqual(revid, tree.last_revision())
407
        # check the parents are what we expect
408
        self.assertEqual([revid], tree.get_parent_ids())
409
        # check that the basis tree has the inventory we expect from applying
410
        # the delta.
411
        result_basis = tree.basis_tree()
6913.4.2 by Jelmer Vernooij
Skip parents tests against non-inventory trees.
412
        with result_basis.lock_read():
6405.2.9 by Jelmer Vernooij
More test fixes.
413
            self.assertEqual(expected_inventory, result_basis.root_inventory)
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
414
415
    def make_inv_delta(self, old, new):
416
        """Make an inventory delta from two inventories."""
6656.1.1 by Martin
Apply 2to3 dict fixer and clean up resulting mess using view helpers
417
        old_ids = set(old._byid)
418
        new_ids = set(new._byid)
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
419
        adds = new_ids - old_ids
420
        deletes = old_ids - new_ids
421
        common = old_ids.intersection(new_ids)
422
        delta = []
423
        for file_id in deletes:
424
            delta.append((old.id2path(file_id), None, file_id, None))
425
        for file_id in adds:
7143.15.2 by Jelmer Vernooij
Run autopep8.
426
            delta.append((None, new.id2path(file_id),
427
                          file_id, new.get_entry(file_id)))
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
428
        for file_id in common:
6915.4.2 by Jelmer Vernooij
Remove __getitem__ and __iter__ from Inventory.
429
            if old.get_entry(file_id) != new.get_entry(file_id):
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
430
                delta.append((old.id2path(file_id), new.id2path(file_id),
7143.15.2 by Jelmer Vernooij
Run autopep8.
431
                              file_id, new.get_entry(file_id)))
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
432
        return delta
433
434
    def fake_up_revision(self, tree, revid, shape):
5809.4.1 by Jelmer Vernooij
Avoid .texts.add_lines, rather use Repository.get_commit_builder.
435
6913.4.2 by Jelmer Vernooij
Skip parents tests against non-inventory trees.
436
        if not isinstance(tree, InventoryTree):
437
            raise TestNotApplicable("test requires inventory tree")
438
5809.4.1 by Jelmer Vernooij
Avoid .texts.add_lines, rather use Repository.get_commit_builder.
439
        class ShapeTree(InventoryRevisionTree):
440
441
            def __init__(self, shape):
442
                self._repository = tree.branch.repository
443
                self._inventory = shape
444
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
445
            def get_file_text(self, path, file_id=None):
446
                if file_id is None:
447
                    file_id = self.path2id(path)
6915.4.2 by Jelmer Vernooij
Remove __getitem__ and __iter__ from Inventory.
448
                ie = self.root_inventory.get_entry(file_id)
5809.4.1 by Jelmer Vernooij
Avoid .texts.add_lines, rather use Repository.get_commit_builder.
449
                if ie.kind != "file":
6977.2.1 by Jelmer Vernooij
Require that get_file implementations are contect managers, simplify file handling in transform.
450
                    return b""
451
                return b'a' * ie.text_size
5809.4.1 by Jelmer Vernooij
Avoid .texts.add_lines, rather use Repository.get_commit_builder.
452
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
453
            def get_file(self, path, file_id=None):
454
                return BytesIO(self.get_file_text(path, file_id))
5809.4.1 by Jelmer Vernooij
Avoid .texts.add_lines, rather use Repository.get_commit_builder.
455
6851.1.1 by Jelmer Vernooij
More foreign branch fixes.
456
        with tree.lock_write():
5809.4.1 by Jelmer Vernooij
Avoid .texts.add_lines, rather use Repository.get_commit_builder.
457
            if shape.root.revision is None:
458
                shape.root.revision = revid
459
            builder = tree.branch.get_commit_builder(
7143.15.2 by Jelmer Vernooij
Run autopep8.
460
                parents=[],
461
                timestamp=0,
462
                timezone=None,
463
                committer="Foo Bar <foo@example.com>",
464
                revision_id=revid)
5809.4.1 by Jelmer Vernooij
Avoid .texts.add_lines, rather use Repository.get_commit_builder.
465
            shape_tree = ShapeTree(shape)
5809.4.3 by Jelmer Vernooij
Fix base revid.
466
            base_tree = tree.branch.repository.revision_tree(
7143.15.2 by Jelmer Vernooij
Run autopep8.
467
                _mod_revision.NULL_REVISION)
5809.4.1 by Jelmer Vernooij
Avoid .texts.add_lines, rather use Repository.get_commit_builder.
468
            changes = shape_tree.iter_changes(
5809.4.3 by Jelmer Vernooij
Fix base revid.
469
                base_tree)
5809.4.1 by Jelmer Vernooij
Avoid .texts.add_lines, rather use Repository.get_commit_builder.
470
            list(builder.record_iter_changes(shape_tree,
7143.15.2 by Jelmer Vernooij
Run autopep8.
471
                                             base_tree.get_revision_id(), changes))
5809.4.1 by Jelmer Vernooij
Avoid .texts.add_lines, rather use Repository.get_commit_builder.
472
            builder.finish_inventory()
473
            builder.commit("Message")
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
474
475
    def add_entry(self, inv, rev_id, entry):
476
        entry.revision = rev_id
477
        inv.add(entry)
478
479
    def add_dir(self, inv, rev_id, file_id, parent_id, name):
480
        new_dir = InventoryDirectory(file_id, name, parent_id)
481
        self.add_entry(inv, rev_id, new_dir)
482
483
    def add_file(self, inv, rev_id, file_id, parent_id, name, sha, size):
484
        new_file = InventoryFile(file_id, name, parent_id)
485
        new_file.text_sha1 = sha
486
        new_file.text_size = size
487
        self.add_entry(inv, rev_id, new_file)
488
489
    def add_link(self, inv, rev_id, file_id, parent_id, name, target):
490
        new_link = InventoryLink(file_id, name, parent_id)
491
        new_link.symlink_target = target
492
        self.add_entry(inv, rev_id, new_link)
493
494
    def add_new_root(self, new_shape, old_revid, new_revid):
495
        if self.bzrdir_format.repository_format.rich_root_data:
6973.11.7 by Jelmer Vernooij
Fix more tests.
496
            self.add_dir(new_shape, old_revid, b'root-id', None, '')
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
497
        else:
6973.11.7 by Jelmer Vernooij
Fix more tests.
498
            self.add_dir(new_shape, new_revid, b'root-id', None, '')
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
499
500
    def assertTransitionFromBasisToShape(self, basis_shape, basis_revid,
7143.15.2 by Jelmer Vernooij
Run autopep8.
501
                                         new_shape, new_revid, extra_parent=None, set_current_inventory=True):
2889.1.1 by Robert Collins
* The class ``bzrlib.repofmt.knitrepo.KnitRepository3`` has been folded into
502
        # set the inventory revision ids.
503
        basis_shape.revision_id = basis_revid
504
        new_shape.revision_id = new_revid
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
505
        delta = self.make_inv_delta(basis_shape, new_shape)
506
        tree = self.make_branch_and_tree('tree')
507
        # the shapes need to be in the tree's repository to be able to set them
508
        # as a parent, but the file content is not needed.
509
        if basis_revid is not None:
510
            self.fake_up_revision(tree, basis_revid, basis_shape)
511
            parents = [basis_revid]
512
            if extra_parent is not None:
513
                parents.append(extra_parent)
514
            tree.set_parent_ids(parents)
515
        self.fake_up_revision(tree, new_revid, new_shape)
6015.45.2 by Brian de Alwis, John Arbash Meinel
Backport the fix for bug #855155 to bzr-2.4
516
        if set_current_inventory:
517
            # give tree an inventory of new_shape
518
            tree._write_inventory(new_shape)
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
519
        self.assertDeltaApplicationResultsInExpectedBasis(tree, new_revid,
7143.15.2 by Jelmer Vernooij
Run autopep8.
520
                                                          delta, new_shape)
2929.2.2 by Robert Collins
Review feedback on dirstate update_basis_via_delta logic.
521
        # The tree should be internally consistent; while this is a moderately
522
        # large hammer, this is a particularly sensitive area of code, so the
523
        # extra assurance is well worth it.
524
        tree._validate()
6437.70.4 by John Arbash Meinel
Now that we have 2 possible locations where things exist, we must cleanup both.
525
        # If tree.branch is remote
6437.70.5 by John Arbash Meinel
user_url seems a cleaner way to do the same thing.
526
        if tree.user_url != tree.branch.user_url:
6437.70.4 by John Arbash Meinel
Now that we have 2 possible locations where things exist, we must cleanup both.
527
            # We have a lightweight checkout, delete both locations
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
528
            tree.branch.controldir.root_transport.delete_tree('.')
529
        tree.controldir.root_transport.delete_tree('.')
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
530
531
    def test_no_parents_just_root(self):
532
        """Test doing an empty commit - no parent, set a root only."""
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
533
        basis_shape = Inventory(root_id=None)  # empty tree
534
        new_shape = Inventory()  # tree with a root
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
535
        self.assertTransitionFromBasisToShape(basis_shape, None, new_shape,
7143.15.2 by Jelmer Vernooij
Run autopep8.
536
                                              b'new_parent')
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
537
538
    def test_no_parents_full_tree(self):
539
        """Test doing a regular initial commit with files and dirs."""
7143.15.2 by Jelmer Vernooij
Run autopep8.
540
        basis_shape = Inventory(root_id=None)  # empty tree
6973.11.7 by Jelmer Vernooij
Fix more tests.
541
        revid = b'new-parent'
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
542
        new_shape = Inventory(root_id=None)
6973.11.7 by Jelmer Vernooij
Fix more tests.
543
        self.add_dir(new_shape, revid, b'root-id', None, '')
7143.15.2 by Jelmer Vernooij
Run autopep8.
544
        self.add_link(new_shape, revid, b'link-id',
545
                      b'root-id', 'link', 'target')
7045.1.1 by Jelmer Vernooij
Fix another 300 tests.
546
        self.add_file(new_shape, revid, b'file-id', b'root-id', 'file', b'1' * 32,
7143.15.2 by Jelmer Vernooij
Run autopep8.
547
                      12)
6973.11.7 by Jelmer Vernooij
Fix more tests.
548
        self.add_dir(new_shape, revid, b'dir-id', b'root-id', 'dir')
549
        self.add_file(new_shape, revid, b'subfile-id', b'dir-id', 'subfile',
7143.15.2 by Jelmer Vernooij
Run autopep8.
550
                      b'2' * 32, 24)
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
551
        self.assertTransitionFromBasisToShape(basis_shape, None, new_shape,
7143.15.2 by Jelmer Vernooij
Run autopep8.
552
                                              revid)
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
553
554
    def test_file_content_change(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
555
        old_revid = b'old-parent'
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
556
        basis_shape = Inventory(root_id=None)
6973.11.7 by Jelmer Vernooij
Fix more tests.
557
        self.add_dir(basis_shape, old_revid, b'root-id', None, '')
558
        self.add_file(basis_shape, old_revid, b'file-id', b'root-id', 'file',
7143.15.2 by Jelmer Vernooij
Run autopep8.
559
                      b'1' * 32, 12)
6973.11.7 by Jelmer Vernooij
Fix more tests.
560
        new_revid = b'new-parent'
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
561
        new_shape = Inventory(root_id=None)
562
        self.add_new_root(new_shape, old_revid, new_revid)
6973.11.7 by Jelmer Vernooij
Fix more tests.
563
        self.add_file(new_shape, new_revid, b'file-id', b'root-id', 'file',
7143.15.2 by Jelmer Vernooij
Run autopep8.
564
                      b'2' * 32, 24)
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
565
        self.assertTransitionFromBasisToShape(basis_shape, old_revid,
7143.15.2 by Jelmer Vernooij
Run autopep8.
566
                                              new_shape, new_revid)
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
567
568
    def test_link_content_change(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
569
        old_revid = b'old-parent'
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
570
        basis_shape = Inventory(root_id=None)
6973.11.7 by Jelmer Vernooij
Fix more tests.
571
        self.add_dir(basis_shape, old_revid, b'root-id', None, '')
572
        self.add_link(basis_shape, old_revid, b'link-id', b'root-id', 'link',
7143.15.2 by Jelmer Vernooij
Run autopep8.
573
                      'old-target')
6973.11.7 by Jelmer Vernooij
Fix more tests.
574
        new_revid = b'new-parent'
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
575
        new_shape = Inventory(root_id=None)
576
        self.add_new_root(new_shape, old_revid, new_revid)
6973.11.7 by Jelmer Vernooij
Fix more tests.
577
        self.add_link(new_shape, new_revid, b'link-id', b'root-id', 'link',
7143.15.2 by Jelmer Vernooij
Run autopep8.
578
                      'new-target')
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
579
        self.assertTransitionFromBasisToShape(basis_shape, old_revid,
7143.15.2 by Jelmer Vernooij
Run autopep8.
580
                                              new_shape, new_revid)
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
581
582
    def test_kind_changes(self):
583
        def do_file(inv, revid):
7045.1.1 by Jelmer Vernooij
Fix another 300 tests.
584
            self.add_file(inv, revid, b'path-id', b'root-id', 'path', b'1' * 32,
7143.15.2 by Jelmer Vernooij
Run autopep8.
585
                          12)
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
586
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
587
        def do_link(inv, revid):
6973.11.7 by Jelmer Vernooij
Fix more tests.
588
            self.add_link(inv, revid, b'path-id', b'root-id', 'path', 'target')
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
589
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
590
        def do_dir(inv, revid):
6973.11.7 by Jelmer Vernooij
Fix more tests.
591
            self.add_dir(inv, revid, b'path-id', b'root-id', 'path')
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
592
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
593
        for old_factory in (do_file, do_link, do_dir):
594
            for new_factory in (do_file, do_link, do_dir):
595
                if old_factory == new_factory:
596
                    continue
6973.11.7 by Jelmer Vernooij
Fix more tests.
597
                old_revid = b'old-parent'
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
598
                basis_shape = Inventory(root_id=None)
6973.11.7 by Jelmer Vernooij
Fix more tests.
599
                self.add_dir(basis_shape, old_revid, b'root-id', None, '')
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
600
                old_factory(basis_shape, old_revid)
6973.11.7 by Jelmer Vernooij
Fix more tests.
601
                new_revid = b'new-parent'
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
602
                new_shape = Inventory(root_id=None)
603
                self.add_new_root(new_shape, old_revid, new_revid)
604
                new_factory(new_shape, new_revid)
605
                self.assertTransitionFromBasisToShape(basis_shape, old_revid,
7143.15.2 by Jelmer Vernooij
Run autopep8.
606
                                                      new_shape, new_revid)
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
607
608
    def test_content_from_second_parent_is_dropped(self):
7045.1.1 by Jelmer Vernooij
Fix another 300 tests.
609
        left_revid = b'left-parent'
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
610
        basis_shape = Inventory(root_id=None)
6973.11.7 by Jelmer Vernooij
Fix more tests.
611
        self.add_dir(basis_shape, left_revid, b'root-id', None, '')
612
        self.add_link(basis_shape, left_revid, b'link-id', b'root-id', 'link',
7143.15.2 by Jelmer Vernooij
Run autopep8.
613
                      'left-target')
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
614
        # the right shape has content - file, link, subdir with a child,
615
        # that should all be discarded by the call.
7045.1.1 by Jelmer Vernooij
Fix another 300 tests.
616
        right_revid = b'right-parent'
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
617
        right_shape = Inventory(root_id=None)
6973.11.7 by Jelmer Vernooij
Fix more tests.
618
        self.add_dir(right_shape, left_revid, b'root-id', None, '')
619
        self.add_link(right_shape, right_revid, b'link-id', b'root-id', 'link',
7143.15.2 by Jelmer Vernooij
Run autopep8.
620
                      'some-target')
6973.11.7 by Jelmer Vernooij
Fix more tests.
621
        self.add_dir(right_shape, right_revid, b'subdir-id', b'root-id', 'dir')
622
        self.add_file(right_shape, right_revid, b'file-id', b'subdir-id', 'file',
7143.15.2 by Jelmer Vernooij
Run autopep8.
623
                      b'2' * 32, 24)
6973.11.7 by Jelmer Vernooij
Fix more tests.
624
        new_revid = b'new-parent'
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
625
        new_shape = Inventory(root_id=None)
626
        self.add_new_root(new_shape, left_revid, new_revid)
6973.11.7 by Jelmer Vernooij
Fix more tests.
627
        self.add_link(new_shape, new_revid, b'link-id', b'root-id', 'link',
7143.15.2 by Jelmer Vernooij
Run autopep8.
628
                      'new-target')
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
629
        self.assertTransitionFromBasisToShape(basis_shape, left_revid,
7143.15.2 by Jelmer Vernooij
Run autopep8.
630
                                              new_shape, new_revid, right_revid)
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
631
632
    def test_parent_id_changed(self):
2865.1.3 by Robert Collins
Review feedback.
633
        # test that when the only change to an entry is its parent id changing
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
634
        # that it is handled correctly (that is it keeps the same path)
6973.11.7 by Jelmer Vernooij
Fix more tests.
635
        old_revid = b'old-parent'
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
636
        basis_shape = Inventory(root_id=None)
6973.11.7 by Jelmer Vernooij
Fix more tests.
637
        self.add_dir(basis_shape, old_revid, b'root-id', None, '')
7143.15.2 by Jelmer Vernooij
Run autopep8.
638
        self.add_dir(basis_shape, old_revid,
639
                     b'orig-parent-id', b'root-id', 'dir')
640
        self.add_dir(basis_shape, old_revid, b'dir-id',
641
                     b'orig-parent-id', 'dir')
6973.11.7 by Jelmer Vernooij
Fix more tests.
642
        new_revid = b'new-parent'
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
643
        new_shape = Inventory(root_id=None)
644
        self.add_new_root(new_shape, old_revid, new_revid)
6973.11.7 by Jelmer Vernooij
Fix more tests.
645
        self.add_dir(new_shape, new_revid, b'new-parent-id', b'root-id', 'dir')
646
        self.add_dir(new_shape, new_revid, b'dir-id', b'new-parent-id', 'dir')
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
647
        self.assertTransitionFromBasisToShape(basis_shape, old_revid,
7143.15.2 by Jelmer Vernooij
Run autopep8.
648
                                              new_shape, new_revid)
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
649
650
    def test_name_changed(self):
2865.1.3 by Robert Collins
Review feedback.
651
        # test that when the only change to an entry is its name changing that
652
        # it is handled correctly (that is it keeps the same parent id)
6973.11.7 by Jelmer Vernooij
Fix more tests.
653
        old_revid = b'old-parent'
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
654
        basis_shape = Inventory(root_id=None)
6973.11.7 by Jelmer Vernooij
Fix more tests.
655
        self.add_dir(basis_shape, old_revid, b'root-id', None, '')
7143.15.2 by Jelmer Vernooij
Run autopep8.
656
        self.add_dir(basis_shape, old_revid,
657
                     b'parent-id', b'root-id', 'origdir')
6973.11.7 by Jelmer Vernooij
Fix more tests.
658
        self.add_dir(basis_shape, old_revid, b'dir-id', b'parent-id', 'olddir')
659
        new_revid = b'new-parent'
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
660
        new_shape = Inventory(root_id=None)
661
        self.add_new_root(new_shape, old_revid, new_revid)
6973.11.7 by Jelmer Vernooij
Fix more tests.
662
        self.add_dir(new_shape, new_revid, b'parent-id', b'root-id', 'newdir')
663
        self.add_dir(new_shape, new_revid, b'dir-id', b'parent-id', 'newdir')
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
664
        self.assertTransitionFromBasisToShape(basis_shape, old_revid,
7143.15.2 by Jelmer Vernooij
Run autopep8.
665
                                              new_shape, new_revid)
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
666
2929.2.2 by Robert Collins
Review feedback on dirstate update_basis_via_delta logic.
667
    def test_parent_child_swap(self):
668
        # test a A->A/B and A/B->A path swap.
6973.11.7 by Jelmer Vernooij
Fix more tests.
669
        old_revid = b'old-parent'
2929.2.2 by Robert Collins
Review feedback on dirstate update_basis_via_delta logic.
670
        basis_shape = Inventory(root_id=None)
6973.11.7 by Jelmer Vernooij
Fix more tests.
671
        self.add_dir(basis_shape, old_revid, b'root-id', None, '')
672
        self.add_dir(basis_shape, old_revid, b'dir-id-A', b'root-id', 'A')
673
        self.add_dir(basis_shape, old_revid, b'dir-id-B', b'dir-id-A', 'B')
7143.15.2 by Jelmer Vernooij
Run autopep8.
674
        self.add_link(basis_shape, old_revid,
675
                      b'link-id-C', b'dir-id-B', 'C', 'C')
6973.11.7 by Jelmer Vernooij
Fix more tests.
676
        new_revid = b'new-parent'
2929.2.2 by Robert Collins
Review feedback on dirstate update_basis_via_delta logic.
677
        new_shape = Inventory(root_id=None)
678
        self.add_new_root(new_shape, old_revid, new_revid)
6973.11.7 by Jelmer Vernooij
Fix more tests.
679
        self.add_dir(new_shape, new_revid, b'dir-id-B', b'root-id', 'A')
680
        self.add_dir(new_shape, new_revid, b'dir-id-A', b'dir-id-B', 'B')
7143.15.2 by Jelmer Vernooij
Run autopep8.
681
        self.add_link(new_shape, new_revid, b'link-id-C',
682
                      b'dir-id-A', 'C', 'C')
2929.2.2 by Robert Collins
Review feedback on dirstate update_basis_via_delta logic.
683
        self.assertTransitionFromBasisToShape(basis_shape, old_revid,
7143.15.2 by Jelmer Vernooij
Run autopep8.
684
                                              new_shape, new_revid)
2929.2.2 by Robert Collins
Review feedback on dirstate update_basis_via_delta logic.
685
3253.2.1 by John Arbash Meinel
Fix moving directories to root nodes.
686
    def test_parent_deleted_child_renamed(self):
687
        # test a A->None and A/B->A.
6973.11.7 by Jelmer Vernooij
Fix more tests.
688
        old_revid = b'old-parent'
3253.2.1 by John Arbash Meinel
Fix moving directories to root nodes.
689
        basis_shape = Inventory(root_id=None)
6973.11.7 by Jelmer Vernooij
Fix more tests.
690
        self.add_dir(basis_shape, old_revid, b'root-id', None, '')
691
        self.add_dir(basis_shape, old_revid, b'dir-id-A', b'root-id', 'A')
692
        self.add_dir(basis_shape, old_revid, b'dir-id-B', b'dir-id-A', 'B')
7143.15.2 by Jelmer Vernooij
Run autopep8.
693
        self.add_link(basis_shape, old_revid,
694
                      b'link-id-C', b'dir-id-B', 'C', 'C')
6973.11.7 by Jelmer Vernooij
Fix more tests.
695
        new_revid = b'new-parent'
3253.2.1 by John Arbash Meinel
Fix moving directories to root nodes.
696
        new_shape = Inventory(root_id=None)
697
        self.add_new_root(new_shape, old_revid, new_revid)
6973.11.7 by Jelmer Vernooij
Fix more tests.
698
        self.add_dir(new_shape, new_revid, b'dir-id-B', b'root-id', 'A')
7143.15.2 by Jelmer Vernooij
Run autopep8.
699
        self.add_link(new_shape, old_revid, b'link-id-C',
700
                      b'dir-id-B', 'C', 'C')
3253.2.1 by John Arbash Meinel
Fix moving directories to root nodes.
701
        self.assertTransitionFromBasisToShape(basis_shape, old_revid,
7143.15.2 by Jelmer Vernooij
Run autopep8.
702
                                              new_shape, new_revid)
3253.2.1 by John Arbash Meinel
Fix moving directories to root nodes.
703
704
    def test_dir_to_root(self):
705
        # test a A->''.
6973.11.7 by Jelmer Vernooij
Fix more tests.
706
        old_revid = b'old-parent'
3253.2.1 by John Arbash Meinel
Fix moving directories to root nodes.
707
        basis_shape = Inventory(root_id=None)
6973.11.7 by Jelmer Vernooij
Fix more tests.
708
        self.add_dir(basis_shape, old_revid, b'root-id', None, '')
709
        self.add_dir(basis_shape, old_revid, b'dir-id-A', b'root-id', 'A')
7143.15.2 by Jelmer Vernooij
Run autopep8.
710
        self.add_link(basis_shape, old_revid,
711
                      b'link-id-B', b'dir-id-A', 'B', 'B')
6973.11.7 by Jelmer Vernooij
Fix more tests.
712
        new_revid = b'new-parent'
3253.2.1 by John Arbash Meinel
Fix moving directories to root nodes.
713
        new_shape = Inventory(root_id=None)
6973.11.7 by Jelmer Vernooij
Fix more tests.
714
        self.add_dir(new_shape, new_revid, b'dir-id-A', None, '')
7143.15.2 by Jelmer Vernooij
Run autopep8.
715
        self.add_link(new_shape, old_revid, b'link-id-B',
716
                      b'dir-id-A', 'B', 'B')
3253.2.1 by John Arbash Meinel
Fix moving directories to root nodes.
717
        self.assertTransitionFromBasisToShape(basis_shape, old_revid,
7143.15.2 by Jelmer Vernooij
Run autopep8.
718
                                              new_shape, new_revid)
3253.2.1 by John Arbash Meinel
Fix moving directories to root nodes.
719
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
720
    def test_path_swap(self):
721
        # test a A->B and B->A path swap.
6973.11.7 by Jelmer Vernooij
Fix more tests.
722
        old_revid = b'old-parent'
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
723
        basis_shape = Inventory(root_id=None)
6973.11.7 by Jelmer Vernooij
Fix more tests.
724
        self.add_dir(basis_shape, old_revid, b'root-id', None, '')
725
        self.add_dir(basis_shape, old_revid, b'dir-id-A', b'root-id', 'A')
726
        self.add_dir(basis_shape, old_revid, b'dir-id-B', b'root-id', 'B')
7143.15.2 by Jelmer Vernooij
Run autopep8.
727
        self.add_link(basis_shape, old_revid,
728
                      b'link-id-C', b'root-id', 'C', 'C')
729
        self.add_link(basis_shape, old_revid,
730
                      b'link-id-D', b'root-id', 'D', 'D')
6973.11.7 by Jelmer Vernooij
Fix more tests.
731
        self.add_file(basis_shape, old_revid, b'file-id-E', b'root-id', 'E',
7143.15.2 by Jelmer Vernooij
Run autopep8.
732
                      b'1' * 32, 12)
6973.11.7 by Jelmer Vernooij
Fix more tests.
733
        self.add_file(basis_shape, old_revid, b'file-id-F', b'root-id', 'F',
7143.15.2 by Jelmer Vernooij
Run autopep8.
734
                      b'2' * 32, 24)
6973.11.7 by Jelmer Vernooij
Fix more tests.
735
        new_revid = b'new-parent'
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
736
        new_shape = Inventory(root_id=None)
737
        self.add_new_root(new_shape, old_revid, new_revid)
6973.11.7 by Jelmer Vernooij
Fix more tests.
738
        self.add_dir(new_shape, new_revid, b'dir-id-A', b'root-id', 'B')
739
        self.add_dir(new_shape, new_revid, b'dir-id-B', b'root-id', 'A')
740
        self.add_link(new_shape, new_revid, b'link-id-C', b'root-id', 'D', 'C')
741
        self.add_link(new_shape, new_revid, b'link-id-D', b'root-id', 'C', 'D')
742
        self.add_file(new_shape, new_revid, b'file-id-E', b'root-id', 'F',
7143.15.2 by Jelmer Vernooij
Run autopep8.
743
                      b'1' * 32, 12)
6973.11.7 by Jelmer Vernooij
Fix more tests.
744
        self.add_file(new_shape, new_revid, b'file-id-F', b'root-id', 'E',
7143.15.2 by Jelmer Vernooij
Run autopep8.
745
                      b'2' * 32, 24)
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
746
        self.assertTransitionFromBasisToShape(basis_shape, old_revid,
7143.15.2 by Jelmer Vernooij
Run autopep8.
747
                                              new_shape, new_revid)
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
748
749
    def test_adds(self):
750
        # test adding paths and dirs, including adding to a newly added dir.
6973.11.7 by Jelmer Vernooij
Fix more tests.
751
        old_revid = b'old-parent'
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
752
        basis_shape = Inventory(root_id=None)
753
        # with a root, so its a commit after the first.
6973.11.7 by Jelmer Vernooij
Fix more tests.
754
        self.add_dir(basis_shape, old_revid, b'root-id', None, '')
755
        new_revid = b'new-parent'
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
756
        new_shape = Inventory(root_id=None)
757
        self.add_new_root(new_shape, old_revid, new_revid)
6973.11.7 by Jelmer Vernooij
Fix more tests.
758
        self.add_dir(new_shape, new_revid, b'dir-id-A', b'root-id', 'A')
759
        self.add_link(new_shape, new_revid, b'link-id-B', b'root-id', 'B', 'C')
760
        self.add_file(new_shape, new_revid, b'file-id-C', b'root-id', 'C',
7143.15.2 by Jelmer Vernooij
Run autopep8.
761
                      b'1' * 32, 12)
6973.11.7 by Jelmer Vernooij
Fix more tests.
762
        self.add_file(new_shape, new_revid, b'file-id-D', b'dir-id-A', 'D',
7143.15.2 by Jelmer Vernooij
Run autopep8.
763
                      b'2' * 32, 24)
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
764
        self.assertTransitionFromBasisToShape(basis_shape, old_revid,
7143.15.2 by Jelmer Vernooij
Run autopep8.
765
                                              new_shape, new_revid)
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
766
767
    def test_removes(self):
768
        # test removing paths, including paths that are within other also
769
        # removed paths.
6973.11.7 by Jelmer Vernooij
Fix more tests.
770
        old_revid = b'old-parent'
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
771
        basis_shape = Inventory(root_id=None)
6973.11.7 by Jelmer Vernooij
Fix more tests.
772
        self.add_dir(basis_shape, old_revid, b'root-id', None, '')
773
        self.add_dir(basis_shape, old_revid, b'dir-id-A', b'root-id', 'A')
7143.15.2 by Jelmer Vernooij
Run autopep8.
774
        self.add_link(basis_shape, old_revid,
775
                      b'link-id-B', b'root-id', 'B', 'C')
6973.11.7 by Jelmer Vernooij
Fix more tests.
776
        self.add_file(basis_shape, old_revid, b'file-id-C', b'root-id', 'C',
7143.15.2 by Jelmer Vernooij
Run autopep8.
777
                      b'1' * 32, 12)
6973.11.7 by Jelmer Vernooij
Fix more tests.
778
        self.add_file(basis_shape, old_revid, b'file-id-D', b'dir-id-A', 'D',
7143.15.2 by Jelmer Vernooij
Run autopep8.
779
                      b'2' * 32, 24)
6973.11.7 by Jelmer Vernooij
Fix more tests.
780
        new_revid = b'new-parent'
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
781
        new_shape = Inventory(root_id=None)
782
        self.add_new_root(new_shape, old_revid, new_revid)
783
        self.assertTransitionFromBasisToShape(basis_shape, old_revid,
7143.15.2 by Jelmer Vernooij
Run autopep8.
784
                                              new_shape, new_revid)
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
785
786
    def test_move_to_added_dir(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
787
        old_revid = b'old-parent'
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
788
        basis_shape = Inventory(root_id=None)
6973.11.7 by Jelmer Vernooij
Fix more tests.
789
        self.add_dir(basis_shape, old_revid, b'root-id', None, '')
7143.15.2 by Jelmer Vernooij
Run autopep8.
790
        self.add_link(basis_shape, old_revid,
791
                      b'link-id-B', b'root-id', 'B', 'C')
6973.11.7 by Jelmer Vernooij
Fix more tests.
792
        new_revid = b'new-parent'
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
793
        new_shape = Inventory(root_id=None)
794
        self.add_new_root(new_shape, old_revid, new_revid)
6973.11.7 by Jelmer Vernooij
Fix more tests.
795
        self.add_dir(new_shape, new_revid, b'dir-id-A', b'root-id', 'A')
7143.15.2 by Jelmer Vernooij
Run autopep8.
796
        self.add_link(new_shape, new_revid, b'link-id-B',
797
                      b'dir-id-A', 'B', 'C')
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
798
        self.assertTransitionFromBasisToShape(basis_shape, old_revid,
7143.15.2 by Jelmer Vernooij
Run autopep8.
799
                                              new_shape, new_revid)
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
800
801
    def test_move_from_removed_dir(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
802
        old_revid = b'old-parent'
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
803
        basis_shape = Inventory(root_id=None)
6973.11.7 by Jelmer Vernooij
Fix more tests.
804
        self.add_dir(basis_shape, old_revid, b'root-id', None, '')
805
        self.add_dir(basis_shape, old_revid, b'dir-id-A', b'root-id', 'A')
7143.15.2 by Jelmer Vernooij
Run autopep8.
806
        self.add_link(basis_shape, old_revid,
807
                      b'link-id-B', b'dir-id-A', 'B', 'C')
6973.11.7 by Jelmer Vernooij
Fix more tests.
808
        new_revid = b'new-parent'
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
809
        new_shape = Inventory(root_id=None)
810
        self.add_new_root(new_shape, old_revid, new_revid)
6973.11.7 by Jelmer Vernooij
Fix more tests.
811
        self.add_link(new_shape, new_revid, b'link-id-B', b'root-id', 'B', 'C')
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
812
        self.assertTransitionFromBasisToShape(basis_shape, old_revid,
7143.15.2 by Jelmer Vernooij
Run autopep8.
813
                                              new_shape, new_revid)
2929.2.1 by Robert Collins
* Commit updates the state of the working tree via a delta rather than
814
815
    def test_move_moves_children_recursively(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
816
        old_revid = b'old-parent'
2929.2.1 by Robert Collins
* Commit updates the state of the working tree via a delta rather than
817
        basis_shape = Inventory(root_id=None)
6973.11.7 by Jelmer Vernooij
Fix more tests.
818
        self.add_dir(basis_shape, old_revid, b'root-id', None, '')
819
        self.add_dir(basis_shape, old_revid, b'dir-id-A', b'root-id', 'A')
820
        self.add_dir(basis_shape, old_revid, b'dir-id-B', b'dir-id-A', 'B')
7143.15.2 by Jelmer Vernooij
Run autopep8.
821
        self.add_link(basis_shape, old_revid,
822
                      b'link-id-C', b'dir-id-B', 'C', 'D')
6973.11.7 by Jelmer Vernooij
Fix more tests.
823
        new_revid = b'new-parent'
2929.2.1 by Robert Collins
* Commit updates the state of the working tree via a delta rather than
824
        new_shape = Inventory(root_id=None)
825
        self.add_new_root(new_shape, old_revid, new_revid)
826
        # the moved path:
6973.11.7 by Jelmer Vernooij
Fix more tests.
827
        self.add_dir(new_shape, new_revid, b'dir-id-A', b'root-id', 'B')
2929.2.1 by Robert Collins
* Commit updates the state of the working tree via a delta rather than
828
        # unmoved children.
6973.11.7 by Jelmer Vernooij
Fix more tests.
829
        self.add_dir(new_shape, old_revid, b'dir-id-B', b'dir-id-A', 'B')
7143.15.2 by Jelmer Vernooij
Run autopep8.
830
        self.add_link(new_shape, old_revid, b'link-id-C',
831
                      b'dir-id-B', 'C', 'D')
2929.2.1 by Robert Collins
* Commit updates the state of the working tree via a delta rather than
832
        self.assertTransitionFromBasisToShape(basis_shape, old_revid,
7143.15.2 by Jelmer Vernooij
Run autopep8.
833
                                              new_shape, new_revid)
6015.45.2 by Brian de Alwis, John Arbash Meinel
Backport the fix for bug #855155 to bzr-2.4
834
835
    def test_add_files_to_empty_directory(self):
6973.11.7 by Jelmer Vernooij
Fix more tests.
836
        old_revid = b'old-parent'
6015.45.2 by Brian de Alwis, John Arbash Meinel
Backport the fix for bug #855155 to bzr-2.4
837
        basis_shape = Inventory(root_id=None)
6973.11.7 by Jelmer Vernooij
Fix more tests.
838
        self.add_dir(basis_shape, old_revid, b'root-id', None, '')
839
        self.add_dir(basis_shape, old_revid, b'dir-id-A', b'root-id', 'A')
840
        new_revid = b'new-parent'
6015.45.2 by Brian de Alwis, John Arbash Meinel
Backport the fix for bug #855155 to bzr-2.4
841
        new_shape = Inventory(root_id=None)
842
        self.add_new_root(new_shape, old_revid, new_revid)
6973.11.7 by Jelmer Vernooij
Fix more tests.
843
        self.add_dir(new_shape, old_revid, b'dir-id-A', b'root-id', 'A')
844
        self.add_file(new_shape, new_revid, b'file-id-B', b'dir-id-A', 'B',
7143.15.2 by Jelmer Vernooij
Run autopep8.
845
                      b'1' * 32, 24)
6015.45.2 by Brian de Alwis, John Arbash Meinel
Backport the fix for bug #855155 to bzr-2.4
846
        self.assertTransitionFromBasisToShape(basis_shape, old_revid,
7143.15.2 by Jelmer Vernooij
Run autopep8.
847
                                              new_shape, new_revid, set_current_inventory=False)