~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_reconfigure.py

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
 
1
# Copyright (C) 2007, 2008, 2009, 2011, 2012 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
16
16
 
17
17
from bzrlib import (
18
18
    branch as _mod_branch,
19
 
    bzrdir,
 
19
    controldir,
20
20
    errors,
21
21
    reconfigure,
22
22
    repository,
23
23
    tests,
 
24
    vf_repository,
24
25
    workingtree,
25
26
    )
26
27
 
44
45
        self.assertRaises(errors.NoWorkingTree, workingtree.WorkingTree.open,
45
46
                          'tree')
46
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
 
47
60
    def test_branch_to_branch(self):
48
61
        branch = self.make_branch('branch')
49
62
        self.assertRaises(errors.AlreadyBranch,
59
72
        checkout = branch.create_checkout('checkout')
60
73
        reconfiguration = reconfigure.Reconfigure.to_branch(checkout.bzrdir)
61
74
        reconfiguration.apply()
62
 
        self.assertIs(None, checkout.branch.get_bound_location())
 
75
        reconfigured = controldir.ControlDir.open('checkout').open_branch()
 
76
        self.assertIs(None, reconfigured.get_bound_location())
63
77
 
64
78
    def prepare_lightweight_checkout_to_branch(self):
65
79
        branch = self.make_branch('branch')
134
148
        self.assertRaises(errors.NoBindLocation,
135
149
                          reconfiguration._select_bind_location)
136
150
        branch.set_parent('http://parent')
 
151
        reconfiguration = reconfigure.Reconfigure(branch.bzrdir)
137
152
        self.assertEqual('http://parent',
138
153
                         reconfiguration._select_bind_location())
139
154
        branch.set_push_location('sftp://push')
 
155
        reconfiguration = reconfigure.Reconfigure(branch.bzrdir)
140
156
        self.assertEqual('sftp://push',
141
157
                         reconfiguration._select_bind_location())
142
 
        branch.set_bound_location('bzr://foo/old-bound')
143
 
        branch.set_bound_location(None)
 
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)
144
165
        self.assertEqual('bzr://foo/old-bound',
145
166
                         reconfiguration._select_bind_location())
146
167
        branch.set_bound_location('bzr://foo/cur-bound')
 
168
        reconfiguration = reconfigure.Reconfigure(branch.bzrdir)
147
169
        self.assertEqual('bzr://foo/cur-bound',
148
170
                         reconfiguration._select_bind_location())
149
171
        reconfiguration.new_bound_location = 'ftp://user-specified'
167
189
        self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
168
190
        # setting a parent allows it to become a checkout
169
191
        tree.branch.set_parent(parent.base)
 
192
        reconfiguration = reconfigure.Reconfigure.to_checkout(tree.bzrdir)
170
193
        reconfiguration.apply()
171
194
        # supplying a location allows it to become a checkout
172
195
        tree2 = self.make_branch_and_tree('tree2')
185
208
        self.assertRaises(errors.NoBindLocation, reconfiguration.apply)
186
209
        # setting a parent allows it to become a checkout
187
210
        tree.branch.set_parent(parent.base)
 
211
        reconfiguration = reconfigure.Reconfigure.to_lightweight_checkout(
 
212
            tree.bzrdir)
188
213
        reconfiguration.apply()
189
214
        # supplying a location allows it to become a checkout
190
215
        tree2 = self.make_branch_and_tree('tree2')
246
271
    def test_branch_to_lightweight_checkout_failure(self):
247
272
        parent, child, reconfiguration = \
248
273
            self.prepare_branch_to_lightweight_checkout()
249
 
        old_Repository_fetch = repository.Repository.fetch
250
 
        repository.Repository.fetch = None
 
274
        old_Repository_fetch = vf_repository.VersionedFileRepository.fetch
 
275
        vf_repository.VersionedFileRepository.fetch = None
251
276
        try:
252
277
            self.assertRaises(TypeError, reconfiguration.apply)
253
278
        finally:
254
 
            repository.Repository.fetch = old_Repository_fetch
 
279
            vf_repository.VersionedFileRepository.fetch = old_Repository_fetch
255
280
        child = _mod_branch.Branch.open('child')
256
281
        self.assertContainsRe(child.base, 'child/$')
257
282
 
420
445
            r"Requested reconfiguration of '.*' is not supported.")
421
446
 
422
447
    def test_lightweight_checkout_to_tree_preserves_reference_locations(self):
423
 
        format = bzrdir.format_registry.make_bzrdir('1.9')
 
448
        format = controldir.format_registry.make_bzrdir('1.9')
424
449
        format.set_branch_format(_mod_branch.BzrBranchFormat8())
425
450
        tree = self.make_branch_and_tree('tree', format=format)
426
451
        tree.branch.set_reference_info('file_id', 'path', '../location')