21
21
from bzrlib import (
25
26
from bzrlib.tests import (
27
28
TestCaseWithTransport,
29
30
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
30
from bzrlib.repofmt.knitrepo import (
31
RepositoryFormatKnit1,
31
from bzrlib.repofmt.groupcompress_repo import (
36
class OldBzrDir(bzrdir.BzrDirMeta1):
37
"""An test bzr dir implementation"""
39
def needs_format_conversion(self, format):
40
return not isinstance(format, self.__class__)
43
class ConvertOldTestToMeta(bzrdir.Converter):
44
"""A trivial converter, used for testing."""
46
def convert(self, to_convert, pb):
47
ui.ui_factory.note('starting upgrade from old test format to 2a')
48
to_convert.control_transport.put_bytes(
50
bzrdir.BzrDirMetaFormat1().get_format_string(),
51
mode=to_convert._get_file_mode())
52
return bzrdir.BzrDir.open(to_convert.user_url)
55
class OldBzrDirFormat(bzrdir.BzrDirMetaFormat1):
57
_lock_class = lockable_files.TransportLock
59
def get_converter(self, format=None):
60
return ConvertOldTestToMeta()
62
def get_format_string(self):
63
return "Ancient Test Format"
65
def _open(self, transport):
66
return OldBzrDir(transport, self)
35
69
class TestWithUpgradableBranches(TestCaseWithTransport):
38
72
super(TestWithUpgradableBranches, self).setUp()
73
old_format = OldBzrDirFormat()
74
self.addCleanup(bzrdir.BzrDirFormat.unregister_format, old_format)
75
bzrdir.BzrDirFormat.register_format(old_format)
39
76
self.addCleanup(controldir.ControlDirFormat._set_default_format,
40
77
controldir.ControlDirFormat.get_default_format())
45
82
current_tree.branch.create_checkout(
46
83
self.get_url('current_format_checkout'), lightweight=True)
48
def make_format_5_branch(self):
49
# setup a format 5 branch we can upgrade from.
50
path = 'format_5_branch'
51
from bzrlib.plugins.weave_fmt.bzrdir import BzrDirFormat5
52
self.make_branch_and_tree(path, format=BzrDirFormat5())
85
def make_old_format_branch(self):
86
# setup an old format branch we can upgrade from.
87
path = 'old_format_branch'
88
self.make_branch_and_tree(path, format=OldBzrDirFormat())
55
def make_metadir_weave_branch(self):
56
self.make_branch_and_tree('metadir_weave_branch', format='metaweave')
58
91
def test_readonly_url_error(self):
59
path = self.make_format_5_branch()
92
path = self.make_old_format_branch()
60
93
(out, err) = self.run_bzr(
61
94
['upgrade', self.get_readonly_url(path)], retcode=3)
62
95
err_msg = 'Upgrade URL cannot work with readonly URLs.'
106
139
# upgrading a branch in a repo should warn about not upgrading the repo
109
def test_upgrade_explicit_metaformat(self):
110
# users can force an upgrade to metadir format.
111
path = self.make_format_5_branch()
142
def test_upgrade_explicit_format(self):
143
# users can force an upgrade to specific format.
144
path = self.make_old_format_branch()
112
145
url = self.get_transport(path).base
113
146
# check --format takes effect
114
from bzrlib.plugins.weave_fmt.bzrdir import BzrDirFormat5
115
controldir.ControlDirFormat._set_default_format(BzrDirFormat5())
147
controldir.ControlDirFormat._set_default_format(OldBzrDirFormat())
116
148
backup_dir = 'backup.bzr.~1~'
117
149
(out, err) = self.run_bzr(
118
['upgrade', '--format=metaweave', url])
150
['upgrade', '--format=2a', url])
119
151
self.assertEqualDiff("""Upgrading branch %s ...
120
152
starting upgrade of %s
121
153
making backup of %s.bzr
123
starting upgrade from format 5 to 6
124
adding prefixes to weaves
125
adding prefixes to revision-store
126
starting upgrade from format 6 to metadir
155
starting upgrade from old test format to 2a
128
157
""" % (url, url, url, url, backup_dir), out)
129
158
self.assertEqualDiff("", err)
132
161
bzrdir.BzrDirMetaFormat1))
134
163
def test_upgrade_explicit_knit(self):
135
# users can force an upgrade to knit format from a metadir weave
137
self.make_metadir_weave_branch()
138
url = self.get_transport('metadir_weave_branch').base
164
# users can force an upgrade to knit format from a metadir pack 0.92
165
# branch to a 2a branch.
166
self.make_branch_and_tree('branch', format='pack-0.92')
167
url = self.get_transport('branch').base
139
168
# check --format takes effect
140
from bzrlib.plugins.weave_fmt.bzrdir import BzrDirFormat5
141
controldir.ControlDirFormat._set_default_format(BzrDirFormat5())
169
controldir.ControlDirFormat._set_default_format(OldBzrDirFormat())
142
170
backup_dir = 'backup.bzr.~1~'
143
171
(out, err) = self.run_bzr(
144
['upgrade', '--format=knit', url])
172
['upgrade', '--format=2a', url])
145
173
self.assertEqualDiff("""Upgrading branch %s ...
146
174
starting upgrade of %s
147
175
making backup of %s.bzr
152
180
""" % (url, url, url, url, backup_dir),
154
182
self.assertEqualDiff("", err)
155
converted_dir = bzrdir.BzrDir.open(self.get_url('metadir_weave_branch'))
183
converted_dir = bzrdir.BzrDir.open(self.get_url('branch'))
156
184
self.assertTrue(isinstance(converted_dir._format,
157
185
bzrdir.BzrDirMetaFormat1))
158
186
self.assertTrue(isinstance(converted_dir.open_repository()._format,
159
RepositoryFormatKnit1))
161
189
def test_upgrade_repo(self):
162
self.run_bzr('init-repository --format=metaweave repo')
163
self.run_bzr('upgrade --format=knit repo')
190
self.run_bzr('init-repository --format=pack-0.92 repo')
191
self.run_bzr('upgrade --format=2a repo')
165
193
def assertLegalOption(self, option_str):
166
194
# Confirm that an option is legal. (Lower level tests are
197
225
self.assertTrue(new_perms == old_perms)
199
227
def test_upgrade_with_existing_backup_dir(self):
200
path = self.make_format_5_branch()
228
path = self.make_old_format_branch()
201
229
t = self.get_transport(path)
203
from bzrlib.plugins.weave_fmt.bzrdir import BzrDirFormat5
204
controldir.ControlDirFormat._set_default_format(BzrDirFormat5())
231
controldir.ControlDirFormat._set_default_format(OldBzrDirFormat())
205
232
backup_dir1 = 'backup.bzr.~1~'
206
233
backup_dir2 = 'backup.bzr.~2~'
207
234
# explicitly create backup_dir1. bzr should create the .~2~ directory
209
236
t.mkdir(backup_dir1)
210
237
(out, err) = self.run_bzr(
211
['upgrade', '--format=metaweave', url])
238
['upgrade', '--format=2a', url])
212
239
self.assertEqualDiff("""Upgrading branch %s ...
213
240
starting upgrade of %s
214
241
making backup of %s.bzr
216
starting upgrade from format 5 to 6
217
adding prefixes to weaves
218
adding prefixes to revision-store
219
starting upgrade from format 6 to metadir
243
starting upgrade from old test format to 2a
221
245
""" % (url, url, url, url, backup_dir2), out)
222
246
self.assertEqualDiff("", err)
230
254
"""Tests for upgrade over sftp."""
232
256
def test_upgrade_url(self):
233
self.run_bzr('init --format=weave')
257
self.run_bzr('init --format=pack-0.92')
234
258
t = self.get_transport()
236
out, err = self.run_bzr(['upgrade', '--format=knit', url])
260
out, err = self.run_bzr(['upgrade', '--format=2a', url])
237
261
backup_dir = 'backup.bzr.~1~'
238
262
self.assertEqualDiff("""Upgrading branch %s ...
239
263
starting upgrade of %s
240
264
making backup of %s.bzr
242
starting upgrade from format 6 to metadir
243
266
starting repository conversion
244
267
repository converted