/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_reconfigure.py

  • Committer: Martin Pool
  • Date: 2007-10-03 08:06:44 UTC
  • mto: This revision was merged to the branch mainline in revision 2901.
  • Revision ID: mbp@sourcefrog.net-20071003080644-oivy0gkg98sex0ed
Avoid internal error tracebacks on failure to lock on readonly transport (#129701).

Add new LockFailed, which doesn't imply that we failed to get it because of
contention.  Raise this if we fail to create the pending or lock directories
because of Transport errors.

UnlockableTransport is not an internal error.

ReadOnlyLockError has a message which didn't match its name or usage; it's now
deprecated and callers are updated to use LockFailed which is more appropriate.

Add zero_ninetytwo deprecation symbol.

Unify assertMatchesRe with TestCase.assertContainsRe.

When the constructor is deprecated, just say that the class is deprecated, not
the __init__ method - this works better with applyDeprecated in tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2009 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
 
    bzrdir,
19
18
    errors,
20
19
    tests,
21
20
    workingtree,
22
21
    )
23
 
from bzrlib.branchbuilder import BranchBuilder
24
22
 
25
23
 
26
24
class TestReconfigure(tests.TestCaseWithTransport):
59
57
        checkout = branch.create_checkout('checkout', lightweight=True)
60
58
        self.run_bzr('reconfigure --checkout checkout')
61
59
 
62
 
    def test_lightweight_checkout_to_tree(self):
63
 
        branch = self.make_branch('branch')
64
 
        checkout = branch.create_checkout('checkout', lightweight=True)
65
 
        self.run_bzr('reconfigure --tree checkout')
66
 
 
67
60
    def test_no_args(self):
68
61
        branch = self.make_branch('branch')
69
62
        self.run_bzr_error(['No target configuration specified'],
70
63
                           'reconfigure', working_dir='branch')
71
 
 
72
 
    def test_checkout_to_lightweight_checkout(self):
73
 
        branch = self.make_branch('branch')
74
 
        checkout = branch.create_checkout('checkout')
75
 
        self.run_bzr('reconfigure --lightweight-checkout checkout')
76
 
 
77
 
    def test_standalone_to_use_shared(self):
78
 
        self.build_tree(['repo/'])
79
 
        tree = self.make_branch_and_tree('repo/tree')
80
 
        repo = self.make_repository('repo', shared=True)
81
 
        self.run_bzr('reconfigure --use-shared', working_dir='repo/tree')
82
 
        tree = workingtree.WorkingTree.open('repo/tree')
83
 
        self.assertNotEqual(tree.bzrdir.root_transport.base,
84
 
            tree.branch.repository.bzrdir.root_transport.base)
85
 
 
86
 
    def test_use_shared_to_standalone(self):
87
 
        repo = self.make_repository('repo', shared=True)
88
 
        branch = bzrdir.BzrDir.create_branch_convenience('repo/tree')
89
 
        self.assertNotEqual(branch.bzrdir.root_transport.base,
90
 
            branch.repository.bzrdir.root_transport.base)
91
 
        self.run_bzr('reconfigure --standalone', working_dir='repo/tree')
92
 
        tree = workingtree.WorkingTree.open('repo/tree')
93
 
        self.assertEqual(tree.bzrdir.root_transport.base,
94
 
            tree.branch.repository.bzrdir.root_transport.base)
95
 
 
96
 
    def test_make_with_trees(self):
97
 
        repo = self.make_repository('repo', shared=True)
98
 
        repo.set_make_working_trees(False)
99
 
        self.run_bzr('reconfigure --with-trees', working_dir='repo')
100
 
        self.assertIs(True, repo.make_working_trees())
101
 
 
102
 
    def test_make_with_trees_already_trees(self):
103
 
        repo = self.make_repository('repo', shared=True)
104
 
        repo.set_make_working_trees(True)
105
 
        self.run_bzr_error([" already creates working trees"],
106
 
                            'reconfigure --with-trees repo')
107
 
 
108
 
    def test_make_without_trees(self):
109
 
        repo = self.make_repository('repo', shared=True)
110
 
        repo.set_make_working_trees(True)
111
 
        self.run_bzr('reconfigure --with-no-trees', working_dir='repo')
112
 
        self.assertIs(False, repo.make_working_trees())
113
 
 
114
 
    def test_make_without_trees_already_no_trees(self):
115
 
        repo = self.make_repository('repo', shared=True)
116
 
        repo.set_make_working_trees(False)
117
 
        self.run_bzr_error([" already doesn't create working trees"],
118
 
                            'reconfigure --with-no-trees repo')
119
 
 
120
 
    def test_make_with_trees_nonshared_repo(self):
121
 
        branch = self.make_branch('branch')
122
 
        self.run_bzr_error(
123
 
            ["Requested reconfiguration of '.*' is not supported"],
124
 
            'reconfigure --with-trees branch')
125
 
 
126
 
    def test_make_without_trees_leaves_tree_alone(self):
127
 
        repo = self.make_repository('repo', shared=True)
128
 
        branch = bzrdir.BzrDir.create_branch_convenience('repo/branch')
129
 
        tree = workingtree.WorkingTree.open('repo/branch')
130
 
        self.build_tree(['repo/branch/foo'])
131
 
        tree.add('foo')
132
 
        self.run_bzr('reconfigure --with-no-trees --force',
133
 
            working_dir='repo/branch')
134
 
        self.failUnlessExists('repo/branch/foo')
135
 
        tree = workingtree.WorkingTree.open('repo/branch')
136
 
 
137
 
    def test_shared_format_to_standalone(self, format=None):
138
 
        repo = self.make_repository('repo', shared=True, format=format)
139
 
        branch = bzrdir.BzrDir.create_branch_convenience('repo/tree')
140
 
        self.assertNotEqual(branch.bzrdir.root_transport.base,
141
 
            branch.repository.bzrdir.root_transport.base)
142
 
        tree = workingtree.WorkingTree.open('repo/tree')
143
 
        self.build_tree_contents([('repo/tree/file', 'foo\n')]);
144
 
        tree.add(['file'])
145
 
        tree.commit('added file')
146
 
        self.run_bzr('reconfigure --standalone', working_dir='repo/tree')
147
 
        tree = workingtree.WorkingTree.open('repo/tree')
148
 
        self.build_tree_contents([('repo/tree/file', 'bar\n')]);
149
 
        self.check_file_contents('repo/tree/file', 'bar\n')
150
 
        self.run_bzr('revert', working_dir='repo/tree')
151
 
        self.check_file_contents('repo/tree/file', 'foo\n')
152
 
        self.assertEqual(tree.bzrdir.root_transport.base,
153
 
            tree.branch.repository.bzrdir.root_transport.base)
154
 
 
155
 
    def test_shared_knit_to_standalone(self):
156
 
        self.test_shared_format_to_standalone('knit')
157
 
 
158
 
    def test_shared_pack092_to_standalone(self):
159
 
        self.test_shared_format_to_standalone('pack-0.92')
160
 
 
161
 
    def test_shared_rich_root_pack_to_standalone(self):
162
 
        self.test_shared_format_to_standalone('rich-root-pack')
163
 
 
164
 
    def test_lightweight_format_checkout_to_tree(self, format=None):
165
 
        branch = self.make_branch('branch', format=format)
166
 
        checkout = branch.create_checkout('checkout', lightweight=True)
167
 
        tree = workingtree.WorkingTree.open('checkout')
168
 
        self.build_tree_contents([('checkout/file', 'foo\n')]);
169
 
        tree.add(['file'])
170
 
        tree.commit('added file')
171
 
        self.run_bzr('reconfigure --tree', working_dir='checkout')
172
 
        tree = workingtree.WorkingTree.open('checkout')
173
 
        self.build_tree_contents([('checkout/file', 'bar\n')]);
174
 
        self.check_file_contents('checkout/file', 'bar\n')
175
 
        self.run_bzr('revert', working_dir='checkout')
176
 
        self.check_file_contents('checkout/file', 'foo\n')
177
 
 
178
 
    def test_lightweight_knit_checkout_to_tree(self, format=None):
179
 
        self.test_lightweight_format_checkout_to_tree('knit')
180
 
 
181
 
    def test_lightweight_pack092_checkout_to_tree(self, format=None):
182
 
        self.test_lightweight_format_checkout_to_tree('pack-0.92')
183
 
 
184
 
    def test_lightweight_rich_root_pack_checkout_to_tree(self, format=None):
185
 
        self.test_lightweight_format_checkout_to_tree('rich-root-pack')
186
 
 
187
 
 
188
 
class TestReconfigureStacking(tests.TestCaseWithTransport):
189
 
 
190
 
    def test_reconfigure_stacking(self):
191
 
        """Test a fairly realistic scenario for stacking:
192
 
 
193
 
         * make a branch with some history
194
 
         * branch it
195
 
         * make the second branch stacked on the first
196
 
         * commit in the second
197
 
         * then make the second unstacked, so it has to fill in history from
198
 
           the original fallback lying underneath its original content
199
 
 
200
 
        See discussion in <https://bugs.edge.launchpad.net/bzr/+bug/391411>
201
 
        """
202
 
        # there are also per_branch tests that exercise remote operation etc
203
 
        tree_1 = self.make_branch_and_tree('b1', format='2a')
204
 
        self.build_tree(['b1/foo'])
205
 
        tree_1.add(['foo'])
206
 
        tree_1.commit('add foo')
207
 
        branch_1 = tree_1.branch
208
 
        # now branch and commit again
209
 
        bzrdir_2 = tree_1.bzrdir.sprout('b2')
210
 
        tree_2 = bzrdir_2.open_workingtree()
211
 
        branch_2 = tree_2.branch
212
 
        # now reconfigure to be stacked
213
 
        out, err = self.run_bzr('reconfigure --stacked-on b1 b2')
214
 
        self.assertContainsRe(out,
215
 
            '^.*/b2/ is now stacked on ../b1\n$')
216
 
        self.assertEquals('', err)
217
 
        # can also give the absolute URL of the branch, and it gets stored 
218
 
        # as a relative path if possible
219
 
        out, err = self.run_bzr('reconfigure --stacked-on %s b2'
220
 
            % (self.get_url('b1'),))
221
 
        self.assertContainsRe(out,
222
 
            '^.*/b2/ is now stacked on ../b1\n$')
223
 
        self.assertEquals('', err)
224
 
        # It should be given a relative URL to the destination, if possible,
225
 
        # because that's most likely to work across different transports
226
 
        self.assertEquals(branch_2.get_stacked_on_url(),
227
 
            '../b1')
228
 
        # commit, and it should be stored into b2's repo
229
 
        self.build_tree_contents([('foo', 'new foo')])
230
 
        tree_2.commit('update foo')
231
 
        # Now turn it off again
232
 
        out, err = self.run_bzr('reconfigure --unstacked b2')
233
 
        self.assertContainsRe(out,
234
 
            '^.*/b2/ is now not stacked\n$')
235
 
        self.assertEquals('', err)
236
 
        self.assertRaises(errors.NotStacked,
237
 
            branch_2.get_stacked_on_url)
238
 
 
239
 
    # XXX: Needs a test for reconfiguring stacking and shape at the same time;
240
 
    # no branch at location; stacked-on is not a branch; quiet mode.
241
 
    # -- mbp 20090706