~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_reconfigure.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-01-03 18:09:01 UTC
  • mfrom: (3159.1.1 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20080103180901-w987y1ftqoh02qbm
(vila) Fix #179368 by keeping the current range hint on
        ShortReadvErrors

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2007 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
from bzrlib import (
 
18
    branch as _mod_branch,
 
19
    errors,
 
20
    reconfigure,
 
21
    repository,
 
22
    tests,
 
23
    workingtree,
 
24
    )
 
25
 
 
26
 
 
27
class TestReconfigure(tests.TestCaseWithTransport):
 
28
 
 
29
    def test_tree_to_branch(self):
 
30
        tree = self.make_branch_and_tree('tree')
 
31
        reconfiguration = reconfigure.Reconfigure.to_branch(tree.bzrdir)
 
32
        reconfiguration.apply()
 
33
        self.assertRaises(errors.NoWorkingTree, workingtree.WorkingTree.open,
 
34
                          'tree')
 
35
 
 
36
    def test_modified_tree_to_branch(self):
 
37
        tree = self.make_branch_and_tree('tree')
 
38
        self.build_tree(['tree/file'])
 
39
        tree.add('file')
 
40
        reconfiguration = reconfigure.Reconfigure.to_branch(tree.bzrdir)
 
41
        self.assertRaises(errors.UncommittedChanges, reconfiguration.apply)
 
42
        reconfiguration.apply(force=True)
 
43
        self.assertRaises(errors.NoWorkingTree, workingtree.WorkingTree.open,
 
44
                          'tree')
 
45
 
 
46
    def test_branch_to_branch(self):
 
47
        branch = self.make_branch('branch')
 
48
        self.assertRaises(errors.AlreadyBranch,
 
49
                          reconfigure.Reconfigure.to_branch, branch.bzrdir)
 
50
 
 
51
    def test_repo_to_branch(self):
 
52
        repo = self.make_repository('repo')
 
53
        reconfiguration = reconfigure.Reconfigure.to_branch(repo.bzrdir)
 
54
        reconfiguration.apply()
 
55
 
 
56
    def test_checkout_to_branch(self):
 
57
        branch = self.make_branch('branch')
 
58
        checkout = branch.create_checkout('checkout')
 
59
        reconfiguration = reconfigure.Reconfigure.to_branch(checkout.bzrdir)
 
60
        reconfiguration.apply()
 
61
        self.assertIs(None, checkout.branch.get_bound_location())
 
62
 
 
63
    def test_lightweight_checkout_to_branch(self):
 
64
        branch = self.make_branch('branch')
 
65
        checkout = branch.create_checkout('checkout', lightweight=True)
 
66
        checkout.commit('first commit', rev_id='rev1')
 
67
        reconfiguration = reconfigure.Reconfigure.to_branch(checkout.bzrdir)
 
68
        reconfiguration.apply()
 
69
        checkout_branch = checkout.bzrdir.open_branch()
 
70
        self.assertEqual(checkout_branch.bzrdir.root_transport.base,
 
71
                         checkout.bzrdir.root_transport.base)
 
72
        self.assertEqual('rev1', checkout_branch.last_revision())
 
73
        repo = checkout.bzrdir.open_repository()
 
74
        repo.get_revision('rev1')
 
75
 
 
76
    def test_lightweight_checkout_to_checkout(self):
 
77
        branch = self.make_branch('branch')
 
78
        checkout = branch.create_checkout('checkout', lightweight=True)
 
79
        reconfiguration = reconfigure.Reconfigure.to_checkout(checkout.bzrdir)
 
80
        reconfiguration.apply()
 
81
        checkout_branch = checkout.bzrdir.open_branch()
 
82
        self.assertIsNot(checkout_branch.get_bound_location(), None)
 
83
 
 
84
    def test_lightweight_conversion_uses_shared_repo(self):
 
85
        parent = self.make_branch('parent')
 
86
        shared_repo = self.make_repository('repo', shared=True)
 
87
        checkout = parent.create_checkout('repo/checkout', lightweight=True)
 
88
        reconfigure.Reconfigure.to_tree(checkout.bzrdir).apply()
 
89
        checkout_repo = checkout.bzrdir.open_branch().repository
 
90
        self.assertEqual(shared_repo.bzrdir.root_transport.base,
 
91
                         checkout_repo.bzrdir.root_transport.base)
 
92
 
 
93
    def test_branch_to_tree(self):
 
94
        branch = self.make_branch('branch')
 
95
        reconfiguration=reconfigure.Reconfigure.to_tree(branch.bzrdir)
 
96
        reconfiguration.apply()
 
97
        branch.bzrdir.open_workingtree()
 
98
 
 
99
    def test_tree_to_tree(self):
 
100
        tree = self.make_branch_and_tree('tree')
 
101
        self.assertRaises(errors.AlreadyTree, reconfigure.Reconfigure.to_tree,
 
102
                          tree.bzrdir)
 
103
 
 
104
    def test_select_bind_location(self):
 
105
        branch = self.make_branch('branch')
 
106
        reconfiguration = reconfigure.Reconfigure(branch.bzrdir)
 
107
        self.assertRaises(errors.NoBindLocation,
 
108
                          reconfiguration._select_bind_location)
 
109
        branch.set_parent('http://parent')
 
110
        self.assertEqual('http://parent',
 
111
                         reconfiguration._select_bind_location())
 
112
        branch.set_push_location('sftp://push')
 
113
        self.assertEqual('sftp://push',
 
114
                         reconfiguration._select_bind_location())
 
115
        branch.set_bound_location('bzr://foo/old-bound')
 
116
        branch.set_bound_location(None)
 
117
        self.assertEqual('bzr://foo/old-bound',
 
118
                         reconfiguration._select_bind_location())
 
119
        branch.set_bound_location('bzr://foo/cur-bound')
 
120
        self.assertEqual('bzr://foo/cur-bound',
 
121
                         reconfiguration._select_bind_location())
 
122
        reconfiguration.new_bound_location = 'ftp://user-specified'
 
123
        self.assertEqual('ftp://user-specified',
 
124
                         reconfiguration._select_bind_location())
 
125
 
 
126
    def test_select_reference_bind_location(self):
 
127
        branch = self.make_branch('branch')
 
128
        checkout = branch.create_checkout('checkout', lightweight=True)
 
129
        reconfiguration = reconfigure.Reconfigure(checkout.bzrdir)
 
130
        self.assertEqual(branch.base,
 
131
                         reconfiguration._select_bind_location())
 
132
 
 
133
    def test_tree_to_checkout(self):
 
134
        # A tree with no related branches and no supplied bind location cannot
 
135
        # become a checkout
 
136
        parent = self.make_branch('parent')
 
137
 
 
138
        tree = self.make_branch_and_tree('tree')
 
139
        reconfiguration = reconfigure.Reconfigure.to_checkout(tree.bzrdir)
 
140
        self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
 
141
        # setting a parent allows it to become a checkout
 
142
        tree.branch.set_parent(parent.base)
 
143
        reconfiguration.apply()
 
144
        # supplying a location allows it to become a checkout
 
145
        tree2 = self.make_branch_and_tree('tree2')
 
146
        reconfiguration = reconfigure.Reconfigure.to_checkout(tree2.bzrdir,
 
147
                                                              parent.base)
 
148
        reconfiguration.apply()
 
149
 
 
150
    def test_tree_to_lightweight_checkout(self):
 
151
        # A tree with no related branches and no supplied bind location cannot
 
152
        # become a checkout
 
153
        parent = self.make_branch('parent')
 
154
 
 
155
        tree = self.make_branch_and_tree('tree')
 
156
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
 
157
            tree.bzrdir)
 
158
        self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
 
159
        # setting a parent allows it to become a checkout
 
160
        tree.branch.set_parent(parent.base)
 
161
        reconfiguration.apply()
 
162
        # supplying a location allows it to become a checkout
 
163
        tree2 = self.make_branch_and_tree('tree2')
 
164
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
 
165
            tree2.bzrdir, parent.base)
 
166
        reconfiguration.apply()
 
167
 
 
168
    def test_checkout_to_checkout(self):
 
169
        parent = self.make_branch('parent')
 
170
        checkout = parent.create_checkout('checkout')
 
171
        self.assertRaises(errors.AlreadyCheckout,
 
172
                          reconfigure.Reconfigure.to_checkout, checkout.bzrdir)
 
173
 
 
174
    def test_checkout_to_lightweight(self):
 
175
        parent = self.make_branch('parent')
 
176
        checkout = parent.create_checkout('checkout')
 
177
        checkout.commit('test', rev_id='new-commit', local=True)
 
178
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
 
179
            checkout.bzrdir)
 
180
        reconfiguration.apply()
 
181
        wt = checkout.bzrdir.open_workingtree()
 
182
        self.assertTrue(parent.repository.has_same_location(
 
183
            wt.branch.repository))
 
184
        parent.repository.get_revision('new-commit')
 
185
        self.assertRaises(errors.NoRepositoryPresent,
 
186
                          checkout.bzrdir.open_repository)
 
187
 
 
188
    def test_branch_to_lightweight_checkout(self):
 
189
        parent = self.make_branch('parent')
 
190
        child = parent.bzrdir.sprout('child').open_workingtree()
 
191
        child.commit('test', rev_id='new-commit')
 
192
        child.bzrdir.destroy_workingtree()
 
193
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
 
194
            child.bzrdir)
 
195
        reconfiguration.apply()
 
196
        wt = child.bzrdir.open_workingtree()
 
197
        self.assertTrue(parent.repository.has_same_location(
 
198
            wt.branch.repository))
 
199
        parent.repository.get_revision('new-commit')
 
200
        self.assertRaises(errors.NoRepositoryPresent,
 
201
                          child.bzrdir.open_repository)
 
202
 
 
203
    def test_lightweight_checkout_to_lightweight_checkout(self):
 
204
        parent = self.make_branch('parent')
 
205
        checkout = parent.create_checkout('checkout', lightweight=True)
 
206
        self.assertRaises(errors.AlreadyLightweightCheckout,
 
207
                          reconfigure.Reconfigure.to_lightweight_checkout,
 
208
                          checkout.bzrdir)
 
209
 
 
210
    def test_repo_to_tree(self):
 
211
        repo = self.make_repository('repo')
 
212
        reconfiguration = reconfigure.Reconfigure.to_tree(repo.bzrdir)
 
213
        reconfiguration.apply()
 
214
        workingtree.WorkingTree.open('repo')
 
215
 
 
216
    def test_shared_repo_to_lightweight_checkout(self):
 
217
        repo = self.make_repository('repo', shared=True)
 
218
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
 
219
            repo.bzrdir)
 
220
        self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
 
221
        branch = self.make_branch('branch')
 
222
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
 
223
            repo.bzrdir, 'branch')
 
224
        reconfiguration.apply()
 
225
        workingtree.WorkingTree.open('repo')
 
226
        repository.Repository.open('repo')
 
227
 
 
228
    def test_unshared_repo_to_lightweight_checkout(self):
 
229
        repo = self.make_repository('repo', shared=False)
 
230
        branch = self.make_branch('branch')
 
231
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
 
232
            repo.bzrdir, 'branch')
 
233
        reconfiguration.apply()
 
234
        workingtree.WorkingTree.open('repo')
 
235
        self.assertRaises(errors.NoRepositoryPresent,
 
236
                          repository.Repository.open, 'repo')