~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_reconfigure.py

  • Committer: Jelmer Vernooij
  • Date: 2012-01-27 19:05:43 UTC
  • mto: This revision was merged to the branch mainline in revision 6450.
  • Revision ID: jelmer@samba.org-20120127190543-vk350mv4a0c7aug2
Fix weave test.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
 
1
# Copyright (C) 2007, 2008, 2009 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
from bzrlib import (
18
18
    branch as _mod_branch,
 
19
    bzrdir,
19
20
    errors,
20
21
    reconfigure,
21
22
    repository,
22
23
    tests,
 
24
    vf_repository,
23
25
    workingtree,
24
26
    )
25
27
 
43
45
        self.assertRaises(errors.NoWorkingTree, workingtree.WorkingTree.open,
44
46
                          'tree')
45
47
 
 
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
 
46
60
    def test_branch_to_branch(self):
47
61
        branch = self.make_branch('branch')
48
62
        self.assertRaises(errors.AlreadyBranch,
245
259
    def test_branch_to_lightweight_checkout_failure(self):
246
260
        parent, child, reconfiguration = \
247
261
            self.prepare_branch_to_lightweight_checkout()
248
 
        old_Repository_fetch = repository.Repository.fetch
249
 
        repository.Repository.fetch = None
 
262
        old_Repository_fetch = vf_repository.VersionedFileRepository.fetch
 
263
        vf_repository.VersionedFileRepository.fetch = None
250
264
        try:
251
265
            self.assertRaises(TypeError, reconfiguration.apply)
252
266
        finally:
253
 
            repository.Repository.fetch = old_Repository_fetch
 
267
            vf_repository.VersionedFileRepository.fetch = old_Repository_fetch
254
268
        child = _mod_branch.Branch.open('child')
255
269
        self.assertContainsRe(child.base, 'child/$')
256
270
 
377
391
    def test_unsynced_branch_to_lightweight_checkout_forced(self):
378
392
        reconfiguration = self.make_unsynced_branch_reconfiguration()
379
393
        reconfiguration.apply(force=True)
 
394
 
 
395
    def make_repository_with_without_trees(self, with_trees):
 
396
        repo = self.make_repository('repo', shared=True)
 
397
        repo.set_make_working_trees(with_trees)
 
398
        return repo
 
399
 
 
400
    def test_make_with_trees(self):
 
401
        repo = self.make_repository_with_without_trees(False)
 
402
        reconfiguration = reconfigure.Reconfigure.set_repository_trees(
 
403
            repo.bzrdir, True)
 
404
        reconfiguration.apply()
 
405
        self.assertIs(True, repo.make_working_trees())
 
406
 
 
407
    def test_make_without_trees(self):
 
408
        repo = self.make_repository_with_without_trees(True)
 
409
        reconfiguration = reconfigure.Reconfigure.set_repository_trees(
 
410
            repo.bzrdir, False)
 
411
        reconfiguration.apply()
 
412
        self.assertIs(False, repo.make_working_trees())
 
413
 
 
414
    def test_make_with_trees_already_with_trees(self):
 
415
        repo = self.make_repository_with_without_trees(True)
 
416
        e = self.assertRaises(errors.AlreadyWithTrees,
 
417
           reconfigure.Reconfigure.set_repository_trees, repo.bzrdir, True)
 
418
        self.assertContainsRe(str(e),
 
419
            r"Shared repository '.*' already creates working trees.")
 
420
 
 
421
    def test_make_without_trees_already_no_trees(self):
 
422
        repo = self.make_repository_with_without_trees(False)
 
423
        e = self.assertRaises(errors.AlreadyWithNoTrees,
 
424
            reconfigure.Reconfigure.set_repository_trees, repo.bzrdir, False)
 
425
        self.assertContainsRe(str(e),
 
426
            r"Shared repository '.*' already doesn't create working trees.")
 
427
 
 
428
    def test_repository_tree_reconfiguration_not_supported(self):
 
429
        tree = self.make_branch_and_tree('tree')
 
430
        e = self.assertRaises(errors.ReconfigurationNotSupported,
 
431
            reconfigure.Reconfigure.set_repository_trees, tree.bzrdir, None)
 
432
        self.assertContainsRe(str(e),
 
433
            r"Requested reconfiguration of '.*' is not supported.")
 
434
 
 
435
    def test_lightweight_checkout_to_tree_preserves_reference_locations(self):
 
436
        format = bzrdir.format_registry.make_bzrdir('1.9')
 
437
        format.set_branch_format(_mod_branch.BzrBranchFormat8())
 
438
        tree = self.make_branch_and_tree('tree', format=format)
 
439
        tree.branch.set_reference_info('file_id', 'path', '../location')
 
440
        checkout = tree.branch.create_checkout('checkout', lightweight=True)
 
441
        reconfiguration = reconfigure.Reconfigure.to_tree(checkout.bzrdir)
 
442
        reconfiguration.apply()
 
443
        checkout_branch = checkout.bzrdir.open_branch()
 
444
        self.assertEqual(('path', '../location'),
 
445
                         checkout_branch.get_reference_info('file_id'))