~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_branchbuilder.py

(spiv) Add a 'flush' action to BranchBuilder.build_snapshot. (Andrew
 Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
247
247
                              (u'dir', 'dir-id', 'directory'),
248
248
                              (u'dir/a', 'a-id', 'file')], rev_tree)
249
249
 
 
250
    def test_rename_out_of_unversioned_subdir(self):
 
251
        builder = self.build_a_rev()
 
252
        builder.build_snapshot('B-id', None,
 
253
            [('add', ('dir', 'dir-id', 'directory', None)),
 
254
             ('rename', ('a', 'dir/a'))])
 
255
        builder.build_snapshot('C-id', None,
 
256
            [('rename', ('dir/a', 'a')),
 
257
             ('unversion', 'dir-id')])
 
258
        rev_tree = builder.get_branch().repository.revision_tree('C-id')
 
259
        self.assertTreeShape([(u'', 'a-root-id', 'directory'),
 
260
                              (u'a', 'a-id', 'file')], rev_tree)
 
261
 
250
262
    def test_set_parent(self):
251
263
        builder = self.build_a_rev()
252
264
        builder.start_series()
364
376
        self.addCleanup(b.unlock)
365
377
        self.assertEqual(('ghost',),
366
378
            b.repository.get_graph().get_parent_map(['tip'])['tip'])
 
379
 
 
380
    def test_unversion_root_add_new_root(self):
 
381
        builder = BranchBuilder(self.get_transport().clone('foo'))
 
382
        builder.start_series()
 
383
        builder.build_snapshot('rev-1', None,
 
384
            [('add', ('', 'TREE_ROOT', 'directory', ''))])
 
385
        builder.build_snapshot('rev-2', None,
 
386
            [('unversion', 'TREE_ROOT'),
 
387
             ('add', ('', 'my-root', 'directory', ''))])
 
388
        builder.finish_series()
 
389
        rev_tree = builder.get_branch().repository.revision_tree('rev-2')
 
390
        self.assertTreeShape([(u'', 'my-root', 'directory')], rev_tree)
 
391
 
 
392
    def test_empty_flush(self):
 
393
        """A flush with no actions before it is a no-op."""
 
394
        builder = BranchBuilder(self.get_transport().clone('foo'))
 
395
        builder.start_series()
 
396
        builder.build_snapshot('rev-1', None,
 
397
            [('add', ('', 'TREE_ROOT', 'directory', ''))])
 
398
        builder.build_snapshot('rev-2', None, [('flush', None)])
 
399
        builder.finish_series()
 
400
        rev_tree = builder.get_branch().repository.revision_tree('rev-2')
 
401
        self.assertTreeShape([(u'', 'TREE_ROOT', 'directory')], rev_tree)
 
402
 
 
403
    def test_kind_change(self):
 
404
        """It's possible to change the kind of an entry in a single snapshot
 
405
        with a bit of help from the 'flush' action.
 
406
        """
 
407
        builder = BranchBuilder(self.get_transport().clone('foo'))
 
408
        builder.start_series()
 
409
        builder.build_snapshot('A-id', None,
 
410
            [('add', (u'', 'a-root-id', 'directory', None)),
 
411
             ('add', (u'a', 'a-id', 'file', 'content\n'))])
 
412
        builder.build_snapshot('B-id', None,
 
413
            [('unversion', 'a-id'),
 
414
             ('flush', None),
 
415
             ('add', (u'a', 'a-id', 'directory', None))])
 
416
        builder.finish_series()
 
417
        rev_tree = builder.get_branch().repository.revision_tree('B-id')
 
418
        self.assertTreeShape(
 
419
            [(u'', 'a-root-id', 'directory'), (u'a', 'a-id', 'directory')],
 
420
            rev_tree)
 
421
 
 
422
    def test_pivot_root(self):
 
423
        """It's possible (albeit awkward) to move an existing dir to the root
 
424
        in a single snapshot by using unversion then flush then add.
 
425
        """
 
426
        builder = BranchBuilder(self.get_transport().clone('foo'))
 
427
        builder.start_series()
 
428
        builder.build_snapshot('A-id', None,
 
429
            [('add', (u'', 'orig-root', 'directory', None)),
 
430
             ('add', (u'dir', 'dir-id', 'directory', None))])
 
431
        builder.build_snapshot('B-id', None,
 
432
            [('unversion', 'orig-root'),  # implicitly unversions all children
 
433
             ('flush', None),
 
434
             ('add', (u'', 'dir-id', 'directory', None))])
 
435
        builder.finish_series()
 
436
        rev_tree = builder.get_branch().repository.revision_tree('B-id')
 
437
        self.assertTreeShape([(u'', 'dir-id', 'directory')], rev_tree)
 
438