~bzr-pqm/bzr/bzr.dev

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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
16
17
from bzrlib import (
18
    branch as _mod_branch,
4273.1.18 by Aaron Bentley
Reconfigure preserves reference locations.
19
    bzrdir,
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
20
    errors,
21
    reconfigure,
2796.2.25 by Aaron Bentley
Avoid destroying shared repositories
22
    repository,
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
23
    tests,
24
    workingtree,
25
    )
26
27
28
class TestReconfigure(tests.TestCaseWithTransport):
29
30
    def test_tree_to_branch(self):
31
        tree = self.make_branch_and_tree('tree')
32
        reconfiguration = reconfigure.Reconfigure.to_branch(tree.bzrdir)
33
        reconfiguration.apply()
34
        self.assertRaises(errors.NoWorkingTree, workingtree.WorkingTree.open,
35
                          'tree')
36
37
    def test_modified_tree_to_branch(self):
38
        tree = self.make_branch_and_tree('tree')
39
        self.build_tree(['tree/file'])
40
        tree.add('file')
41
        reconfiguration = reconfigure.Reconfigure.to_branch(tree.bzrdir)
42
        self.assertRaises(errors.UncommittedChanges, reconfiguration.apply)
43
        reconfiguration.apply(force=True)
44
        self.assertRaises(errors.NoWorkingTree, workingtree.WorkingTree.open,
45
                          'tree')
46
47
    def test_branch_to_branch(self):
48
        branch = self.make_branch('branch')
49
        self.assertRaises(errors.AlreadyBranch,
50
                          reconfigure.Reconfigure.to_branch, branch.bzrdir)
51
52
    def test_repo_to_branch(self):
53
        repo = self.make_repository('repo')
2796.2.23 by Aaron Bentley
Add support for reconfiguring repositories into branches or trees
54
        reconfiguration = reconfigure.Reconfigure.to_branch(repo.bzrdir)
55
        reconfiguration.apply()
2796.2.1 by Aaron Bentley
Begin work on reconfigure command
56
57
    def test_checkout_to_branch(self):
58
        branch = self.make_branch('branch')
59
        checkout = branch.create_checkout('checkout')
60
        reconfiguration = reconfigure.Reconfigure.to_branch(checkout.bzrdir)
61
        reconfiguration.apply()
62
        self.assertIs(None, checkout.branch.get_bound_location())
2796.2.2 by Aaron Bentley
Refuse to turn lightweight checkouts into branches
63
2796.2.32 by Aaron Bentley
Preserve tags converting from lightweight checkouts
64
    def prepare_lightweight_checkout_to_branch(self):
65
        branch = self.make_branch('branch')
66
        checkout = branch.create_checkout('checkout', lightweight=True)
67
        checkout.commit('first commit', rev_id='rev1')
68
        reconfiguration = reconfigure.Reconfigure.to_branch(checkout.bzrdir)
69
        return reconfiguration, checkout
70
2796.2.2 by Aaron Bentley
Refuse to turn lightweight checkouts into branches
71
    def test_lightweight_checkout_to_branch(self):
2796.2.32 by Aaron Bentley
Preserve tags converting from lightweight checkouts
72
        reconfiguration, checkout = \
73
            self.prepare_lightweight_checkout_to_branch()
2796.2.7 by Aaron Bentley
Implement converting a lightweight checkout to a branch
74
        reconfiguration.apply()
75
        checkout_branch = checkout.bzrdir.open_branch()
76
        self.assertEqual(checkout_branch.bzrdir.root_transport.base,
77
                         checkout.bzrdir.root_transport.base)
2796.2.8 by Aaron Bentley
Ensure conversion from lightweight fetches revisions and sets revision info
78
        self.assertEqual('rev1', checkout_branch.last_revision())
79
        repo = checkout.bzrdir.open_repository()
80
        repo.get_revision('rev1')
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
81
2796.2.32 by Aaron Bentley
Preserve tags converting from lightweight checkouts
82
    def test_lightweight_checkout_to_branch_tags(self):
83
        reconfiguration, checkout = \
84
            self.prepare_lightweight_checkout_to_branch()
85
        checkout.branch.tags.set_tag('foo', 'bar')
86
        reconfiguration.apply()
87
        checkout_branch = checkout.bzrdir.open_branch()
88
        self.assertEqual('bar', checkout_branch.tags.lookup_tag('foo'))
89
2796.2.33 by Aaron Bentley
Add lightweight-checkout-to-checkout tags test
90
    def prepare_lightweight_checkout_to_checkout(self):
91
        branch = self.make_branch('branch')
92
        checkout = branch.create_checkout('checkout', lightweight=True)
93
        reconfiguration = reconfigure.Reconfigure.to_checkout(checkout.bzrdir)
94
        return reconfiguration, checkout
95
2796.2.9 by Aaron Bentley
Ensure conversion from lightweight checkout works
96
    def test_lightweight_checkout_to_checkout(self):
2796.2.33 by Aaron Bentley
Add lightweight-checkout-to-checkout tags test
97
        reconfiguration, checkout = \
98
            self.prepare_lightweight_checkout_to_checkout()
2796.2.9 by Aaron Bentley
Ensure conversion from lightweight checkout works
99
        reconfiguration.apply()
100
        checkout_branch = checkout.bzrdir.open_branch()
101
        self.assertIsNot(checkout_branch.get_bound_location(), None)
102
2796.2.33 by Aaron Bentley
Add lightweight-checkout-to-checkout tags test
103
    def test_lightweight_checkout_to_checkout_tags(self):
104
        reconfiguration, checkout = \
105
            self.prepare_lightweight_checkout_to_checkout()
106
        checkout.branch.tags.set_tag('foo', 'bar')
107
        reconfiguration.apply()
108
        checkout_branch = checkout.bzrdir.open_branch()
109
        self.assertEqual('bar', checkout_branch.tags.lookup_tag('foo'))
110
2796.2.10 by Aaron Bentley
Ensure that shared repositories are used where possible
111
    def test_lightweight_conversion_uses_shared_repo(self):
112
        parent = self.make_branch('parent')
113
        shared_repo = self.make_repository('repo', shared=True)
114
        checkout = parent.create_checkout('repo/checkout', lightweight=True)
115
        reconfigure.Reconfigure.to_tree(checkout.bzrdir).apply()
116
        checkout_repo = checkout.bzrdir.open_branch().repository
117
        self.assertEqual(shared_repo.bzrdir.root_transport.base,
118
                         checkout_repo.bzrdir.root_transport.base)
119
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
120
    def test_branch_to_tree(self):
121
        branch = self.make_branch('branch')
122
        reconfiguration=reconfigure.Reconfigure.to_tree(branch.bzrdir)
123
        reconfiguration.apply()
124
        branch.bzrdir.open_workingtree()
125
126
    def test_tree_to_tree(self):
127
        tree = self.make_branch_and_tree('tree')
128
        self.assertRaises(errors.AlreadyTree, reconfigure.Reconfigure.to_tree,
129
                          tree.bzrdir)
130
131
    def test_select_bind_location(self):
132
        branch = self.make_branch('branch')
133
        reconfiguration = reconfigure.Reconfigure(branch.bzrdir)
134
        self.assertRaises(errors.NoBindLocation,
135
                          reconfiguration._select_bind_location)
136
        branch.set_parent('http://parent')
137
        self.assertEqual('http://parent',
138
                         reconfiguration._select_bind_location())
139
        branch.set_push_location('sftp://push')
140
        self.assertEqual('sftp://push',
141
                         reconfiguration._select_bind_location())
2796.2.22 by Aaron Bentley
Tweak from review
142
        branch.set_bound_location('bzr://foo/old-bound')
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
143
        branch.set_bound_location(None)
2796.2.22 by Aaron Bentley
Tweak from review
144
        self.assertEqual('bzr://foo/old-bound',
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
145
                         reconfiguration._select_bind_location())
2796.2.22 by Aaron Bentley
Tweak from review
146
        branch.set_bound_location('bzr://foo/cur-bound')
147
        self.assertEqual('bzr://foo/cur-bound',
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
148
                         reconfiguration._select_bind_location())
2796.2.11 by Aaron Bentley
Cleanups
149
        reconfiguration.new_bound_location = 'ftp://user-specified'
150
        self.assertEqual('ftp://user-specified',
151
                         reconfiguration._select_bind_location())
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
152
2796.2.9 by Aaron Bentley
Ensure conversion from lightweight checkout works
153
    def test_select_reference_bind_location(self):
154
        branch = self.make_branch('branch')
155
        checkout = branch.create_checkout('checkout', lightweight=True)
156
        reconfiguration = reconfigure.Reconfigure(checkout.bzrdir)
157
        self.assertEqual(branch.base,
158
                         reconfiguration._select_bind_location())
159
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
160
    def test_tree_to_checkout(self):
161
        # A tree with no related branches and no supplied bind location cannot
162
        # become a checkout
163
        parent = self.make_branch('parent')
164
165
        tree = self.make_branch_and_tree('tree')
166
        reconfiguration = reconfigure.Reconfigure.to_checkout(tree.bzrdir)
167
        self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
168
        # setting a parent allows it to become a checkout
169
        tree.branch.set_parent(parent.base)
170
        reconfiguration.apply()
171
        # supplying a location allows it to become a checkout
172
        tree2 = self.make_branch_and_tree('tree2')
173
        reconfiguration = reconfigure.Reconfigure.to_checkout(tree2.bzrdir,
174
                                                              parent.base)
2796.2.4 by Aaron Bentley
Fix support for reconfiguring to selected bound location
175
        reconfiguration.apply()
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
176
2796.2.26 by Aaron Bentley
Support converting standalone tree to lightweight checkout
177
    def test_tree_to_lightweight_checkout(self):
178
        # A tree with no related branches and no supplied bind location cannot
179
        # become a checkout
180
        parent = self.make_branch('parent')
181
182
        tree = self.make_branch_and_tree('tree')
183
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
184
            tree.bzrdir)
185
        self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
186
        # setting a parent allows it to become a checkout
187
        tree.branch.set_parent(parent.base)
188
        reconfiguration.apply()
189
        # supplying a location allows it to become a checkout
190
        tree2 = self.make_branch_and_tree('tree2')
191
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
192
            tree2.bzrdir, parent.base)
193
        reconfiguration.apply()
194
2796.2.3 by Aaron Bentley
Implement conversion to tree and checkout
195
    def test_checkout_to_checkout(self):
196
        parent = self.make_branch('parent')
197
        checkout = parent.create_checkout('checkout')
198
        self.assertRaises(errors.AlreadyCheckout,
199
                          reconfigure.Reconfigure.to_checkout, checkout.bzrdir)
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
200
3338.1.2 by Aaron Bentley
Split out tests even further
201
    def make_unsynced_checkout(self):
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
202
        parent = self.make_branch('parent')
203
        checkout = parent.create_checkout('checkout')
204
        checkout.commit('test', rev_id='new-commit', local=True)
205
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
206
            checkout.bzrdir)
3338.1.2 by Aaron Bentley
Split out tests even further
207
        return checkout, parent, reconfiguration
208
209
    def test_unsynced_checkout_to_lightweight(self):
210
        checkout, parent, reconfiguration = self.make_unsynced_checkout()
3338.1.1 by Aaron Bentley
Raise an error when converting a branch to a lightweight checkout loses data
211
        self.assertRaises(errors.UnsyncedBranches, reconfiguration.apply)
3338.1.2 by Aaron Bentley
Split out tests even further
212
213
    def test_synced_checkout_to_lightweight(self):
214
        checkout, parent, reconfiguration = self.make_unsynced_checkout()
3338.1.1 by Aaron Bentley
Raise an error when converting a branch to a lightweight checkout loses data
215
        parent.pull(checkout.branch)
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
216
        reconfiguration.apply()
217
        wt = checkout.bzrdir.open_workingtree()
218
        self.assertTrue(parent.repository.has_same_location(
219
            wt.branch.repository))
220
        parent.repository.get_revision('new-commit')
221
        self.assertRaises(errors.NoRepositoryPresent,
222
                          checkout.bzrdir.open_repository)
223
2796.2.31 by Aaron Bentley
Fetch tags to reference branch when converting to checkout
224
    def prepare_branch_to_lightweight_checkout(self):
225
        parent = self.make_branch('parent')
226
        child = parent.bzrdir.sprout('child').open_workingtree()
227
        child.commit('test', rev_id='new-commit')
3338.1.1 by Aaron Bentley
Raise an error when converting a branch to a lightweight checkout loses data
228
        parent.pull(child.branch)
2796.2.31 by Aaron Bentley
Fetch tags to reference branch when converting to checkout
229
        child.bzrdir.destroy_workingtree()
230
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
231
            child.bzrdir)
232
        return parent, child, reconfiguration
233
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
234
    def test_branch_to_lightweight_checkout(self):
2796.2.31 by Aaron Bentley
Fetch tags to reference branch when converting to checkout
235
        parent, child, reconfiguration = \
236
            self.prepare_branch_to_lightweight_checkout()
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
237
        reconfiguration.apply()
2796.2.31 by Aaron Bentley
Fetch tags to reference branch when converting to checkout
238
        self.assertTrue(reconfiguration._destroy_branch)
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
239
        wt = child.bzrdir.open_workingtree()
240
        self.assertTrue(parent.repository.has_same_location(
241
            wt.branch.repository))
242
        parent.repository.get_revision('new-commit')
243
        self.assertRaises(errors.NoRepositoryPresent,
244
                          child.bzrdir.open_repository)
245
2796.2.30 by Aaron Bentley
Reconfigure can safely be interrupted while fetching (#179316)
246
    def test_branch_to_lightweight_checkout_failure(self):
2796.2.31 by Aaron Bentley
Fetch tags to reference branch when converting to checkout
247
        parent, child, reconfiguration = \
248
            self.prepare_branch_to_lightweight_checkout()
2796.2.30 by Aaron Bentley
Reconfigure can safely be interrupted while fetching (#179316)
249
        old_Repository_fetch = repository.Repository.fetch
250
        repository.Repository.fetch = None
251
        try:
252
            self.assertRaises(TypeError, reconfiguration.apply)
253
        finally:
254
            repository.Repository.fetch = old_Repository_fetch
255
        child = _mod_branch.Branch.open('child')
256
        self.assertContainsRe(child.base, 'child/$')
257
2796.2.31 by Aaron Bentley
Fetch tags to reference branch when converting to checkout
258
    def test_branch_to_lightweight_checkout_fetch_tags(self):
259
        parent, child, reconfiguration = \
260
            self.prepare_branch_to_lightweight_checkout()
261
        child.branch.tags.set_tag('foo', 'bar')
262
        reconfiguration.apply()
263
        child = _mod_branch.Branch.open('child')
264
        self.assertEqual('bar', parent.tags.lookup_tag('foo'))
265
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
266
    def test_lightweight_checkout_to_lightweight_checkout(self):
267
        parent = self.make_branch('parent')
268
        checkout = parent.create_checkout('checkout', lightweight=True)
269
        self.assertRaises(errors.AlreadyLightweightCheckout,
270
                          reconfigure.Reconfigure.to_lightweight_checkout,
271
                          checkout.bzrdir)
2796.2.23 by Aaron Bentley
Add support for reconfiguring repositories into branches or trees
272
273
    def test_repo_to_tree(self):
274
        repo = self.make_repository('repo')
275
        reconfiguration = reconfigure.Reconfigure.to_tree(repo.bzrdir)
276
        reconfiguration.apply()
277
        workingtree.WorkingTree.open('repo')
278
2796.2.25 by Aaron Bentley
Avoid destroying shared repositories
279
    def test_shared_repo_to_lightweight_checkout(self):
280
        repo = self.make_repository('repo', shared=True)
2796.2.23 by Aaron Bentley
Add support for reconfiguring repositories into branches or trees
281
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
282
            repo.bzrdir)
283
        self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
284
        branch = self.make_branch('branch')
285
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
286
            repo.bzrdir, 'branch')
287
        reconfiguration.apply()
2796.2.25 by Aaron Bentley
Avoid destroying shared repositories
288
        workingtree.WorkingTree.open('repo')
289
        repository.Repository.open('repo')
290
291
    def test_unshared_repo_to_lightweight_checkout(self):
292
        repo = self.make_repository('repo', shared=False)
293
        branch = self.make_branch('branch')
294
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
295
            repo.bzrdir, 'branch')
296
        reconfiguration.apply()
297
        workingtree.WorkingTree.open('repo')
298
        self.assertRaises(errors.NoRepositoryPresent,
299
                          repository.Repository.open, 'repo')
3311.2.1 by Aaron Bentley
Initial make-sharing functionality
300
3311.2.6 by Aaron Bentley
rename 'sharing' to 'use-shared'
301
    def test_standalone_to_use_shared(self):
3311.2.1 by Aaron Bentley
Initial make-sharing functionality
302
        self.build_tree(['root/'])
303
        tree = self.make_branch_and_tree('root/tree')
304
        tree.commit('Hello', rev_id='hello-id')
305
        repo = self.make_repository('root', shared=True)
3311.2.6 by Aaron Bentley
rename 'sharing' to 'use-shared'
306
        reconfiguration = reconfigure.Reconfigure.to_use_shared(tree.bzrdir)
3311.2.1 by Aaron Bentley
Initial make-sharing functionality
307
        reconfiguration.apply()
308
        tree = workingtree.WorkingTree.open('root/tree')
309
        self.assertTrue(repo.has_same_location(tree.branch.repository))
310
        self.assertEqual('Hello', repo.get_revision('hello-id').message)
3311.2.2 by Aaron Bentley
Flesh out to_sharing
311
3311.2.7 by Aaron Bentley
Get head preservation under test
312
    def add_dead_head(self, tree):
313
        revno, revision_id = tree.branch.last_revision_info()
314
        tree.commit('Dead head', rev_id='dead-head-id')
315
        tree.branch.set_last_revision_info(revno, revision_id)
316
        tree.set_last_revision(revision_id)
317
318
    def test_standalone_to_use_shared_preserves_dead_heads(self):
319
        self.build_tree(['root/'])
320
        tree = self.make_branch_and_tree('root/tree')
321
        self.add_dead_head(tree)
322
        tree.commit('Hello', rev_id='hello-id')
323
        repo = self.make_repository('root', shared=True)
324
        reconfiguration = reconfigure.Reconfigure.to_use_shared(tree.bzrdir)
325
        reconfiguration.apply()
326
        tree = workingtree.WorkingTree.open('root/tree')
327
        message = repo.get_revision('dead-head-id').message
328
        self.assertEqual('Dead head', message)
329
3311.2.6 by Aaron Bentley
rename 'sharing' to 'use-shared'
330
    def make_repository_tree(self):
3311.2.4 by Aaron Bentley
Implement conversion to standalone
331
        self.build_tree(['root/'])
332
        repo = self.make_repository('root', shared=True)
333
        tree = self.make_branch_and_tree('root/tree')
3311.2.6 by Aaron Bentley
rename 'sharing' to 'use-shared'
334
        reconfigure.Reconfigure.to_use_shared(tree.bzrdir).apply()
3311.2.4 by Aaron Bentley
Implement conversion to standalone
335
        return workingtree.WorkingTree.open('root/tree')
336
3311.2.6 by Aaron Bentley
rename 'sharing' to 'use-shared'
337
    def test_use_shared_to_use_shared(self):
338
        tree = self.make_repository_tree()
339
        self.assertRaises(errors.AlreadyUsingShared,
340
                          reconfigure.Reconfigure.to_use_shared, tree.bzrdir)
3311.2.4 by Aaron Bentley
Implement conversion to standalone
341
3311.2.6 by Aaron Bentley
rename 'sharing' to 'use-shared'
342
    def test_use_shared_to_standalone(self):
343
        tree = self.make_repository_tree()
3311.2.4 by Aaron Bentley
Implement conversion to standalone
344
        tree.commit('Hello', rev_id='hello-id')
345
        reconfigure.Reconfigure.to_standalone(tree.bzrdir).apply()
346
        tree = workingtree.WorkingTree.open('root/tree')
347
        repo = tree.branch.repository
348
        self.assertEqual(repo.bzrdir.root_transport.base,
349
                         tree.bzrdir.root_transport.base)
350
        self.assertEqual('Hello', repo.get_revision('hello-id').message)
351
3311.2.7 by Aaron Bentley
Get head preservation under test
352
    def test_use_shared_to_standalone_preserves_dead_heads(self):
353
        tree = self.make_repository_tree()
354
        self.add_dead_head(tree)
355
        tree.commit('Hello', rev_id='hello-id')
356
        reconfigure.Reconfigure.to_standalone(tree.bzrdir).apply()
357
        tree = workingtree.WorkingTree.open('root/tree')
358
        repo = tree.branch.repository
359
        self.assertRaises(errors.NoSuchRevision, repo.get_revision,
360
                          'dead-head-id')
361
3311.2.4 by Aaron Bentley
Implement conversion to standalone
362
    def test_standalone_to_standalone(self):
363
        tree = self.make_branch_and_tree('tree')
364
        self.assertRaises(errors.AlreadyStandalone,
365
                          reconfigure.Reconfigure.to_standalone, tree.bzrdir)
3338.1.3 by Aaron Bentley
Merge bzr.dev
366
3338.1.2 by Aaron Bentley
Split out tests even further
367
    def make_unsynced_branch_reconfiguration(self):
3338.1.1 by Aaron Bentley
Raise an error when converting a branch to a lightweight checkout loses data
368
        parent = self.make_branch_and_tree('parent')
369
        parent.commit('commit 1')
370
        child = parent.bzrdir.sprout('child').open_workingtree()
371
        child.commit('commit 2')
3338.1.2 by Aaron Bentley
Split out tests even further
372
        return reconfigure.Reconfigure.to_lightweight_checkout(child.bzrdir)
373
374
    def test_unsynced_branch_to_lightweight_checkout_unforced(self):
375
        reconfiguration = self.make_unsynced_branch_reconfiguration()
3338.1.1 by Aaron Bentley
Raise an error when converting a branch to a lightweight checkout loses data
376
        self.assertRaises(errors.UnsyncedBranches, reconfiguration.apply)
3338.1.2 by Aaron Bentley
Split out tests even further
377
378
    def test_unsynced_branch_to_lightweight_checkout_forced(self):
379
        reconfiguration = self.make_unsynced_branch_reconfiguration()
3338.1.1 by Aaron Bentley
Raise an error when converting a branch to a lightweight checkout loses data
380
        reconfiguration.apply(force=True)
3921.4.4 by Matthew Fuller
Add unit tests for Reconfigure.set_repository_trees().
381
382
    def make_repository_with_without_trees(self, with_trees):
383
        repo = self.make_repository('repo', shared=True)
384
        repo.set_make_working_trees(with_trees)
385
        return repo
386
387
    def test_make_with_trees(self):
388
        repo = self.make_repository_with_without_trees(False)
389
        reconfiguration = reconfigure.Reconfigure.set_repository_trees(
390
            repo.bzrdir, True)
391
        reconfiguration.apply()
3921.4.5 by Matthew Fuller
Add assertions to the unit tests to make sure the reconfiguration
392
        self.assertIs(True, repo.make_working_trees())
3921.4.4 by Matthew Fuller
Add unit tests for Reconfigure.set_repository_trees().
393
394
    def test_make_without_trees(self):
395
        repo = self.make_repository_with_without_trees(True)
396
        reconfiguration = reconfigure.Reconfigure.set_repository_trees(
397
            repo.bzrdir, False)
398
        reconfiguration.apply()
3921.4.5 by Matthew Fuller
Add assertions to the unit tests to make sure the reconfiguration
399
        self.assertIs(False, repo.make_working_trees())
3921.4.4 by Matthew Fuller
Add unit tests for Reconfigure.set_repository_trees().
400
401
    def test_make_with_trees_already_with_trees(self):
402
        repo = self.make_repository_with_without_trees(True)
3983.3.9 by Marius Kruger
check error message too
403
        e = self.assertRaises(errors.AlreadyWithTrees,
404
           reconfigure.Reconfigure.set_repository_trees, repo.bzrdir, True)
405
        self.assertContainsRe(str(e),
406
            r"Shared repository '.*' already creates working trees.")
3921.4.4 by Matthew Fuller
Add unit tests for Reconfigure.set_repository_trees().
407
408
    def test_make_without_trees_already_no_trees(self):
409
        repo = self.make_repository_with_without_trees(False)
3983.3.9 by Marius Kruger
check error message too
410
        e = self.assertRaises(errors.AlreadyWithNoTrees,
3921.4.4 by Matthew Fuller
Add unit tests for Reconfigure.set_repository_trees().
411
            reconfigure.Reconfigure.set_repository_trees, repo.bzrdir, False)
3983.3.9 by Marius Kruger
check error message too
412
        self.assertContainsRe(str(e),
413
            r"Shared repository '.*' already doesn't create working trees.")
3983.3.10 by Marius Kruger
add test_repository_tree_reconfiguration_not_supported
414
415
    def test_repository_tree_reconfiguration_not_supported(self):
416
        tree = self.make_branch_and_tree('tree')
417
        e = self.assertRaises(errors.ReconfigurationNotSupported,
418
            reconfigure.Reconfigure.set_repository_trees, tree.bzrdir, None)
419
        self.assertContainsRe(str(e),
420
            r"Requested reconfiguration of '.*' is not supported.")
4273.1.18 by Aaron Bentley
Reconfigure preserves reference locations.
421
422
    def test_lightweight_checkout_to_tree_preserves_reference_locations(self):
423
        format = bzrdir.format_registry.make_bzrdir('1.9')
424
        format.set_branch_format(_mod_branch.BzrBranchFormat8())
425
        tree = self.make_branch_and_tree('tree', format=format)
426
        tree.branch.set_reference_info('file_id', 'path', '../location')
427
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
428
        reconfiguration = reconfigure.Reconfigure.to_tree(checkout.bzrdir)
429
        reconfiguration.apply()
430
        checkout_branch = checkout.bzrdir.open_branch()
431
        self.assertEqual(('path', '../location'),
432
                         checkout_branch.get_reference_info('file_id'))