~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_branch.py

  • Committer: Aaron Bentley
  • Date: 2007-12-25 04:17:50 UTC
  • mto: This revision was merged to the branch mainline in revision 3160.
  • Revision ID: aaron.bentley@utoronto.ca-20071225041750-t6chr3pmgnebvqcz
Handle non-directory parent conflicts (abentley, #177390)

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
from bzrlib.tests import TestCase, TestCaseWithTransport
54
54
from bzrlib.transport import get_transport
55
55
 
56
 
 
57
56
class TestDefaultFormat(TestCase):
58
57
 
59
58
    def test_default_format(self):
123
122
        self.assertFileEqual("# comment\n"
124
123
                             "[%s]\n"
125
124
                             "push_location = foo\n"
126
 
                             "push_location:policy = norecurse\n" % local_path,
 
125
                             "push_location:policy = norecurse" % local_path,
127
126
                             fn)
128
127
 
129
128
    # TODO RBC 20051029 test getting a push location from a branch in a
201
200
        self.make_branch_and_tree('bar')
202
201
 
203
202
 
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)
 
203
class TestBranch6(TestCaseWithTransport):
215
204
 
216
205
    def test_creation(self):
217
206
        format = BzrDirMetaFormat1()
218
207
        format.set_branch_format(_mod_branch.BzrBranchFormat6())
219
208
        branch = self.make_branch('a', format=format)
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())
 
209
        self.assertIsInstance(branch, _mod_branch.BzrBranch6)
 
210
        branch = self.make_branch('b', format='dirstate-tags')
 
211
        self.assertIsInstance(branch, _mod_branch.BzrBranch6)
223
212
        branch = _mod_branch.Branch.open('a')
224
 
        self.assertIsInstance(branch, self.get_class())
 
213
        self.assertIsInstance(branch, _mod_branch.BzrBranch6)
225
214
 
226
215
    def test_layout(self):
227
 
        branch = self.make_branch('a', format=self.get_format_name())
 
216
        branch = self.make_branch('a', format='dirstate-tags')
228
217
        self.failUnlessExists('a/.bzr/branch/last-revision')
229
218
        self.failIfExists('a/.bzr/branch/revision-history')
230
219
 
231
220
    def test_config(self):
232
221
        """Ensure that all configuration data is stored in the branch"""
233
 
        branch = self.make_branch('a', format=self.get_format_name())
 
222
        branch = self.make_branch('a', format='dirstate-tags')
234
223
        branch.set_parent('http://bazaar-vcs.org')
235
224
        self.failIfExists('a/.bzr/branch/parent')
236
225
        self.assertEqual('http://bazaar-vcs.org', branch.get_parent())
243
232
        self.assertEqual('ftp://bazaar-vcs.org', branch.get_bound_location())
244
233
 
245
234
    def test_set_revision_history(self):
246
 
        builder = self.make_branch_builder('.', format=self.get_format_name())
247
 
        builder.build_snapshot('foo', None,
248
 
            [('add', ('', None, 'directory', None))],
249
 
            message='foo')
250
 
        builder.build_snapshot('bar', None, [], message='bar')
251
 
        branch = builder.get_branch()
252
 
        branch.lock_write()
253
 
        self.addCleanup(branch.unlock)
254
 
        branch.set_revision_history(['foo', 'bar'])
255
 
        branch.set_revision_history(['foo'])
256
 
        self.assertRaises(errors.NotLefthandHistory,
257
 
                          branch.set_revision_history, ['bar'])
 
235
        tree = self.make_branch_and_memory_tree('.',
 
236
            format='dirstate-tags')
 
237
        tree.lock_write()
 
238
        try:
 
239
            tree.add('.')
 
240
            tree.commit('foo', rev_id='foo')
 
241
            tree.commit('bar', rev_id='bar')
 
242
            tree.branch.set_revision_history(['foo', 'bar'])
 
243
            tree.branch.set_revision_history(['foo'])
 
244
            self.assertRaises(errors.NotLefthandHistory,
 
245
                              tree.branch.set_revision_history, ['bar'])
 
246
        finally:
 
247
            tree.unlock()
258
248
 
259
249
    def do_checkout_test(self, lightweight=False):
260
 
        tree = self.make_branch_and_tree('source',
261
 
            format=self.get_format_name_subtree())
 
250
        tree = self.make_branch_and_tree('source', format='dirstate-with-subtree')
262
251
        subtree = self.make_branch_and_tree('source/subtree',
263
 
            format=self.get_format_name_subtree())
 
252
            format='dirstate-with-subtree')
264
253
        subsubtree = self.make_branch_and_tree('source/subtree/subsubtree',
265
 
            format=self.get_format_name_subtree())
 
254
            format='dirstate-with-subtree')
266
255
        self.build_tree(['source/subtree/file',
267
256
                         'source/subtree/subsubtree/file'])
268
257
        subsubtree.add('file')
290
279
        self.do_checkout_test(lightweight=True)
291
280
 
292
281
    def test_set_push(self):
293
 
        branch = self.make_branch('source', format=self.get_format_name())
 
282
        branch = self.make_branch('source', format='dirstate-tags')
294
283
        branch.get_config().set_user_option('push_location', 'old',
295
284
            store=config.STORE_LOCATION)
296
285
        warnings = []
305
294
        self.assertEqual(warnings[0], 'Value "new" is masked by "old" from '
306
295
                         'locations.conf')
307
296
 
308
 
 
309
 
class TestBranch6(TestBranch67, TestCaseWithTransport):
310
 
 
311
 
    def get_class(self):
312
 
        return _mod_branch.BzrBranch6
313
 
 
314
 
    def get_format_name(self):
315
 
        return "dirstate-tags"
316
 
 
317
 
    def get_format_name_subtree(self):
318
 
        return "dirstate-with-subtree"
319
 
 
320
 
    def test_set_stacked_on_url_errors(self):
321
 
        branch = self.make_branch('a', format=self.get_format_name())
322
 
        self.assertRaises(errors.UnstackableBranchFormat,
323
 
            branch.set_stacked_on_url, None)
324
 
 
325
 
    def test_default_stacked_location(self):
326
 
        branch = self.make_branch('a', format=self.get_format_name())
327
 
        self.assertRaises(errors.UnstackableBranchFormat, branch.get_stacked_on_url)
328
 
 
329
 
 
330
 
class TestBranch7(TestBranch67, TestCaseWithTransport):
331
 
 
332
 
    def get_class(self):
333
 
        return _mod_branch.BzrBranch7
334
 
 
335
 
    def get_format_name(self):
336
 
        return "development"
337
 
 
338
 
    def get_format_name_subtree(self):
339
 
        return "development-subtree"
340
 
 
341
 
    def test_set_stacked_on_url_unstackable_repo(self):
342
 
        repo = self.make_repository('a', format='dirstate-tags')
343
 
        control = repo.bzrdir
344
 
        branch = _mod_branch.BzrBranchFormat7().initialize(control)
345
 
        target = self.make_branch('b')
346
 
        self.assertRaises(errors.UnstackableRepositoryFormat,
347
 
            branch.set_stacked_on_url, target.base)
348
 
 
349
 
    def test_clone_stacked_on_unstackable_repo(self):
350
 
        repo = self.make_repository('a', format='dirstate-tags')
351
 
        control = repo.bzrdir
352
 
        branch = _mod_branch.BzrBranchFormat7().initialize(control)
353
 
        # Calling clone should not raise UnstackableRepositoryFormat.
354
 
        cloned_bzrdir = control.clone('cloned')
355
 
 
356
 
    def _test_default_stacked_location(self):
357
 
        branch = self.make_branch('a', format=self.get_format_name())
358
 
        self.assertRaises(errors.NotStacked, branch.get_stacked_on_url)
359
 
 
360
 
    def test_stack_and_unstack(self):
361
 
        branch = self.make_branch('a', format=self.get_format_name())
362
 
        target = self.make_branch_and_tree('b', format=self.get_format_name())
363
 
        branch.set_stacked_on_url(target.branch.base)
364
 
        self.assertEqual(target.branch.base, branch.get_stacked_on_url())
365
 
        revid = target.commit('foo')
366
 
        self.assertTrue(branch.repository.has_revision(revid))
367
 
        branch.set_stacked_on_url(None)
368
 
        self.assertRaises(errors.NotStacked, branch.get_stacked_on_url)
369
 
        self.assertFalse(branch.repository.has_revision(revid))
370
 
 
371
 
    def test_open_opens_stacked_reference(self):
372
 
        branch = self.make_branch('a', format=self.get_format_name())
373
 
        target = self.make_branch_and_tree('b', format=self.get_format_name())
374
 
        branch.set_stacked_on_url(target.branch.base)
375
 
        branch = branch.bzrdir.open_branch()
376
 
        revid = target.commit('foo')
377
 
        self.assertTrue(branch.repository.has_revision(revid))
378
 
 
379
 
 
380
297
class TestBranchReference(TestCaseWithTransport):
381
298
    """Tests for the branch reference facility."""
382
299
 
417
334
        self.assertTrue("pre_commit" in hooks, "pre_commit not in %s" % hooks)
418
335
        self.assertTrue("post_pull" in hooks, "post_pull not in %s" % hooks)
419
336
        self.assertTrue("post_uncommit" in hooks, "post_uncommit not in %s" % hooks)
420
 
        self.assertTrue("post_change_branch_tip" in hooks,
421
 
                        "post_change_branch_tip not in %s" % hooks)
422
337
 
423
338
    def test_installed_hooks_are_BranchHooks(self):
424
339
        """The installed hooks object should be a BranchHooks."""