/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 bzrlib/tests/per_branch/test_create_clone.py

  • Committer: Martin von Gagern
  • Date: 2010-04-20 08:47:38 UTC
  • mfrom: (5167 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5195.
  • Revision ID: martin.vgagern@gmx.net-20100420084738-ygymnqmdllzrhpfn
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2009, 2010 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 branch.create_clone behaviour."""
 
18
 
 
19
from bzrlib import (
 
20
    branch,
 
21
    errors,
 
22
    remote,
 
23
    tests,
 
24
    )
 
25
from bzrlib.tests import per_branch
 
26
 
 
27
 
 
28
class TestCreateClone(per_branch.TestCaseWithBranch):
 
29
 
 
30
    def test_create_clone_on_transport_missing_parent_dir(self):
 
31
        tree = self.make_branch_and_tree('source')
 
32
        tree.commit('a commit')
 
33
        source = tree.branch
 
34
        target_transport = self.get_transport('subdir').clone('target')
 
35
        self.assertRaises(errors.NoSuchFile,
 
36
            tree.branch.create_clone_on_transport, target_transport)
 
37
        self.assertFalse(self.get_transport('.').has('subdir'))
 
38
 
 
39
    def test_create_clone_on_transport_missing_parent_dir_create(self):
 
40
        tree = self.make_branch_and_tree('source')
 
41
        tree.commit('a commit')
 
42
        source = tree.branch
 
43
        target_transport = self.get_transport('subdir').clone('target')
 
44
        result = tree.branch.create_clone_on_transport(target_transport,
 
45
            create_prefix=True)
 
46
        self.assertEqual(source.last_revision(), result.last_revision())
 
47
        self.assertEqual(target_transport.base,
 
48
            result.bzrdir.root_transport.base)
 
49
 
 
50
    def test_create_clone_on_transport_use_existing_dir_false(self):
 
51
        tree = self.make_branch_and_tree('source')
 
52
        tree.commit('a commit')
 
53
        source = tree.branch
 
54
        target_transport = self.get_transport('target')
 
55
        target_transport.create_prefix()
 
56
        self.assertRaises(errors.FileExists,
 
57
            tree.branch.create_clone_on_transport, target_transport)
 
58
        self.assertFalse(target_transport.has(".bzr"))
 
59
 
 
60
    def test_create_clone_on_transport_use_existing_dir_true(self):
 
61
        tree = self.make_branch_and_tree('source')
 
62
        tree.commit('a commit')
 
63
        source = tree.branch
 
64
        target_transport = self.get_transport('target')
 
65
        target_transport.create_prefix()
 
66
        result = tree.branch.create_clone_on_transport(target_transport,
 
67
            use_existing_dir=True)
 
68
        self.assertEqual(source.last_revision(), result.last_revision())
 
69
 
 
70
    def test_create_clone_on_transport_no_revision_id(self):
 
71
        tree = self.make_branch_and_tree('source')
 
72
        tree.commit('a commit')
 
73
        source = tree.branch
 
74
        target_transport = self.get_transport('target')
 
75
        result = tree.branch.create_clone_on_transport(target_transport)
 
76
        self.assertEqual(source.last_revision(), result.last_revision())
 
77
 
 
78
    def test_create_clone_on_transport_revision_id(self):
 
79
        tree = self.make_branch_and_tree('source')
 
80
        old_revid = tree.commit('a commit')
 
81
        source_tip = tree.commit('a second commit')
 
82
        source = tree.branch
 
83
        target_transport = self.get_transport('target')
 
84
        result = tree.branch.create_clone_on_transport(target_transport,
 
85
            revision_id=old_revid)
 
86
        self.assertEqual(old_revid, result.last_revision())
 
87
        result.lock_read()
 
88
        self.addCleanup(result.unlock)
 
89
        self.assertFalse(result.repository.has_revision(source_tip))
 
90
 
 
91
    def test_create_clone_on_transport_stacked(self):
 
92
        tree = self.make_branch_and_tree('source')
 
93
        tree.commit('a commit')
 
94
        trunk = tree.branch.create_clone_on_transport(
 
95
            self.get_transport('trunk'))
 
96
        revid = tree.commit('a second commit')
 
97
        source = tree.branch
 
98
        target_transport = self.get_transport('target')
 
99
        result = tree.branch.create_clone_on_transport(target_transport,
 
100
            stacked_on=trunk.base)
 
101
        self.assertEqual(revid, result.last_revision())
 
102
        self.assertEqual(trunk.base, result.get_stacked_on_url())
 
103
 
 
104
    def test_create_clone_of_multiple_roots(self):
 
105
        try:
 
106
            builder = self.make_branch_builder('local')
 
107
        except (errors.TransportNotPossible, errors.UninitializableFormat):
 
108
            raise tests.TestNotApplicable('format not directly constructable')
 
109
        builder.start_series()
 
110
        builder.build_snapshot('rev1', None, [
 
111
            ('add', ('', 'root-id', 'directory', ''))])
 
112
        builder.build_snapshot('rev2', ['rev1'], [])
 
113
        builder.build_snapshot('other', None, [
 
114
            ('add', ('', 'root-id', 'directory', ''))])
 
115
        builder.build_snapshot('rev3', ['rev2', 'other'], [])
 
116
        builder.finish_series()
 
117
        local = builder.get_branch()
 
118
        local.bzrdir.clone(self.get_url('remote'), revision_id='rev3')
 
119
 
 
120
    def assertBranchHookBranchIsStacked(self, pre_change_params):
 
121
        # Just calling will either succeed or fail.
 
122
        pre_change_params.branch.get_stacked_on_url()
 
123
        self.hook_calls.append(pre_change_params)
 
124
 
 
125
    def test_create_clone_on_transport_stacked_hooks_get_stacked_branch(self):
 
126
        tree = self.make_branch_and_tree('source')
 
127
        tree.commit('a commit')
 
128
        trunk = tree.branch.create_clone_on_transport(
 
129
            self.get_transport('trunk'))
 
130
        revid = tree.commit('a second commit')
 
131
        source = tree.branch
 
132
        target_transport = self.get_transport('target')
 
133
        self.hook_calls = []
 
134
        branch.Branch.hooks.install_named_hook(
 
135
            'pre_change_branch_tip', self.assertBranchHookBranchIsStacked, None)
 
136
        result = tree.branch.create_clone_on_transport(target_transport,
 
137
            stacked_on=trunk.base)
 
138
        self.assertEqual(revid, result.last_revision())
 
139
        self.assertEqual(trunk.base, result.get_stacked_on_url())
 
140
        # Smart servers invoke hooks on both sides
 
141
        if isinstance(result, remote.RemoteBranch):
 
142
            expected_calls = 2
 
143
        else:
 
144
            expected_calls = 1
 
145
        self.assertEqual(expected_calls, len(self.hook_calls))