~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_reconfigure.py

  • Committer: John Arbash Meinel
  • Author(s): Mark Hammond
  • Date: 2008-09-09 17:02:21 UTC
  • mto: This revision was merged to the branch mainline in revision 3697.
  • Revision ID: john@arbash-meinel.com-20080909170221-svim3jw2mrz0amp3
An updated transparent icon for bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2008, 2009, 2011, 2012 Canonical Ltd
 
1
# Copyright (C) 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
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
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
from bzrlib import (
18
18
    branch as _mod_branch,
19
 
    controldir,
20
19
    errors,
21
20
    reconfigure,
22
21
    repository,
23
22
    tests,
24
 
    vf_repository,
25
23
    workingtree,
26
24
    )
27
25
 
45
43
        self.assertRaises(errors.NoWorkingTree, workingtree.WorkingTree.open,
46
44
                          'tree')
47
45
 
48
 
    def test_tree_with_pending_merge_to_branch(self):
49
 
        tree = self.make_branch_and_tree('tree')
50
 
        tree.commit('unchanged')
51
 
        other_tree = tree.bzrdir.sprout('other').open_workingtree()
52
 
        other_tree.commit('mergeable commit')
53
 
        tree.merge_from_branch(other_tree.branch)
54
 
        reconfiguration = reconfigure.Reconfigure.to_branch(tree.bzrdir)
55
 
        self.assertRaises(errors.UncommittedChanges, reconfiguration.apply)
56
 
        reconfiguration.apply(force=True)
57
 
        self.assertRaises(errors.NoWorkingTree, workingtree.WorkingTree.open,
58
 
                          'tree')
59
 
 
60
46
    def test_branch_to_branch(self):
61
47
        branch = self.make_branch('branch')
62
48
        self.assertRaises(errors.AlreadyBranch,
72
58
        checkout = branch.create_checkout('checkout')
73
59
        reconfiguration = reconfigure.Reconfigure.to_branch(checkout.bzrdir)
74
60
        reconfiguration.apply()
75
 
        reconfigured = controldir.ControlDir.open('checkout').open_branch()
76
 
        self.assertIs(None, reconfigured.get_bound_location())
 
61
        self.assertIs(None, checkout.branch.get_bound_location())
77
62
 
78
63
    def prepare_lightweight_checkout_to_branch(self):
79
64
        branch = self.make_branch('branch')
148
133
        self.assertRaises(errors.NoBindLocation,
149
134
                          reconfiguration._select_bind_location)
150
135
        branch.set_parent('http://parent')
151
 
        reconfiguration = reconfigure.Reconfigure(branch.bzrdir)
152
136
        self.assertEqual('http://parent',
153
137
                         reconfiguration._select_bind_location())
154
138
        branch.set_push_location('sftp://push')
155
 
        reconfiguration = reconfigure.Reconfigure(branch.bzrdir)
156
139
        self.assertEqual('sftp://push',
157
140
                         reconfiguration._select_bind_location())
158
 
        branch.lock_write()
159
 
        try:
160
 
            branch.set_bound_location('bzr://foo/old-bound')
161
 
            branch.set_bound_location(None)
162
 
        finally:
163
 
            branch.unlock()
164
 
        reconfiguration = reconfigure.Reconfigure(branch.bzrdir)
 
141
        branch.set_bound_location('bzr://foo/old-bound')
 
142
        branch.set_bound_location(None)
165
143
        self.assertEqual('bzr://foo/old-bound',
166
144
                         reconfiguration._select_bind_location())
167
145
        branch.set_bound_location('bzr://foo/cur-bound')
168
 
        reconfiguration = reconfigure.Reconfigure(branch.bzrdir)
169
146
        self.assertEqual('bzr://foo/cur-bound',
170
147
                         reconfiguration._select_bind_location())
171
148
        reconfiguration.new_bound_location = 'ftp://user-specified'
189
166
        self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
190
167
        # setting a parent allows it to become a checkout
191
168
        tree.branch.set_parent(parent.base)
192
 
        reconfiguration = reconfigure.Reconfigure.to_checkout(tree.bzrdir)
193
169
        reconfiguration.apply()
194
170
        # supplying a location allows it to become a checkout
195
171
        tree2 = self.make_branch_and_tree('tree2')
208
184
        self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
209
185
        # setting a parent allows it to become a checkout
210
186
        tree.branch.set_parent(parent.base)
211
 
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
212
 
            tree.bzrdir)
213
187
        reconfiguration.apply()
214
188
        # supplying a location allows it to become a checkout
215
189
        tree2 = self.make_branch_and_tree('tree2')
271
245
    def test_branch_to_lightweight_checkout_failure(self):
272
246
        parent, child, reconfiguration = \
273
247
            self.prepare_branch_to_lightweight_checkout()
274
 
        old_Repository_fetch = vf_repository.VersionedFileRepository.fetch
275
 
        vf_repository.VersionedFileRepository.fetch = None
 
248
        old_Repository_fetch = repository.Repository.fetch
 
249
        repository.Repository.fetch = None
276
250
        try:
277
251
            self.assertRaises(TypeError, reconfiguration.apply)
278
252
        finally:
279
 
            vf_repository.VersionedFileRepository.fetch = old_Repository_fetch
 
253
            repository.Repository.fetch = old_Repository_fetch
280
254
        child = _mod_branch.Branch.open('child')
281
255
        self.assertContainsRe(child.base, 'child/$')
282
256
 
403
377
    def test_unsynced_branch_to_lightweight_checkout_forced(self):
404
378
        reconfiguration = self.make_unsynced_branch_reconfiguration()
405
379
        reconfiguration.apply(force=True)
406
 
 
407
 
    def make_repository_with_without_trees(self, with_trees):
408
 
        repo = self.make_repository('repo', shared=True)
409
 
        repo.set_make_working_trees(with_trees)
410
 
        return repo
411
 
 
412
 
    def test_make_with_trees(self):
413
 
        repo = self.make_repository_with_without_trees(False)
414
 
        reconfiguration = reconfigure.Reconfigure.set_repository_trees(
415
 
            repo.bzrdir, True)
416
 
        reconfiguration.apply()
417
 
        self.assertIs(True, repo.make_working_trees())
418
 
 
419
 
    def test_make_without_trees(self):
420
 
        repo = self.make_repository_with_without_trees(True)
421
 
        reconfiguration = reconfigure.Reconfigure.set_repository_trees(
422
 
            repo.bzrdir, False)
423
 
        reconfiguration.apply()
424
 
        self.assertIs(False, repo.make_working_trees())
425
 
 
426
 
    def test_make_with_trees_already_with_trees(self):
427
 
        repo = self.make_repository_with_without_trees(True)
428
 
        e = self.assertRaises(errors.AlreadyWithTrees,
429
 
           reconfigure.Reconfigure.set_repository_trees, repo.bzrdir, True)
430
 
        self.assertContainsRe(str(e),
431
 
            r"Shared repository '.*' already creates working trees.")
432
 
 
433
 
    def test_make_without_trees_already_no_trees(self):
434
 
        repo = self.make_repository_with_without_trees(False)
435
 
        e = self.assertRaises(errors.AlreadyWithNoTrees,
436
 
            reconfigure.Reconfigure.set_repository_trees, repo.bzrdir, False)
437
 
        self.assertContainsRe(str(e),
438
 
            r"Shared repository '.*' already doesn't create working trees.")
439
 
 
440
 
    def test_repository_tree_reconfiguration_not_supported(self):
441
 
        tree = self.make_branch_and_tree('tree')
442
 
        e = self.assertRaises(errors.ReconfigurationNotSupported,
443
 
            reconfigure.Reconfigure.set_repository_trees, tree.bzrdir, None)
444
 
        self.assertContainsRe(str(e),
445
 
            r"Requested reconfiguration of '.*' is not supported.")
446
 
 
447
 
    def test_lightweight_checkout_to_tree_preserves_reference_locations(self):
448
 
        format = controldir.format_registry.make_bzrdir('1.9')
449
 
        format.set_branch_format(_mod_branch.BzrBranchFormat8())
450
 
        tree = self.make_branch_and_tree('tree', format=format)
451
 
        tree.branch.set_reference_info('file_id', 'path', '../location')
452
 
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
453
 
        reconfiguration = reconfigure.Reconfigure.to_tree(checkout.bzrdir)
454
 
        reconfiguration.apply()
455
 
        checkout_branch = checkout.bzrdir.open_branch()
456
 
        self.assertEqual(('path', '../location'),
457
 
                         checkout_branch.get_reference_info('file_id'))