/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: Martin
  • Date: 2017-06-11 01:12:29 UTC
  • mto: This revision was merged to the branch mainline in revision 6685.
  • Revision ID: gzlist@googlemail.com-20170611011229-somdjbalby8m7vlw
Make _chunks_to_lines pass for Python 3

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,
 
21
    bzrbranch as _mod_bzrbranch,
22
22
    revision as _mod_revision,
23
23
    tests,
24
24
    )
25
 
from bzrlib.branchbuilder import BranchBuilder
 
25
from ..branchbuilder import BranchBuilder
26
26
 
27
27
 
28
28
class TestBranchBuilder(tests.TestCaseWithMemoryTransport):
47
47
        """Making a BranchBuilder with a format option sets the branch type."""
48
48
        builder = BranchBuilder(self.get_transport(), format='dirstate-tags')
49
49
        branch = builder.get_branch()
50
 
        self.assertIsInstance(branch, _mod_branch.BzrBranch6)
 
50
        self.assertIsInstance(branch, _mod_bzrbranch.BzrBranch6)
51
51
 
52
52
    def test_build_one_commit(self):
53
53
        """doing build_commit causes a commit to happen."""
87
87
            [rev_id1],
88
88
            branch.repository.get_revision(branch.last_revision()).parent_ids)
89
89
 
 
90
    def test_build_commit_parent_ids(self):
 
91
        """build_commit() takes a parent_ids argument."""
 
92
        builder = BranchBuilder(self.get_transport().clone('foo'))
 
93
        rev_id1 = builder.build_commit(
 
94
            parent_ids=["ghost"], allow_leftmost_as_ghost=True)
 
95
        rev_id2 = builder.build_commit(parent_ids=[])
 
96
        branch = builder.get_branch()
 
97
        self.assertEqual((1, rev_id2), branch.last_revision_info())
 
98
        self.assertEqual(
 
99
            ["ghost"],
 
100
            branch.repository.get_revision(rev_id1).parent_ids)
 
101
 
90
102
 
91
103
class TestBranchBuilderBuildSnapshot(tests.TestCaseWithMemoryTransport):
92
104
 
248
260
                              (u'dir', 'dir-id', 'directory'),
249
261
                              (u'dir/a', 'a-id', 'file')], rev_tree)
250
262
 
 
263
    def test_rename_out_of_unversioned_subdir(self):
 
264
        builder = self.build_a_rev()
 
265
        builder.build_snapshot('B-id', None,
 
266
            [('add', ('dir', 'dir-id', 'directory', None)),
 
267
             ('rename', ('a', 'dir/a'))])
 
268
        builder.build_snapshot('C-id', None,
 
269
            [('rename', ('dir/a', 'a')),
 
270
             ('unversion', 'dir-id')])
 
271
        rev_tree = builder.get_branch().repository.revision_tree('C-id')
 
272
        self.assertTreeShape([(u'', 'a-root-id', 'directory'),
 
273
                              (u'a', 'a-id', 'file')], rev_tree)
 
274
 
251
275
    def test_set_parent(self):
252
276
        builder = self.build_a_rev()
253
277
        builder.start_series()
322
346
                             ], d_tree)
323
347
        # Because we copied the exact text into *this* tree, the 'c' file
324
348
        # should look like it was not modified in the merge
325
 
        self.assertEqual('C-id', d_tree.inventory['c-id'].revision)
326
 
 
 
349
        self.assertEqual('C-id', d_tree.get_file_revision('c-id'))
 
350
 
 
351
    def test_set_parent_to_null(self):
 
352
        builder = self.build_a_rev()
 
353
        builder.start_series()
 
354
        self.addCleanup(builder.finish_series)
 
355
        builder.build_snapshot('B-id', [],
 
356
            [('add', ('', None, 'directory', None))])
 
357
        # We should now have a graph:
 
358
        #   A B
 
359
        # And not A => B
 
360
        repo = builder.get_branch().repository
 
361
        self.assertEqual({'A-id': (_mod_revision.NULL_REVISION,),
 
362
                          'B-id': (_mod_revision.NULL_REVISION,),},
 
363
                         repo.get_parent_map(['A-id', 'B-id']))
 
364
 
 
365
    
327
366
    def test_start_finish_series(self):
328
367
        builder = BranchBuilder(self.get_transport().clone('foo'))
329
368
        builder.start_series()
350
389
        self.addCleanup(b.unlock)
351
390
        self.assertEqual(('ghost',),
352
391
            b.repository.get_graph().get_parent_map(['tip'])['tip'])
 
392
 
 
393
    def test_unversion_root_add_new_root(self):
 
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,
 
399
            [('unversion', 'TREE_ROOT'),
 
400
             ('add', ('', 'my-root', 'directory', ''))])
 
401
        builder.finish_series()
 
402
        rev_tree = builder.get_branch().repository.revision_tree('rev-2')
 
403
        self.assertTreeShape([(u'', 'my-root', 'directory')], rev_tree)
 
404
 
 
405
    def test_empty_flush(self):
 
406
        """A flush with no actions before it is a no-op."""
 
407
        builder = BranchBuilder(self.get_transport().clone('foo'))
 
408
        builder.start_series()
 
409
        builder.build_snapshot('rev-1', None,
 
410
            [('add', ('', 'TREE_ROOT', 'directory', ''))])
 
411
        builder.build_snapshot('rev-2', None, [('flush', None)])
 
412
        builder.finish_series()
 
413
        rev_tree = builder.get_branch().repository.revision_tree('rev-2')
 
414
        self.assertTreeShape([(u'', 'TREE_ROOT', 'directory')], rev_tree)
 
415
 
 
416
    def test_kind_change(self):
 
417
        """It's possible to change the kind of an entry in a single snapshot
 
418
        with a bit of help from the 'flush' action.
 
419
        """
 
420
        builder = BranchBuilder(self.get_transport().clone('foo'))
 
421
        builder.start_series()
 
422
        builder.build_snapshot('A-id', None,
 
423
            [('add', (u'', 'a-root-id', 'directory', None)),
 
424
             ('add', (u'a', 'a-id', 'file', 'content\n'))])
 
425
        builder.build_snapshot('B-id', None,
 
426
            [('unversion', 'a-id'),
 
427
             ('flush', None),
 
428
             ('add', (u'a', 'a-id', 'directory', None))])
 
429
        builder.finish_series()
 
430
        rev_tree = builder.get_branch().repository.revision_tree('B-id')
 
431
        self.assertTreeShape(
 
432
            [(u'', 'a-root-id', 'directory'), (u'a', 'a-id', 'directory')],
 
433
            rev_tree)
 
434
 
 
435
    def test_pivot_root(self):
 
436
        """It's possible (albeit awkward) to move an existing dir to the root
 
437
        in a single snapshot by using unversion then flush then add.
 
438
        """
 
439
        builder = BranchBuilder(self.get_transport().clone('foo'))
 
440
        builder.start_series()
 
441
        builder.build_snapshot('A-id', None,
 
442
            [('add', (u'', 'orig-root', 'directory', None)),
 
443
             ('add', (u'dir', 'dir-id', 'directory', None))])
 
444
        builder.build_snapshot('B-id', None,
 
445
            [('unversion', 'orig-root'),  # implicitly unversions all children
 
446
             ('flush', None),
 
447
             ('add', (u'', 'dir-id', 'directory', None))])
 
448
        builder.finish_series()
 
449
        rev_tree = builder.get_branch().repository.revision_tree('B-id')
 
450
        self.assertTreeShape([(u'', 'dir-id', 'directory')], rev_tree)
 
451