/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4044.1.1 by Robert Collins
Create Branch.create_clone_on_transport helper method to combine bzr and branch creation for push.
1
# Copyright (C) 2009 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""Tests for branch.create_clone behaviour."""
18
4053.2.2 by Andrew Bennetts
Better fix, with test.
19
from bzrlib import errors
20
from bzrlib import tests
4044.1.1 by Robert Collins
Create Branch.create_clone_on_transport helper method to combine bzr and branch creation for push.
21
from bzrlib.tests.branch_implementations.test_branch import TestCaseWithBranch
22
23
24
class TestCreateClone(TestCaseWithBranch):
25
26
    def test_create_clone_on_transport_no_revision_id(self):
27
        tree = self.make_branch_and_tree('source')
28
        tree.commit('a commit')
29
        source = tree.branch
30
        target_transport = self.get_transport('target')
31
        result = tree.branch.create_clone_on_transport(target_transport)
32
        self.assertEqual(source.last_revision(), result.last_revision())
33
34
    def test_create_clone_on_transport_revision_id(self):
35
        tree = self.make_branch_and_tree('source')
36
        old_revid = tree.commit('a commit')
37
        source_tip = tree.commit('a second commit')
38
        source = tree.branch
39
        target_transport = self.get_transport('target')
40
        result = tree.branch.create_clone_on_transport(target_transport,
41
            revision_id=old_revid)
42
        self.assertEqual(old_revid, result.last_revision())
43
        result.lock_read()
44
        self.addCleanup(result.unlock)
45
        self.assertFalse(result.repository.has_revision(source_tip))
46
47
    def test_create_clone_on_transport_stacked(self):
48
        tree = self.make_branch_and_tree('source')
49
        tree.commit('a commit')
50
        trunk = tree.branch.create_clone_on_transport(
51
            self.get_transport('trunk'))
52
        revid = tree.commit('a second commit')
53
        source = tree.branch
54
        target_transport = self.get_transport('target')
55
        result = tree.branch.create_clone_on_transport(target_transport,
56
            stacked_on=trunk.base)
57
        self.assertEqual(revid, result.last_revision())
58
        self.assertEqual(trunk.base, result.get_stacked_on_url())
4053.2.2 by Andrew Bennetts
Better fix, with test.
59
4053.2.3 by Andrew Bennetts
Fix some nits.
60
    def test_create_clone_of_multiple_roots(self):
4053.2.2 by Andrew Bennetts
Better fix, with test.
61
        try:
62
            builder = self.make_branch_builder('local')
63
        except (errors.TransportNotPossible, errors.UninitializableFormat):
64
            raise tests.TestNotApplicable('format not directly constructable')
65
        builder.start_series()
66
        builder.build_snapshot('rev1', None, [
67
            ('add', ('', 'root-id', 'directory', ''))])
68
        builder.build_snapshot('rev2', ['rev1'], [])
69
        builder.build_snapshot('other', None, [
70
            ('add', ('', 'root-id', 'directory', ''))])
71
        builder.build_snapshot('rev3', ['rev2', 'other'], [])
72
        builder.finish_series()
73
        local = builder.get_branch()
74
        local.bzrdir.clone(self.get_url('remote'), revision_id='rev3')
75