~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_branch.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-07-14 08:21:19 UTC
  • mfrom: (3517.4.20 stacking)
  • Revision ID: pqm@pqm.ubuntu.com-20080714082119-ju6qe5weo8pp7f1c
merge integrated branch stacking

Show diffs side-by-side

added added

removed removed

Lines of Context:
201
201
        self.make_branch_and_tree('bar')
202
202
 
203
203
 
204
 
class TestBranch6(TestCaseWithTransport):
 
204
class TestBranch67(object):
 
205
    """Common tests for both branch 6 and 7 which are mostly the same."""
 
206
 
 
207
    def get_format_name(self):
 
208
        raise NotImplementedError(self.get_format_name)
 
209
 
 
210
    def get_format_name_subtree(self):
 
211
        raise NotImplementedError(self.get_format_name)
 
212
 
 
213
    def get_class(self):
 
214
        raise NotImplementedError(self.get_class)
205
215
 
206
216
    def test_creation(self):
207
217
        format = BzrDirMetaFormat1()
208
218
        format.set_branch_format(_mod_branch.BzrBranchFormat6())
209
219
        branch = self.make_branch('a', format=format)
210
 
        self.assertIsInstance(branch, _mod_branch.BzrBranch6)
211
 
        branch = self.make_branch('b', format='dirstate-tags')
212
 
        self.assertIsInstance(branch, _mod_branch.BzrBranch6)
 
220
        self.assertIsInstance(branch, self.get_class())
 
221
        branch = self.make_branch('b', format=self.get_format_name())
 
222
        self.assertIsInstance(branch, self.get_class())
213
223
        branch = _mod_branch.Branch.open('a')
214
 
        self.assertIsInstance(branch, _mod_branch.BzrBranch6)
 
224
        self.assertIsInstance(branch, self.get_class())
215
225
 
216
226
    def test_layout(self):
217
 
        branch = self.make_branch('a', format='dirstate-tags')
 
227
        branch = self.make_branch('a', format=self.get_format_name())
218
228
        self.failUnlessExists('a/.bzr/branch/last-revision')
219
229
        self.failIfExists('a/.bzr/branch/revision-history')
220
230
 
221
231
    def test_config(self):
222
232
        """Ensure that all configuration data is stored in the branch"""
223
 
        branch = self.make_branch('a', format='dirstate-tags')
 
233
        branch = self.make_branch('a', format=self.get_format_name())
224
234
        branch.set_parent('http://bazaar-vcs.org')
225
235
        self.failIfExists('a/.bzr/branch/parent')
226
236
        self.assertEqual('http://bazaar-vcs.org', branch.get_parent())
234
244
 
235
245
    def test_set_revision_history(self):
236
246
        tree = self.make_branch_and_memory_tree('.',
237
 
            format='dirstate-tags')
 
247
            format=self.get_format_name())
238
248
        tree.lock_write()
239
249
        try:
240
250
            tree.add('.')
248
258
            tree.unlock()
249
259
 
250
260
    def do_checkout_test(self, lightweight=False):
251
 
        tree = self.make_branch_and_tree('source', format='dirstate-with-subtree')
 
261
        tree = self.make_branch_and_tree('source',
 
262
            format=self.get_format_name_subtree())
252
263
        subtree = self.make_branch_and_tree('source/subtree',
253
 
            format='dirstate-with-subtree')
 
264
            format=self.get_format_name_subtree())
254
265
        subsubtree = self.make_branch_and_tree('source/subtree/subsubtree',
255
 
            format='dirstate-with-subtree')
 
266
            format=self.get_format_name_subtree())
256
267
        self.build_tree(['source/subtree/file',
257
268
                         'source/subtree/subsubtree/file'])
258
269
        subsubtree.add('file')
280
291
        self.do_checkout_test(lightweight=True)
281
292
 
282
293
    def test_set_push(self):
283
 
        branch = self.make_branch('source', format='dirstate-tags')
 
294
        branch = self.make_branch('source', format=self.get_format_name())
284
295
        branch.get_config().set_user_option('push_location', 'old',
285
296
            store=config.STORE_LOCATION)
286
297
        warnings = []
296
307
                         'locations.conf')
297
308
 
298
309
 
 
310
class TestBranch6(TestBranch67, TestCaseWithTransport):
 
311
 
 
312
    def get_class(self):
 
313
        return _mod_branch.BzrBranch6
 
314
 
 
315
    def get_format_name(self):
 
316
        return "dirstate-tags"
 
317
 
 
318
    def get_format_name_subtree(self):
 
319
        return "dirstate-with-subtree"
 
320
 
 
321
    def test_set_stacked_on_errors(self):
 
322
        branch = self.make_branch('a', format=self.get_format_name())
 
323
        self.assertRaises(errors.UnstackableBranchFormat,
 
324
            branch.set_stacked_on, None)
 
325
 
 
326
    def test_default_stacked_location(self):
 
327
        branch = self.make_branch('a', format=self.get_format_name())
 
328
        self.assertRaises(errors.UnstackableBranchFormat, branch.get_stacked_on)
 
329
 
 
330
 
 
331
class TestBranch7(TestBranch67, TestCaseWithTransport):
 
332
 
 
333
    def get_class(self):
 
334
        return _mod_branch.BzrBranch7
 
335
 
 
336
    def get_format_name(self):
 
337
        return "development"
 
338
 
 
339
    def get_format_name_subtree(self):
 
340
        return "development-subtree"
 
341
 
 
342
    def test_set_stacked_on_unstackable_repo(self):
 
343
        repo = self.make_repository('a', format='dirstate-tags')
 
344
        control = repo.bzrdir
 
345
        branch = _mod_branch.BzrBranchFormat7().initialize(control)
 
346
        target = self.make_branch('b')
 
347
        self.assertRaises(errors.UnstackableRepositoryFormat,
 
348
            branch.set_stacked_on, target.base)
 
349
 
 
350
    def _test_default_stacked_location(self):
 
351
        branch = self.make_branch('a', format=self.get_format_name())
 
352
        self.assertRaises(errors.NotStacked, branch.get_stacked_on)
 
353
 
 
354
    def test_stack_and_unstack(self):
 
355
        branch = self.make_branch('a', format=self.get_format_name())
 
356
        target = self.make_branch_and_tree('b', format=self.get_format_name())
 
357
        branch.set_stacked_on(target.branch.base)
 
358
        self.assertEqual(target.branch.base, branch.get_stacked_on())
 
359
        revid = target.commit('foo')
 
360
        self.assertTrue(branch.repository.has_revision(revid))
 
361
        branch.set_stacked_on(None)
 
362
        self.assertRaises(errors.NotStacked, branch.get_stacked_on)
 
363
        self.assertFalse(branch.repository.has_revision(revid))
 
364
 
 
365
    def test_open_opens_stacked_reference(self):
 
366
        branch = self.make_branch('a', format=self.get_format_name())
 
367
        target = self.make_branch_and_tree('b', format=self.get_format_name())
 
368
        branch.set_stacked_on(target.branch.base)
 
369
        branch = branch.bzrdir.open_branch()
 
370
        revid = target.commit('foo')
 
371
        self.assertTrue(branch.repository.has_revision(revid))
 
372
 
 
373
 
299
374
class TestBranchReference(TestCaseWithTransport):
300
375
    """Tests for the branch reference facility."""
301
376