/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_branchbuilder.py

  • Committer: Jelmer Vernooij
  • Date: 2020-03-22 01:35:14 UTC
  • mfrom: (7490.7.6 work)
  • mto: This revision was merged to the branch mainline in revision 7499.
  • Revision ID: jelmer@jelmer.uk-20200322013514-7vw1ntwho04rcuj3
merge lp:brz/3.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2007-2011 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
"""Tests for the BranchBuilder class."""
 
18
 
 
19
from .. import (
 
20
    branch as _mod_branch,
 
21
    revision as _mod_revision,
 
22
    tests,
 
23
    )
 
24
from ..bzr import (
 
25
    branch as _mod_bzrbranch,
 
26
    )
 
27
from ..branchbuilder import BranchBuilder
 
28
 
 
29
 
 
30
class TestBranchBuilder(tests.TestCaseWithMemoryTransport):
 
31
 
 
32
    def test_create(self):
 
33
        """Test the constructor api."""
 
34
        builder = BranchBuilder(self.get_transport().clone('foo'))
 
35
        # we dont care if the branch has been built or not at this point.
 
36
 
 
37
    def test_get_branch(self):
 
38
        """get_branch returns the created branch."""
 
39
        builder = BranchBuilder(self.get_transport().clone('foo'))
 
40
        branch = builder.get_branch()
 
41
        self.assertIsInstance(branch, _mod_branch.Branch)
 
42
        self.assertEqual(self.get_transport().clone('foo').base,
 
43
                         branch.base)
 
44
        self.assertEqual(
 
45
            (0, _mod_revision.NULL_REVISION),
 
46
            branch.last_revision_info())
 
47
 
 
48
    def test_format(self):
 
49
        """Making a BranchBuilder with a format option sets the branch type."""
 
50
        builder = BranchBuilder(self.get_transport(), format='dirstate-tags')
 
51
        branch = builder.get_branch()
 
52
        self.assertIsInstance(branch, _mod_bzrbranch.BzrBranch6)
 
53
 
 
54
    def test_build_one_commit(self):
 
55
        """doing build_commit causes a commit to happen."""
 
56
        builder = BranchBuilder(self.get_transport().clone('foo'))
 
57
        rev_id = builder.build_commit()
 
58
        branch = builder.get_branch()
 
59
        self.assertEqual((1, rev_id), branch.last_revision_info())
 
60
        self.assertEqual(
 
61
            'commit 1',
 
62
            branch.repository.get_revision(branch.last_revision()).message)
 
63
 
 
64
    def test_build_commit_timestamp(self):
 
65
        """You can set a date when committing."""
 
66
        builder = self.make_branch_builder('foo')
 
67
        rev_id = builder.build_commit(timestamp=1236043340)
 
68
        branch = builder.get_branch()
 
69
        self.assertEqual((1, rev_id), branch.last_revision_info())
 
70
        rev = branch.repository.get_revision(branch.last_revision())
 
71
        self.assertEqual(
 
72
            'commit 1',
 
73
            rev.message)
 
74
        self.assertEqual(
 
75
            1236043340,
 
76
            int(rev.timestamp))
 
77
 
 
78
    def test_build_two_commits(self):
 
79
        """The second commit has the right parents and message."""
 
80
        builder = BranchBuilder(self.get_transport().clone('foo'))
 
81
        rev_id1 = builder.build_commit()
 
82
        rev_id2 = builder.build_commit()
 
83
        branch = builder.get_branch()
 
84
        self.assertEqual((2, rev_id2), branch.last_revision_info())
 
85
        self.assertEqual(
 
86
            'commit 2',
 
87
            branch.repository.get_revision(branch.last_revision()).message)
 
88
        self.assertEqual(
 
89
            [rev_id1],
 
90
            branch.repository.get_revision(branch.last_revision()).parent_ids)
 
91
 
 
92
    def test_build_commit_parent_ids(self):
 
93
        """build_commit() takes a parent_ids argument."""
 
94
        builder = BranchBuilder(self.get_transport().clone('foo'))
 
95
        rev_id1 = builder.build_commit(
 
96
            parent_ids=[b"ghost"], allow_leftmost_as_ghost=True)
 
97
        rev_id2 = builder.build_commit(parent_ids=[])
 
98
        branch = builder.get_branch()
 
99
        self.assertEqual((1, rev_id2), branch.last_revision_info())
 
100
        self.assertEqual(
 
101
            [b"ghost"],
 
102
            branch.repository.get_revision(rev_id1).parent_ids)
 
103
 
 
104
 
 
105
class TestBranchBuilderBuildSnapshot(tests.TestCaseWithMemoryTransport):
 
106
 
 
107
    def assertTreeShape(self, expected_shape, tree):
 
108
        """Check that the tree shape matches expectations."""
 
109
        tree.lock_read()
 
110
        try:
 
111
            entries = [(path, ie.file_id, ie.kind)
 
112
                       for path, ie in tree.iter_entries_by_dir()]
 
113
        finally:
 
114
            tree.unlock()
 
115
        self.assertEqual(expected_shape, entries)
 
116
 
 
117
    def build_a_rev(self):
 
118
        builder = BranchBuilder(self.get_transport().clone('foo'))
 
119
        rev_id1 = builder.build_snapshot(None,
 
120
                                         [('add', ('', b'a-root-id', 'directory', None)),
 
121
                                          ('add', ('a', b'a-id', 'file', b'contents'))],
 
122
                                         revision_id=b'A-id')
 
123
        self.assertEqual(b'A-id', rev_id1)
 
124
        return builder
 
125
 
 
126
    def test_add_one_file(self):
 
127
        builder = self.build_a_rev()
 
128
        branch = builder.get_branch()
 
129
        self.assertEqual((1, b'A-id'), branch.last_revision_info())
 
130
        rev_tree = branch.repository.revision_tree(b'A-id')
 
131
        rev_tree.lock_read()
 
132
        self.addCleanup(rev_tree.unlock)
 
133
        self.assertTreeShape([(u'', b'a-root-id', 'directory'),
 
134
                              (u'a', b'a-id', 'file')], rev_tree)
 
135
        self.assertEqual(b'contents', rev_tree.get_file_text('a'))
 
136
 
 
137
    def test_add_second_file(self):
 
138
        builder = self.build_a_rev()
 
139
        rev_id2 = builder.build_snapshot(None,
 
140
                                         [('add', ('b', b'b-id', 'file', b'content_b'))],
 
141
                                         revision_id=b'B-id')
 
142
        self.assertEqual(b'B-id', rev_id2)
 
143
        branch = builder.get_branch()
 
144
        self.assertEqual((2, rev_id2), branch.last_revision_info())
 
145
        rev_tree = branch.repository.revision_tree(rev_id2)
 
146
        rev_tree.lock_read()
 
147
        self.addCleanup(rev_tree.unlock)
 
148
        self.assertTreeShape([(u'', b'a-root-id', 'directory'),
 
149
                              (u'a', b'a-id', 'file'),
 
150
                              (u'b', b'b-id', 'file')], rev_tree)
 
151
        self.assertEqual(b'content_b', rev_tree.get_file_text('b'))
 
152
 
 
153
    def test_add_empty_dir(self):
 
154
        builder = self.build_a_rev()
 
155
        rev_id2 = builder.build_snapshot(None,
 
156
                                         [('add', ('b', b'b-id', 'directory', None))],
 
157
                                         revision_id=b'B-id')
 
158
        rev_tree = builder.get_branch().repository.revision_tree(b'B-id')
 
159
        self.assertTreeShape([(u'', b'a-root-id', 'directory'),
 
160
                              (u'a', b'a-id', 'file'),
 
161
                              (u'b', b'b-id', 'directory'),
 
162
                              ], rev_tree)
 
163
 
 
164
    def test_commit_timestamp(self):
 
165
        builder = self.make_branch_builder('foo')
 
166
        rev_id = builder.build_snapshot(None,
 
167
                                        [('add', (u'', None, 'directory', None))],
 
168
                                        timestamp=1234567890)
 
169
        rev = builder.get_branch().repository.get_revision(rev_id)
 
170
        self.assertEqual(
 
171
            1234567890,
 
172
            int(rev.timestamp))
 
173
 
 
174
    def test_commit_message_default(self):
 
175
        builder = BranchBuilder(self.get_transport().clone('foo'))
 
176
        rev_id = builder.build_snapshot(None,
 
177
                                        [('add', (u'', None, 'directory', None))])
 
178
        branch = builder.get_branch()
 
179
        rev = branch.repository.get_revision(rev_id)
 
180
        self.assertEqual(u'commit 1', rev.message)
 
181
 
 
182
    def test_commit_message_supplied(self):
 
183
        builder = BranchBuilder(self.get_transport().clone('foo'))
 
184
        rev_id = builder.build_snapshot(None,
 
185
                                        [('add', (u'', None, 'directory', None))],
 
186
                                        message=u'Foo')
 
187
        branch = builder.get_branch()
 
188
        rev = branch.repository.get_revision(rev_id)
 
189
        self.assertEqual(u'Foo', rev.message)
 
190
 
 
191
    def test_commit_message_callback(self):
 
192
        builder = BranchBuilder(self.get_transport().clone('foo'))
 
193
        rev_id = builder.build_snapshot(None,
 
194
                                        [('add', (u'', None, 'directory', None))],
 
195
                                        message_callback=lambda x: u'Foo')
 
196
        branch = builder.get_branch()
 
197
        rev = branch.repository.get_revision(rev_id)
 
198
        self.assertEqual(u'Foo', rev.message)
 
199
 
 
200
    def test_modify_file(self):
 
201
        builder = self.build_a_rev()
 
202
        rev_id2 = builder.build_snapshot(None,
 
203
                                         [('modify', ('a', b'new\ncontent\n'))],
 
204
                                         revision_id=b'B-id')
 
205
        self.assertEqual(b'B-id', rev_id2)
 
206
        branch = builder.get_branch()
 
207
        rev_tree = branch.repository.revision_tree(rev_id2)
 
208
        rev_tree.lock_read()
 
209
        self.addCleanup(rev_tree.unlock)
 
210
        self.assertEqual(b'new\ncontent\n',
 
211
                         rev_tree.get_file_text('a'))
 
212
 
 
213
    def test_delete_file(self):
 
214
        builder = self.build_a_rev()
 
215
        rev_id2 = builder.build_snapshot(None,
 
216
                                         [('unversion', 'a')], revision_id=b'B-id')
 
217
        self.assertEqual(b'B-id', rev_id2)
 
218
        branch = builder.get_branch()
 
219
        rev_tree = branch.repository.revision_tree(rev_id2)
 
220
        rev_tree.lock_read()
 
221
        self.addCleanup(rev_tree.unlock)
 
222
        self.assertTreeShape([(u'', b'a-root-id', 'directory')], rev_tree)
 
223
 
 
224
    def test_delete_directory(self):
 
225
        builder = self.build_a_rev()
 
226
        rev_id2 = builder.build_snapshot(None,
 
227
                                         [('add', ('b', b'b-id', 'directory', None)),
 
228
                                          ('add', ('b/c', b'c-id', 'file', b'foo\n')),
 
229
                                             ('add', ('b/d', b'd-id',
 
230
                                                      'directory', None)),
 
231
                                             ('add', ('b/d/e', b'e-id',
 
232
                                                      'file', b'eff\n')),
 
233
                                          ], revision_id=b'B-id')
 
234
        rev_tree = builder.get_branch().repository.revision_tree(b'B-id')
 
235
        self.assertTreeShape([(u'', b'a-root-id', 'directory'),
 
236
                              (u'a', b'a-id', 'file'),
 
237
                              (u'b', b'b-id', 'directory'),
 
238
                              (u'b/c', b'c-id', 'file'),
 
239
                              (u'b/d', b'd-id', 'directory'),
 
240
                              (u'b/d/e', b'e-id', 'file')], rev_tree)
 
241
        # Removing a directory removes all child dirs
 
242
        builder.build_snapshot(
 
243
            None, [('unversion', 'b')],
 
244
            revision_id=b'C-id')
 
245
        rev_tree = builder.get_branch().repository.revision_tree(b'C-id')
 
246
        self.assertTreeShape([(u'', b'a-root-id', 'directory'),
 
247
                              (u'a', b'a-id', 'file'),
 
248
                              ], rev_tree)
 
249
 
 
250
    def test_unknown_action(self):
 
251
        builder = self.build_a_rev()
 
252
        e = self.assertRaises(ValueError,
 
253
                              builder.build_snapshot, None, [
 
254
                                  ('weirdo', ('foo',))],
 
255
                              revision_id=b'B-id')
 
256
        self.assertEqual('Unknown build action: "weirdo"', str(e))
 
257
 
 
258
    def test_rename(self):
 
259
        builder = self.build_a_rev()
 
260
        builder.build_snapshot(None,
 
261
                               [('rename', ('a', 'b'))], revision_id=b'B-id')
 
262
        rev_tree = builder.get_branch().repository.revision_tree(b'B-id')
 
263
        self.assertTreeShape([(u'', b'a-root-id', 'directory'),
 
264
                              (u'b', b'a-id', 'file')], rev_tree)
 
265
 
 
266
    def test_rename_into_subdir(self):
 
267
        builder = self.build_a_rev()
 
268
        builder.build_snapshot(None,
 
269
                               [('add', ('dir', b'dir-id', 'directory', None)),
 
270
                                ('rename', ('a', 'dir/a'))], revision_id=b'B-id')
 
271
        rev_tree = builder.get_branch().repository.revision_tree(b'B-id')
 
272
        self.assertTreeShape([(u'', b'a-root-id', 'directory'),
 
273
                              (u'dir', b'dir-id', 'directory'),
 
274
                              (u'dir/a', b'a-id', 'file')], rev_tree)
 
275
 
 
276
    def test_rename_out_of_unversioned_subdir(self):
 
277
        builder = self.build_a_rev()
 
278
        builder.build_snapshot(None,
 
279
                               [('add', ('dir', b'dir-id', 'directory', None)),
 
280
                                ('rename', ('a', 'dir/a'))],
 
281
                               revision_id=b'B-id')
 
282
        builder.build_snapshot(None,
 
283
                               [('rename', ('dir/a', 'a')),
 
284
                                ('unversion', 'dir')], revision_id=b'C-id')
 
285
        rev_tree = builder.get_branch().repository.revision_tree(b'C-id')
 
286
        self.assertTreeShape([(u'', b'a-root-id', 'directory'),
 
287
                              (u'a', b'a-id', 'file')], rev_tree)
 
288
 
 
289
    def test_set_parent(self):
 
290
        builder = self.build_a_rev()
 
291
        builder.start_series()
 
292
        self.addCleanup(builder.finish_series)
 
293
        builder.build_snapshot([b'A-id'],
 
294
                               [('modify', ('a', b'new\ncontent\n'))],
 
295
                               revision_id=b'B-id')
 
296
        builder.build_snapshot([b'A-id'],
 
297
                               [('add', ('c', b'c-id', 'file', b'alt\ncontent\n'))],
 
298
                               revision_id=b'C-id')
 
299
        # We should now have a graph:
 
300
        #   A
 
301
        #   |\
 
302
        #   C B
 
303
        # And not A => B => C
 
304
        repo = builder.get_branch().repository
 
305
        self.assertEqual({b'B-id': (b'A-id',), b'C-id': (b'A-id',)},
 
306
                         repo.get_parent_map([b'B-id', b'C-id']))
 
307
        b_tree = repo.revision_tree(b'B-id')
 
308
        self.assertTreeShape([(u'', b'a-root-id', 'directory'),
 
309
                              (u'a', b'a-id', 'file'),
 
310
                              ], b_tree)
 
311
        self.assertEqual(b'new\ncontent\n', b_tree.get_file_text('a'))
 
312
 
 
313
        # We should still be using the content from A in C, not from B
 
314
        c_tree = repo.revision_tree(b'C-id')
 
315
        self.assertTreeShape([(u'', b'a-root-id', 'directory'),
 
316
                              (u'a', b'a-id', 'file'),
 
317
                              (u'c', b'c-id', 'file'),
 
318
                              ], c_tree)
 
319
        self.assertEqual(b'contents', c_tree.get_file_text('a'))
 
320
        self.assertEqual(b'alt\ncontent\n', c_tree.get_file_text('c'))
 
321
 
 
322
    def test_set_merge_parent(self):
 
323
        builder = self.build_a_rev()
 
324
        builder.start_series()
 
325
        self.addCleanup(builder.finish_series)
 
326
        builder.build_snapshot([b'A-id'],
 
327
                               [('add', ('b', b'b-id', 'file', b'b\ncontent\n'))],
 
328
                               revision_id=b'B-id')
 
329
        builder.build_snapshot([b'A-id'],
 
330
                               [('add', ('c', b'c-id', 'file', b'alt\ncontent\n'))],
 
331
                               revision_id=b'C-id')
 
332
        builder.build_snapshot([b'B-id', b'C-id'], [], revision_id=b'D-id')
 
333
        repo = builder.get_branch().repository
 
334
        self.assertEqual({b'B-id': (b'A-id',), b'C-id': (b'A-id',),
 
335
                          b'D-id': (b'B-id', b'C-id')},
 
336
                         repo.get_parent_map([b'B-id', b'C-id', b'D-id']))
 
337
        d_tree = repo.revision_tree(b'D-id')
 
338
        # Note: by default a merge node does *not* pull in the changes from the
 
339
        #       merged tree, you have to supply it yourself.
 
340
        self.assertTreeShape([(u'', b'a-root-id', 'directory'),
 
341
                              (u'a', b'a-id', 'file'),
 
342
                              (u'b', b'b-id', 'file'),
 
343
                              ], d_tree)
 
344
 
 
345
    def test_set_merge_parent_and_contents(self):
 
346
        builder = self.build_a_rev()
 
347
        builder.start_series()
 
348
        self.addCleanup(builder.finish_series)
 
349
        builder.build_snapshot([b'A-id'],
 
350
                               [('add', ('b', b'b-id', 'file', b'b\ncontent\n'))],
 
351
                               revision_id=b'B-id')
 
352
        builder.build_snapshot([b'A-id'],
 
353
                               [('add', ('c', b'c-id', 'file', b'alt\ncontent\n'))],
 
354
                               revision_id=b'C-id')
 
355
        builder.build_snapshot([b'B-id', b'C-id'],
 
356
                               [('add', ('c', b'c-id', 'file', b'alt\ncontent\n'))],
 
357
                               revision_id=b'D-id')
 
358
        repo = builder.get_branch().repository
 
359
        self.assertEqual({b'B-id': (b'A-id',), b'C-id': (b'A-id',),
 
360
                          b'D-id': (b'B-id', b'C-id')},
 
361
                         repo.get_parent_map([b'B-id', b'C-id', b'D-id']))
 
362
        d_tree = repo.revision_tree(b'D-id')
 
363
        self.assertTreeShape([(u'', b'a-root-id', 'directory'),
 
364
                              (u'a', b'a-id', 'file'),
 
365
                              (u'b', b'b-id', 'file'),
 
366
                              (u'c', b'c-id', 'file'),
 
367
                              ], d_tree)
 
368
        # Because we copied the exact text into *this* tree, the 'c' file
 
369
        # should look like it was not modified in the merge
 
370
        self.assertEqual(b'C-id', d_tree.get_file_revision('c'))
 
371
 
 
372
    def test_set_parent_to_null(self):
 
373
        builder = self.build_a_rev()
 
374
        builder.start_series()
 
375
        self.addCleanup(builder.finish_series)
 
376
        builder.build_snapshot([],
 
377
                               [('add', ('', None, 'directory', None))],
 
378
                               revision_id=b'B-id')
 
379
        # We should now have a graph:
 
380
        #   A B
 
381
        # And not A => B
 
382
        repo = builder.get_branch().repository
 
383
        self.assertEqual({b'A-id': (_mod_revision.NULL_REVISION,),
 
384
                          b'B-id': (_mod_revision.NULL_REVISION,), },
 
385
                         repo.get_parent_map([b'A-id', b'B-id']))
 
386
 
 
387
    def test_start_finish_series(self):
 
388
        builder = BranchBuilder(self.get_transport().clone('foo'))
 
389
        builder.start_series()
 
390
        try:
 
391
            self.assertIsNot(None, builder._tree)
 
392
            self.assertEqual('w', builder._tree._lock_mode)
 
393
            self.assertTrue(builder._branch.is_locked())
 
394
        finally:
 
395
            builder.finish_series()
 
396
        self.assertIs(None, builder._tree)
 
397
        self.assertFalse(builder._branch.is_locked())
 
398
 
 
399
    def test_ghost_mainline_history(self):
 
400
        builder = BranchBuilder(self.get_transport().clone('foo'))
 
401
        builder.start_series()
 
402
        try:
 
403
            builder.build_snapshot([b'ghost'],
 
404
                                   [('add', ('', b'ROOT_ID', 'directory', ''))],
 
405
                                   allow_leftmost_as_ghost=True, revision_id=b'tip')
 
406
        finally:
 
407
            builder.finish_series()
 
408
        b = builder.get_branch()
 
409
        b.lock_read()
 
410
        self.addCleanup(b.unlock)
 
411
        self.assertEqual((b'ghost',),
 
412
                         b.repository.get_graph().get_parent_map([b'tip'])[b'tip'])
 
413
 
 
414
    def test_unversion_root_add_new_root(self):
 
415
        builder = BranchBuilder(self.get_transport().clone('foo'))
 
416
        builder.start_series()
 
417
        builder.build_snapshot(None,
 
418
                               [('add', ('', b'TREE_ROOT', 'directory', ''))],
 
419
                               revision_id=b'rev-1')
 
420
        builder.build_snapshot(None,
 
421
                               [('unversion', ''),
 
422
                                ('add', ('', b'my-root', 'directory', ''))],
 
423
                               revision_id=b'rev-2')
 
424
        builder.finish_series()
 
425
        rev_tree = builder.get_branch().repository.revision_tree(b'rev-2')
 
426
        self.assertTreeShape([(u'', b'my-root', 'directory')], rev_tree)
 
427
 
 
428
    def test_empty_flush(self):
 
429
        """A flush with no actions before it is a no-op."""
 
430
        builder = BranchBuilder(self.get_transport().clone('foo'))
 
431
        builder.start_series()
 
432
        builder.build_snapshot(None,
 
433
                               [('add', ('', b'TREE_ROOT', 'directory', ''))],
 
434
                               revision_id=b'rev-1')
 
435
        builder.build_snapshot(None, [('flush', None)], revision_id=b'rev-2')
 
436
        builder.finish_series()
 
437
        rev_tree = builder.get_branch().repository.revision_tree(b'rev-2')
 
438
        self.assertTreeShape([(u'', b'TREE_ROOT', 'directory')], rev_tree)
 
439
 
 
440
    def test_kind_change(self):
 
441
        """It's possible to change the kind of an entry in a single snapshot
 
442
        with a bit of help from the 'flush' action.
 
443
        """
 
444
        builder = BranchBuilder(self.get_transport().clone('foo'))
 
445
        builder.start_series()
 
446
        builder.build_snapshot(None,
 
447
                               [('add', (u'', b'a-root-id', 'directory', None)),
 
448
                                ('add', (u'a', b'a-id', 'file', b'content\n'))],
 
449
                               revision_id=b'A-id')
 
450
        builder.build_snapshot(None,
 
451
                               [('unversion', 'a'),
 
452
                                ('flush', None),
 
453
                                   ('add', (u'a', b'a-id', 'directory', None))],
 
454
                               revision_id=b'B-id')
 
455
        builder.finish_series()
 
456
        rev_tree = builder.get_branch().repository.revision_tree(b'B-id')
 
457
        self.assertTreeShape(
 
458
            [(u'', b'a-root-id', 'directory'), (u'a', b'a-id', 'directory')],
 
459
            rev_tree)
 
460
 
 
461
    def test_pivot_root(self):
 
462
        """It's possible (albeit awkward) to move an existing dir to the root
 
463
        in a single snapshot by using unversion then flush then add.
 
464
        """
 
465
        builder = BranchBuilder(self.get_transport().clone('foo'))
 
466
        builder.start_series()
 
467
        builder.build_snapshot(None,
 
468
                               [('add', (u'', b'orig-root', 'directory', None)),
 
469
                                ('add', (u'dir', b'dir-id', 'directory', None))],
 
470
                               revision_id=b'A-id')
 
471
        builder.build_snapshot(None,
 
472
                               [('unversion', ''),  # implicitly unversions all children
 
473
                                ('flush', None),
 
474
                                   ('add', (u'', b'dir-id', 'directory', None))],
 
475
                               revision_id=b'B-id')
 
476
        builder.finish_series()
 
477
        rev_tree = builder.get_branch().repository.revision_tree(b'B-id')
 
478
        self.assertTreeShape([(u'', b'dir-id', 'directory')], rev_tree)