1
# (C) 2006 Canonical Ltd
1
# Copyright (C) 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
38
38
from bzrlib.transport import get_transport
39
39
from bzrlib.transport.http import HttpServer
40
40
from bzrlib.transport.memory import MemoryServer
41
from bzrlib import upgrade, workingtree
43
44
class TestDefaultFormat(TestCase):
45
46
def test_get_set_default_format(self):
47
private_default = repository._default_format.__class__
46
48
old_format = repository.RepositoryFormat.get_default_format()
47
self.assertTrue(isinstance(old_format, repository.RepositoryFormatKnit1))
49
self.assertTrue(isinstance(old_format, private_default))
48
50
repository.RepositoryFormat.set_default_format(SampleRepositoryFormat())
49
51
# creating a repository should now create an instrumented dir.
51
53
# the default branch format is used by the meta dir format
52
54
# which is not the default bzrdir format at this point
53
dir = bzrdir.BzrDirMetaFormat1().initialize('memory:/')
55
dir = bzrdir.BzrDirMetaFormat1().initialize('memory:///')
54
56
result = dir.create_repository()
55
57
self.assertEqual(result, 'A bzr repository dir')
72
74
def initialize(self, a_bzrdir, shared=False):
73
75
"""Initialize a repository in a BzrDir"""
74
76
t = a_bzrdir.get_repository_transport(self)
75
t.put('format', StringIO(self.get_format_string()))
77
t.put_bytes('format', self.get_format_string())
76
78
return 'A bzr repository dir'
78
80
def is_supported(self):
429
431
repo = repo_dir.open_repository()
430
432
self.assertTrue(isinstance(target_format, repo._format.__class__))
435
class TestMisc(TestCase):
437
def test_unescape_xml(self):
438
"""We get some kind of error when malformed entities are passed"""
439
self.assertRaises(KeyError, repository._unescape_xml, 'foo&bar;')
442
class TestRepositoryFormatKnit2(TestCaseWithTransport):
444
def test_convert(self):
445
"""Ensure the upgrade adds weaves for roots"""
446
format = bzrdir.BzrDirMetaFormat1()
447
format.repository_format = repository.RepositoryFormatKnit1()
448
tree = self.make_branch_and_tree('.', format)
449
tree.commit("Dull commit", rev_id="dull")
450
revision_tree = tree.branch.repository.revision_tree('dull')
451
self.assertRaises(errors.NoSuchFile, revision_tree.get_file_lines,
452
revision_tree.inventory.root.file_id)
453
format = bzrdir.BzrDirMetaFormat1()
454
format.repository_format = repository.RepositoryFormatKnit2()
455
upgrade.Convert('.', format)
456
tree = workingtree.WorkingTree.open('.')
457
revision_tree = tree.branch.repository.revision_tree('dull')
458
revision_tree.get_file_lines(revision_tree.inventory.root.file_id)
459
tree.commit("Another dull commit", rev_id='dull2')
460
revision_tree = tree.branch.repository.revision_tree('dull2')
461
self.assertEqual('dull', revision_tree.inventory.root.revision)