~bzr-pqm/bzr/bzr.dev

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