1
# (C) 2005 Canonical Ltd
1
# Copyright (C) 2005, 2006 Canonical Ltd
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
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
11
# GNU General Public License for more details.
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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
37
41
class TestDefaultFormat(TestCase):
39
43
def test_get_set_default_format(self):
40
old_format = branch.BranchFormat.get_default_format()
44
old_format = bzrlib.branch.BranchFormat.get_default_format()
42
self.assertTrue(isinstance(old_format, branch.BzrBranchFormat5))
43
branch.BranchFormat.set_default_format(SampleBranchFormat())
46
self.assertTrue(isinstance(old_format, bzrlib.branch.BzrBranchFormat5))
47
bzrlib.branch.BranchFormat.set_default_format(SampleBranchFormat())
45
49
# the default branch format is used by the meta dir format
46
50
# which is not the default bzrdir format at this point
47
dir = bzrdir.BzrDirMetaFormat1().initialize('memory:/')
51
dir = BzrDirMetaFormat1().initialize('memory:///')
48
52
result = dir.create_branch()
49
53
self.assertEqual(result, 'A branch')
51
branch.BranchFormat.set_default_format(old_format)
52
self.assertEqual(old_format, branch.BranchFormat.get_default_format())
55
class SampleBranchFormat(branch.BranchFormat):
55
bzrlib.branch.BranchFormat.set_default_format(old_format)
56
self.assertEqual(old_format, bzrlib.branch.BranchFormat.get_default_format())
59
class TestBranchFormat5(TestCaseWithTransport):
60
"""Tests specific to branch format 5"""
62
def test_branch_format_5_uses_lockdir(self):
64
bzrdir = BzrDirMetaFormat1().initialize(url)
65
bzrdir.create_repository()
66
branch = bzrdir.create_branch()
67
t = self.get_transport()
68
self.log("branch instance is %r" % branch)
69
self.assert_(isinstance(branch, BzrBranch5))
70
self.assertIsDirectory('.', t)
71
self.assertIsDirectory('.bzr/branch', t)
72
self.assertIsDirectory('.bzr/branch/lock', t)
75
self.assertIsDirectory('.bzr/branch/lock/held', t)
80
class TestBranchEscaping(TestCaseWithTransport):
81
"""Test a branch can be correctly stored and used on a vfat-like transport
83
Makes sure we have proper escaping of invalid characters, etc.
85
It'd be better to test all operations on the FakeVFATTransportDecorator,
86
but working trees go straight to the os not through the Transport layer.
87
Therefore we build some history first in the regular way and then
88
check it's safe to access for vfat.
95
super(TestBranchEscaping, self).setUp()
96
from bzrlib.repository import RepositoryFormatKnit1
97
bzrdir = BzrDirMetaFormat1().initialize(self.get_url())
98
repo = RepositoryFormatKnit1().initialize(bzrdir)
99
branch = bzrdir.create_branch()
100
wt = bzrdir.create_workingtree()
101
self.build_tree_contents([("foo", "contents of foo")])
102
# add file with id containing wierd characters
103
wt.add(['foo'], [self.FOO_ID])
104
wt.commit('this is my new commit', rev_id=self.REV_ID)
106
def test_branch_on_vfat(self):
107
from bzrlib.transport.fakevfat import FakeVFATTransportDecorator
108
# now access over vfat; should be safe
109
transport = FakeVFATTransportDecorator('vfat+' + self.get_url())
110
bzrdir, junk = BzrDir.open_containing_from_transport(transport)
111
branch = bzrdir.open_branch()
112
revtree = branch.repository.revision_tree(self.REV_ID)
113
contents = revtree.get_file_text(self.FOO_ID)
114
self.assertEqual(contents, 'contents of foo')
117
class SampleBranchFormat(bzrlib.branch.BranchFormat):
56
118
"""A sample format
58
120
this format is initializable, unsupported to aid in testing the
88
150
dir = format._matchingbzrdir.initialize(url)
89
151
dir.create_repository()
90
152
format.initialize(dir)
91
found_format = branch.BranchFormat.find_format(dir)
153
found_format = bzrlib.branch.BranchFormat.find_format(dir)
92
154
self.failUnless(isinstance(found_format, format.__class__))
93
check_format(branch.BzrBranchFormat5(), "bar")
155
check_format(bzrlib.branch.BzrBranchFormat5(), "bar")
95
157
def test_find_format_not_branch(self):
96
158
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
97
159
self.assertRaises(NotBranchError,
98
branch.BranchFormat.find_format,
160
bzrlib.branch.BranchFormat.find_format,
101
163
def test_find_format_unknown_format(self):
102
164
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
103
165
SampleBranchFormat().initialize(dir)
104
166
self.assertRaises(UnknownFormatError,
105
branch.BranchFormat.find_format,
167
bzrlib.branch.BranchFormat.find_format,
108
170
def test_register_unregister_format(self):
113
175
format.initialize(dir)
114
176
# register a format for it.
115
branch.BranchFormat.register_format(format)
177
bzrlib.branch.BranchFormat.register_format(format)
116
178
# which branch.Open will refuse (not supported)
117
self.assertRaises(UnsupportedFormatError, branch.Branch.open, self.get_url())
179
self.assertRaises(UnsupportedFormatError, bzrlib.branch.Branch.open, self.get_url())
118
180
# but open_downlevel will work
119
181
self.assertEqual(format.open(dir), bzrdir.BzrDir.open(self.get_url()).open_branch(unsupported=True))
120
182
# unregister the format
121
branch.BranchFormat.unregister_format(format)
183
bzrlib.branch.BranchFormat.unregister_format(format)
124
186
class TestBranchReference(TestCaseWithTransport):