~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_branch.py

  • Committer: Ian Clatworthy
  • Date: 2007-12-11 02:07:30 UTC
  • mto: (3119.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 3120.
  • Revision ID: ian.clatworthy@internode.on.net-20071211020730-sdj4kj794dw0628e
make help topics more discoverable

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
from bzrlib import (
28
28
    branch as _mod_branch,
29
29
    bzrdir,
 
30
    config,
30
31
    errors,
 
32
    trace,
31
33
    urlutils,
32
34
    )
33
35
from bzrlib.branch import (
37
39
    BranchReferenceFormat,
38
40
    BzrBranch5,
39
41
    BzrBranchFormat5,
 
42
    BzrBranchFormat6,
40
43
    PullResult,
41
44
    )
42
45
from bzrlib.bzrdir import (BzrDirMetaFormat1, BzrDirMeta1, 
52
55
 
53
56
class TestDefaultFormat(TestCase):
54
57
 
 
58
    def test_default_format(self):
 
59
        # update this if you change the default branch format
 
60
        self.assertIsInstance(BranchFormat.get_default_format(),
 
61
                BzrBranchFormat6)
 
62
 
 
63
    def test_default_format_is_same_as_bzrdir_default(self):
 
64
        # XXX: it might be nice if there was only one place the default was
 
65
        # set, but at the moment that's not true -- mbp 20070814 -- 
 
66
        # https://bugs.launchpad.net/bzr/+bug/132376
 
67
        self.assertEqual(BranchFormat.get_default_format(),
 
68
                BzrDirFormat.get_default_format().get_branch_format())
 
69
 
55
70
    def test_get_set_default_format(self):
 
71
        # set the format and then set it back again
56
72
        old_format = BranchFormat.get_default_format()
57
 
        # default is 5
58
 
        self.assertTrue(isinstance(old_format, BzrBranchFormat5))
59
73
        BranchFormat.set_default_format(SampleBranchFormat())
60
74
        try:
61
75
            # the default branch format is used by the meta dir format
93
107
                                   ensure_config_dir_exists)
94
108
        ensure_config_dir_exists()
95
109
        fn = locations_config_filename()
 
110
        # write correct newlines to locations.conf
 
111
        # by default ConfigObj uses native line-endings for new files
 
112
        # but uses already existing line-endings if file is not empty
 
113
        f = open(fn, 'wb')
 
114
        try:
 
115
            f.write('# comment\n')
 
116
        finally:
 
117
            f.close()
 
118
 
96
119
        branch = self.make_branch('.', format='knit')
97
120
        branch.set_push_location('foo')
98
121
        local_path = urlutils.local_path_from_url(branch.base[:-1])
99
 
        self.assertFileEqual("[%s]\n"
 
122
        self.assertFileEqual("# comment\n"
 
123
                             "[%s]\n"
100
124
                             "push_location = foo\n"
101
125
                             "push_location:policy = norecurse" % local_path,
102
126
                             fn)
222
246
        finally:
223
247
            tree.unlock()
224
248
 
225
 
    def test_append_revision(self):
226
 
        tree = self.make_branch_and_tree('branch1',
227
 
            format='dirstate-tags')
228
 
        tree.lock_write()
229
 
        try:
230
 
            tree.commit('foo', rev_id='foo')
231
 
            tree.commit('bar', rev_id='bar')
232
 
            tree.commit('baz', rev_id='baz')
233
 
            tree.set_last_revision('bar')
234
 
            tree.branch.set_last_revision_info(2, 'bar')
235
 
            tree.commit('qux', rev_id='qux')
236
 
            tree.add_parent_tree_id('baz')
237
 
            tree.commit('qux', rev_id='quxx')
238
 
            tree.branch.set_last_revision_info(0, 'null:')
239
 
            self.assertRaises(errors.NotLeftParentDescendant,
240
 
                              tree.branch.append_revision, 'bar')
241
 
            tree.branch.append_revision('foo')
242
 
            self.assertRaises(errors.NotLeftParentDescendant,
243
 
                              tree.branch.append_revision, 'baz')
244
 
            tree.branch.append_revision('bar')
245
 
            tree.branch.append_revision('baz')
246
 
            self.assertRaises(errors.NotLeftParentDescendant,
247
 
                              tree.branch.append_revision, 'quxx')
248
 
        finally:
249
 
            tree.unlock()
250
 
 
251
249
    def do_checkout_test(self, lightweight=False):
252
250
        tree = self.make_branch_and_tree('source', format='dirstate-with-subtree')
253
251
        subtree = self.make_branch_and_tree('source/subtree',
274
272
        else:
275
273
            self.assertEndsWith(subbranch.base, 'target/subtree/subsubtree/')
276
274
 
277
 
 
278
275
    def test_checkout_with_references(self):
279
276
        self.do_checkout_test()
280
277
 
281
278
    def test_light_checkout_with_references(self):
282
279
        self.do_checkout_test(lightweight=True)
283
280
 
 
281
    def test_set_push(self):
 
282
        branch = self.make_branch('source', format='dirstate-tags')
 
283
        branch.get_config().set_user_option('push_location', 'old',
 
284
            store=config.STORE_LOCATION)
 
285
        warnings = []
 
286
        def warning(*args):
 
287
            warnings.append(args[0] % args[1:])
 
288
        _warning = trace.warning
 
289
        trace.warning = warning
 
290
        try:
 
291
            branch.set_push_location('new')
 
292
        finally:
 
293
            trace.warning = _warning
 
294
        self.assertEqual(warnings[0], 'Value "new" is masked by "old" from '
 
295
                         'locations.conf')
 
296
 
284
297
class TestBranchReference(TestCaseWithTransport):
285
298
    """Tests for the branch reference facility."""
286
299
 
298
311
        opened_branch = branch_dir.open_branch()
299
312
        self.assertEqual(opened_branch.base, target_branch.base)
300
313
 
 
314
    def test_get_reference(self):
 
315
        """For a BranchReference, get_reference should reutrn the location."""
 
316
        branch = self.make_branch('target')
 
317
        checkout = branch.create_checkout('checkout', lightweight=True)
 
318
        reference_url = branch.bzrdir.root_transport.abspath('') + '/'
 
319
        # if the api for create_checkout changes to return different checkout types
 
320
        # then this file read will fail.
 
321
        self.assertFileEqual(reference_url, 'checkout/.bzr/branch/location')
 
322
        self.assertEqual(reference_url,
 
323
            _mod_branch.BranchReferenceFormat().get_reference(checkout.bzrdir))
 
324
 
301
325
 
302
326
class TestHooks(TestCase):
303
327
 
307
331
        self.assertTrue("set_rh" in hooks, "set_rh not in %s" % hooks)
308
332
        self.assertTrue("post_push" in hooks, "post_push not in %s" % hooks)
309
333
        self.assertTrue("post_commit" in hooks, "post_commit not in %s" % hooks)
 
334
        self.assertTrue("pre_commit" in hooks, "pre_commit not in %s" % hooks)
310
335
        self.assertTrue("post_pull" in hooks, "post_pull not in %s" % hooks)
311
336
        self.assertTrue("post_uncommit" in hooks, "post_uncommit not in %s" % hooks)
312
337
 
315
340
        # the installed hooks are saved in self._preserved_hooks.
316
341
        self.assertIsInstance(self._preserved_hooks[_mod_branch.Branch], BranchHooks)
317
342
 
318
 
    def test_install_hook_raises_unknown_hook(self):
319
 
        """install_hook should raise UnknownHook if a hook is unknown."""
320
 
        hooks = BranchHooks()
321
 
        self.assertRaises(UnknownHook, hooks.install_hook, 'silly', None)
322
 
 
323
 
    def test_install_hook_appends_known_hook(self):
324
 
        """install_hook should append the callable for known hooks."""
325
 
        hooks = BranchHooks()
326
 
        hooks.install_hook('set_rh', None)
327
 
        self.assertEqual(hooks['set_rh'], [None])
328
 
 
329
343
 
330
344
class TestPullResult(TestCase):
331
345