/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: Vincent Ladeuil
  • Date: 2012-01-05 14:26:58 UTC
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120105142658-vek3v6pzlxb751s2
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made. 

@only_raises is evil and gave a hard time since any exception during
save_changes() was swallowed.

Possible improvements: 

- add some needs_write_lock decorators to crucial
  methods (_set_config_location ?) but keep locking the branch at higher levels

- decorate branch.unlock to call stack.save if last_lock() it True
  outside of @only_raises scope (evil decorator)

- add @needs_write_lock to stack.set and stack.remove (will probably get
  rid of most testing issues) we probably need a specialized decorator
  that can relay to the store and from there to the branch or whatever is
  needed. This will also helps bzr config to get it right. The
  get_mutable_section trick should not be needed anymore either.

- decorate branch.unlock to call stack.save if last_lock() it True outside
  of @only_raises scope (evil decorator)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2009 Canonical Ltd
 
1
# Copyright (C) 2007-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
21
21
    workingtree,
22
22
    )
23
23
from bzrlib.branchbuilder import BranchBuilder
24
 
 
25
 
 
26
 
class TestReconfigure(tests.TestCaseWithTransport):
 
24
from bzrlib.tests.script import TestCaseWithTransportAndScript
 
25
 
 
26
 
 
27
class TestReconfigure(TestCaseWithTransportAndScript):
27
28
 
28
29
    def test_no_type(self):
29
30
        branch = self.make_branch('branch')
131
132
        tree.add('foo')
132
133
        self.run_bzr('reconfigure --with-no-trees --force',
133
134
            working_dir='repo/branch')
134
 
        self.failUnlessExists('repo/branch/foo')
 
135
        self.assertPathExists('repo/branch/foo')
135
136
        tree = workingtree.WorkingTree.open('repo/branch')
136
137
 
137
138
    def test_shared_format_to_standalone(self, format=None):
175
176
        self.run_bzr('revert', working_dir='checkout')
176
177
        self.check_file_contents('checkout/file', 'foo\n')
177
178
 
178
 
    def test_lightweight_knit_checkout_to_tree(self, format=None):
 
179
    def test_lightweight_knit_checkout_to_tree(self):
179
180
        self.test_lightweight_format_checkout_to_tree('knit')
180
181
 
181
 
    def test_lightweight_pack092_checkout_to_tree(self, format=None):
 
182
    def test_lightweight_pack092_checkout_to_tree(self):
182
183
        self.test_lightweight_format_checkout_to_tree('pack-0.92')
183
184
 
184
 
    def test_lightweight_rich_root_pack_checkout_to_tree(self, format=None):
 
185
    def test_lightweight_rich_root_pack_checkout_to_tree(self):
185
186
        self.test_lightweight_format_checkout_to_tree('rich-root-pack')
186
187
 
 
188
    def test_branch_and_use_shared(self):
 
189
        self.run_script("""\
 
190
$ bzr init -q branch
 
191
$ echo foo > branch/foo
 
192
$ bzr add -q branch/foo
 
193
$ bzr commit -q -m msg branch
 
194
$ bzr init-repo -q .
 
195
$ bzr reconfigure --branch --use-shared branch
 
196
$ bzr info branch
 
197
Repository branch (format: ...)
 
198
Location:
 
199
  shared repository: .
 
200
  repository branch: branch
 
201
""")
 
202
 
 
203
    def test_use_shared_and_branch(self):
 
204
        self.run_script("""\
 
205
$ bzr init -q branch
 
206
$ echo foo > branch/foo
 
207
$ bzr add -q branch/foo
 
208
$ bzr commit -q -m msg branch
 
209
$ bzr init-repo -q .
 
210
$ bzr reconfigure --use-shared --branch branch
 
211
$ bzr info branch
 
212
Repository branch (format: ...)
 
213
Location:
 
214
  shared repository: .
 
215
  repository branch: branch
 
216
""")
 
217
 
187
218
 
188
219
class TestReconfigureStacking(tests.TestCaseWithTransport):
189
220
 
197
228
         * then make the second unstacked, so it has to fill in history from
198
229
           the original fallback lying underneath its original content
199
230
 
200
 
        See discussion in <https://bugs.edge.launchpad.net/bzr/+bug/391411>
 
231
        See discussion in <https://bugs.launchpad.net/bzr/+bug/391411>
201
232
        """
202
233
        # there are also per_branch tests that exercise remote operation etc
203
234
        tree_1 = self.make_branch_and_tree('b1', format='2a')
211
242
        branch_2 = tree_2.branch
212
243
        # now reconfigure to be stacked
213
244
        out, err = self.run_bzr('reconfigure --stacked-on b1 b2')
214
 
        self.assertContainsRe(out,
215
 
            '^.*/b2/ is now stacked on ../b1\n$')
 
245
        self.assertContainsRe(out, '^.*/b2/ is now stacked on ../b1\n$')
216
246
        self.assertEquals('', err)
217
247
        # can also give the absolute URL of the branch, and it gets stored 
218
248
        # as a relative path if possible
219
249
        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$')
 
250
                                % (self.get_url('b1'),))
 
251
        self.assertContainsRe(out, '^.*/b2/ is now stacked on ../b1\n$')
223
252
        self.assertEquals('', err)
 
253
        b2 = bzrdir.BzrDir.open('b2').open_branch()
224
254
        # It should be given a relative URL to the destination, if possible,
225
255
        # because that's most likely to work across different transports
226
 
        self.assertEquals(branch_2.get_stacked_on_url(),
227
 
            '../b1')
 
256
        self.assertEquals('../b1', b2.get_stacked_on_url())
228
257
        # commit, and it should be stored into b2's repo
229
258
        self.build_tree_contents([('foo', 'new foo')])
230
259
        tree_2.commit('update foo')
233
262
        self.assertContainsRe(out,
234
263
            '^.*/b2/ is now not stacked\n$')
235
264
        self.assertEquals('', err)
236
 
        self.assertRaises(errors.NotStacked,
237
 
            branch_2.get_stacked_on_url)
 
265
        b2 = bzrdir.BzrDir.open('b2').open_branch()
 
266
        self.assertRaises(errors.NotStacked, b2.get_stacked_on_url)
238
267
 
239
268
    # XXX: Needs a test for reconfiguring stacking and shape at the same time;
240
269
    # no branch at location; stacked-on is not a branch; quiet mode.