/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: 2017-06-10 21:59:15 UTC
  • mto: This revision was merged to the branch mainline in revision 6690.
  • Revision ID: jelmer@jelmer.uk-20170610215915-zcpu0in3r1irx3ml
Move serializer to bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2009 Canonical Ltd
 
1
# Copyright (C) 2007-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
16
16
 
17
17
"""Tests for the BranchBuilder class."""
18
18
 
19
 
from bzrlib import (
 
19
from .. import (
20
20
    branch as _mod_branch,
21
 
    errors,
22
21
    revision as _mod_revision,
23
22
    tests,
24
23
    )
25
 
from bzrlib.branchbuilder import BranchBuilder
 
24
from ..bzr import (
 
25
    branch as _mod_bzrbranch,
 
26
    )
 
27
from ..branchbuilder import BranchBuilder
26
28
 
27
29
 
28
30
class TestBranchBuilder(tests.TestCaseWithMemoryTransport):
47
49
        """Making a BranchBuilder with a format option sets the branch type."""
48
50
        builder = BranchBuilder(self.get_transport(), format='dirstate-tags')
49
51
        branch = builder.get_branch()
50
 
        self.assertIsInstance(branch, _mod_branch.BzrBranch6)
 
52
        self.assertIsInstance(branch, _mod_bzrbranch.BzrBranch6)
51
53
 
52
54
    def test_build_one_commit(self):
53
55
        """doing build_commit causes a commit to happen."""
87
89
            [rev_id1],
88
90
            branch.repository.get_revision(branch.last_revision()).parent_ids)
89
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=["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
            ["ghost"],
 
102
            branch.repository.get_revision(rev_id1).parent_ids)
 
103
 
90
104
 
91
105
class TestBranchBuilderBuildSnapshot(tests.TestCaseWithMemoryTransport):
92
106
 
248
262
                              (u'dir', 'dir-id', 'directory'),
249
263
                              (u'dir/a', 'a-id', 'file')], rev_tree)
250
264
 
 
265
    def test_rename_out_of_unversioned_subdir(self):
 
266
        builder = self.build_a_rev()
 
267
        builder.build_snapshot('B-id', None,
 
268
            [('add', ('dir', 'dir-id', 'directory', None)),
 
269
             ('rename', ('a', 'dir/a'))])
 
270
        builder.build_snapshot('C-id', None,
 
271
            [('rename', ('dir/a', 'a')),
 
272
             ('unversion', 'dir-id')])
 
273
        rev_tree = builder.get_branch().repository.revision_tree('C-id')
 
274
        self.assertTreeShape([(u'', 'a-root-id', 'directory'),
 
275
                              (u'a', 'a-id', 'file')], rev_tree)
 
276
 
251
277
    def test_set_parent(self):
252
278
        builder = self.build_a_rev()
253
279
        builder.start_series()
322
348
                             ], d_tree)
323
349
        # Because we copied the exact text into *this* tree, the 'c' file
324
350
        # should look like it was not modified in the merge
325
 
        self.assertEqual('C-id', d_tree.inventory['c-id'].revision)
326
 
 
 
351
        self.assertEqual('C-id', d_tree.get_file_revision('c-id'))
 
352
 
 
353
    def test_set_parent_to_null(self):
 
354
        builder = self.build_a_rev()
 
355
        builder.start_series()
 
356
        self.addCleanup(builder.finish_series)
 
357
        builder.build_snapshot('B-id', [],
 
358
            [('add', ('', None, 'directory', None))])
 
359
        # We should now have a graph:
 
360
        #   A B
 
361
        # And not A => B
 
362
        repo = builder.get_branch().repository
 
363
        self.assertEqual({'A-id': (_mod_revision.NULL_REVISION,),
 
364
                          'B-id': (_mod_revision.NULL_REVISION,),},
 
365
                         repo.get_parent_map(['A-id', 'B-id']))
 
366
 
 
367
    
327
368
    def test_start_finish_series(self):
328
369
        builder = BranchBuilder(self.get_transport().clone('foo'))
329
370
        builder.start_series()
350
391
        self.addCleanup(b.unlock)
351
392
        self.assertEqual(('ghost',),
352
393
            b.repository.get_graph().get_parent_map(['tip'])['tip'])
 
394
 
 
395
    def test_unversion_root_add_new_root(self):
 
396
        builder = BranchBuilder(self.get_transport().clone('foo'))
 
397
        builder.start_series()
 
398
        builder.build_snapshot('rev-1', None,
 
399
            [('add', ('', 'TREE_ROOT', 'directory', ''))])
 
400
        builder.build_snapshot('rev-2', None,
 
401
            [('unversion', 'TREE_ROOT'),
 
402
             ('add', ('', 'my-root', 'directory', ''))])
 
403
        builder.finish_series()
 
404
        rev_tree = builder.get_branch().repository.revision_tree('rev-2')
 
405
        self.assertTreeShape([(u'', 'my-root', 'directory')], rev_tree)
 
406
 
 
407
    def test_empty_flush(self):
 
408
        """A flush with no actions before it is a no-op."""
 
409
        builder = BranchBuilder(self.get_transport().clone('foo'))
 
410
        builder.start_series()
 
411
        builder.build_snapshot('rev-1', None,
 
412
            [('add', ('', 'TREE_ROOT', 'directory', ''))])
 
413
        builder.build_snapshot('rev-2', None, [('flush', None)])
 
414
        builder.finish_series()
 
415
        rev_tree = builder.get_branch().repository.revision_tree('rev-2')
 
416
        self.assertTreeShape([(u'', 'TREE_ROOT', 'directory')], rev_tree)
 
417
 
 
418
    def test_kind_change(self):
 
419
        """It's possible to change the kind of an entry in a single snapshot
 
420
        with a bit of help from the 'flush' action.
 
421
        """
 
422
        builder = BranchBuilder(self.get_transport().clone('foo'))
 
423
        builder.start_series()
 
424
        builder.build_snapshot('A-id', None,
 
425
            [('add', (u'', 'a-root-id', 'directory', None)),
 
426
             ('add', (u'a', 'a-id', 'file', 'content\n'))])
 
427
        builder.build_snapshot('B-id', None,
 
428
            [('unversion', 'a-id'),
 
429
             ('flush', None),
 
430
             ('add', (u'a', 'a-id', 'directory', None))])
 
431
        builder.finish_series()
 
432
        rev_tree = builder.get_branch().repository.revision_tree('B-id')
 
433
        self.assertTreeShape(
 
434
            [(u'', 'a-root-id', 'directory'), (u'a', 'a-id', 'directory')],
 
435
            rev_tree)
 
436
 
 
437
    def test_pivot_root(self):
 
438
        """It's possible (albeit awkward) to move an existing dir to the root
 
439
        in a single snapshot by using unversion then flush then add.
 
440
        """
 
441
        builder = BranchBuilder(self.get_transport().clone('foo'))
 
442
        builder.start_series()
 
443
        builder.build_snapshot('A-id', None,
 
444
            [('add', (u'', 'orig-root', 'directory', None)),
 
445
             ('add', (u'dir', 'dir-id', 'directory', None))])
 
446
        builder.build_snapshot('B-id', None,
 
447
            [('unversion', 'orig-root'),  # implicitly unversions all children
 
448
             ('flush', None),
 
449
             ('add', (u'', 'dir-id', 'directory', None))])
 
450
        builder.finish_series()
 
451
        rev_tree = builder.get_branch().repository.revision_tree('B-id')
 
452
        self.assertTreeShape([(u'', 'dir-id', 'directory')], rev_tree)
 
453