/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
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,
2796.2.25 by Aaron Bentley
Avoid destroying shared repositories
21
    repository,
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
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')
2796.2.23 by Aaron Bentley
Add support for reconfiguring repositories into branches or trees
53
        reconfiguration = reconfigure.Reconfigure.to_branch(repo.bzrdir)
54
        reconfiguration.apply()
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
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())
2796.2.2 by Aaron Bentley
Refuse to turn lightweight checkouts into branches
62
63
    def test_lightweight_checkout_to_branch(self):
64
        branch = self.make_branch('branch')
65
        checkout = branch.create_checkout('checkout', lightweight=True)
2796.2.8 by Aaron Bentley
Ensure conversion from lightweight fetches revisions and sets revision info
66
        checkout.commit('first commit', rev_id='rev1')
2796.2.7 by Aaron Bentley
Implement converting a lightweight checkout to a branch
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)
2796.2.8 by Aaron Bentley
Ensure conversion from lightweight fetches revisions and sets revision info
72
        self.assertEqual('rev1', checkout_branch.last_revision())
73
        repo = checkout.bzrdir.open_repository()
74
        repo.get_revision('rev1')
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
75
2796.2.9 by Aaron Bentley
Ensure conversion from lightweight checkout works
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
2796.2.10 by Aaron Bentley
Ensure that shared repositories are used where possible
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
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
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())
2796.2.22 by Aaron Bentley
Tweak from review
115
        branch.set_bound_location('bzr://foo/old-bound')
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
116
        branch.set_bound_location(None)
2796.2.22 by Aaron Bentley
Tweak from review
117
        self.assertEqual('bzr://foo/old-bound',
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
118
                         reconfiguration._select_bind_location())
2796.2.22 by Aaron Bentley
Tweak from review
119
        branch.set_bound_location('bzr://foo/cur-bound')
120
        self.assertEqual('bzr://foo/cur-bound',
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
121
                         reconfiguration._select_bind_location())
2796.2.11 by Aaron Bentley
Cleanups
122
        reconfiguration.new_bound_location = 'ftp://user-specified'
123
        self.assertEqual('ftp://user-specified',
124
                         reconfiguration._select_bind_location())
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
125
2796.2.9 by Aaron Bentley
Ensure conversion from lightweight checkout works
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
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
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)
2796.2.4 by Aaron Bentley
Fix support for reconfiguring to selected bound location
148
        reconfiguration.apply()
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
149
2796.2.26 by Aaron Bentley
Support converting standalone tree to lightweight checkout
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
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
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)
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
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
2796.2.30 by Aaron Bentley
Reconfigure can safely be interrupted while fetching (#179316)
203
    def test_branch_to_lightweight_checkout_failure(self):
204
        parent = self.make_branch('parent')
205
        child = parent.bzrdir.sprout('child').open_workingtree()
206
        child.commit('test', rev_id='new-commit')
207
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
208
            child.bzrdir)
209
        old_Repository_fetch = repository.Repository.fetch
210
        repository.Repository.fetch = None
211
        try:
212
            self.assertRaises(TypeError, reconfiguration.apply)
213
        finally:
214
            repository.Repository.fetch = old_Repository_fetch
215
        child = _mod_branch.Branch.open('child')
216
        self.assertContainsRe(child.base, 'child/$')
217
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
218
    def test_lightweight_checkout_to_lightweight_checkout(self):
219
        parent = self.make_branch('parent')
220
        checkout = parent.create_checkout('checkout', lightweight=True)
221
        self.assertRaises(errors.AlreadyLightweightCheckout,
222
                          reconfigure.Reconfigure.to_lightweight_checkout,
223
                          checkout.bzrdir)
2796.2.23 by Aaron Bentley
Add support for reconfiguring repositories into branches or trees
224
225
    def test_repo_to_tree(self):
226
        repo = self.make_repository('repo')
227
        reconfiguration = reconfigure.Reconfigure.to_tree(repo.bzrdir)
228
        reconfiguration.apply()
229
        workingtree.WorkingTree.open('repo')
230
2796.2.25 by Aaron Bentley
Avoid destroying shared repositories
231
    def test_shared_repo_to_lightweight_checkout(self):
232
        repo = self.make_repository('repo', shared=True)
2796.2.23 by Aaron Bentley
Add support for reconfiguring repositories into branches or trees
233
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
234
            repo.bzrdir)
235
        self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
236
        branch = self.make_branch('branch')
237
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
238
            repo.bzrdir, 'branch')
239
        reconfiguration.apply()
2796.2.25 by Aaron Bentley
Avoid destroying shared repositories
240
        workingtree.WorkingTree.open('repo')
241
        repository.Repository.open('repo')
242
243
    def test_unshared_repo_to_lightweight_checkout(self):
244
        repo = self.make_repository('repo', shared=False)
245
        branch = self.make_branch('branch')
246
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
247
            repo.bzrdir, 'branch')
248
        reconfiguration.apply()
249
        workingtree.WorkingTree.open('repo')
250
        self.assertRaises(errors.NoRepositoryPresent,
251
                          repository.Repository.open, 'repo')