21
21
from bzrlib import (
28
26
from bzrlib.tests import (
30
28
TestCaseWithTransport,
32
30
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
33
from bzrlib.repofmt.knitpack_repo import RepositoryFormatKnitPack1
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(controldir.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)
31
from bzrlib.repofmt.knitrepo import (
32
RepositoryFormatKnit1,
69
36
class TestWithUpgradableBranches(TestCaseWithTransport):
72
39
super(TestWithUpgradableBranches, self).setUp()
40
self.addCleanup(controldir.ControlDirFormat._set_default_format,
41
controldir.ControlDirFormat.get_default_format())
74
43
def make_current_format_branch_and_checkout(self):
75
44
current_tree = self.make_branch_and_tree('current_format_branch',
77
46
current_tree.branch.create_checkout(
78
47
self.get_url('current_format_checkout'), lightweight=True)
49
def make_format_5_branch(self):
50
# setup a format 5 branch we can upgrade from.
51
path = 'format_5_branch'
52
self.make_branch_and_tree(path, format=bzrdir.BzrDirFormat5())
55
def make_metadir_weave_branch(self):
56
self.make_branch_and_tree('metadir_weave_branch', format='metaweave')
80
58
def test_readonly_url_error(self):
81
self.make_branch_and_tree("old_format_branch", format="knit")
59
path = self.make_format_5_branch()
82
60
(out, err) = self.run_bzr(
83
['upgrade', self.get_readonly_url("old_format_branch")], retcode=3)
61
['upgrade', self.get_readonly_url(path)], retcode=3)
84
62
err_msg = 'Upgrade URL cannot work with readonly URLs.'
85
63
self.assertEqualDiff('conversion error: %s\nbzr: ERROR: %s\n'
86
64
% (err_msg, err_msg),
128
106
# upgrading a branch in a repo should warn about not upgrading the repo
131
def test_upgrade_control_dir(self):
132
old_format = OldBzrDirFormat()
133
self.addCleanup(bzrdir.BzrProber.formats.remove,
134
old_format.get_format_string())
135
bzrdir.BzrProber.formats.register(old_format.get_format_string(),
137
self.addCleanup(controldir.ControlDirFormat._set_default_format,
138
controldir.ControlDirFormat.get_default_format())
140
# setup an old format branch we can upgrade from.
141
path = 'old_format_branch'
142
self.make_branch_and_tree(path, format=old_format)
143
transport = self.get_transport(path)
145
display_url = transport.local_abspath('.')
109
def test_upgrade_explicit_metaformat(self):
110
# users can force an upgrade to metadir format.
111
path = self.make_format_5_branch()
112
url = self.get_transport(path).base
146
113
# check --format takes effect
147
controldir.ControlDirFormat._set_default_format(old_format)
114
controldir.ControlDirFormat._set_default_format(bzrdir.BzrDirFormat5())
148
115
backup_dir = 'backup.bzr.~1~'
149
116
(out, err) = self.run_bzr(
150
['upgrade', '--format=2a', url])
151
self.assertEqualDiff("""Upgrading branch %s/ ...
152
starting upgrade of %s/
153
making backup of %s/.bzr
155
starting upgrade from old test format to 2a
117
['upgrade', '--format=metaweave', url])
118
self.assertEqualDiff("""Upgrading branch %s ...
119
starting upgrade of %s
120
making backup of %s.bzr
122
starting upgrade from format 5 to 6
123
adding prefixes to weaves
124
adding prefixes to revision-store
125
starting upgrade from format 6 to metadir
157
""" % (display_url, display_url, display_url, display_url, backup_dir), out)
127
""" % (url, url, url, url, backup_dir), out)
158
128
self.assertEqualDiff("", err)
159
129
self.assertTrue(isinstance(
160
130
bzrdir.BzrDir.open(self.get_url(path))._format,
161
131
bzrdir.BzrDirMetaFormat1))
163
133
def test_upgrade_explicit_knit(self):
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='knit')
167
transport = self.get_transport('branch')
169
display_url = transport.local_abspath('.')
134
# users can force an upgrade to knit format from a metadir weave
136
self.make_metadir_weave_branch()
137
url = self.get_transport('metadir_weave_branch').base
170
138
# check --format takes effect
139
controldir.ControlDirFormat._set_default_format(bzrdir.BzrDirFormat5())
171
140
backup_dir = 'backup.bzr.~1~'
172
141
(out, err) = self.run_bzr(
173
['upgrade', '--format=pack-0.92', url])
174
self.assertEqualDiff("""Upgrading branch %s/ ...
175
starting upgrade of %s/
176
making backup of %s/.bzr
142
['upgrade', '--format=knit', url])
143
self.assertEqualDiff("""Upgrading branch %s ...
144
starting upgrade of %s
145
making backup of %s.bzr
178
147
starting repository conversion
179
148
repository converted
181
""" % (display_url, display_url, display_url, display_url, backup_dir),
150
""" % (url, url, url, url, backup_dir),
183
152
self.assertEqualDiff("", err)
184
converted_dir = bzrdir.BzrDir.open(self.get_url('branch'))
153
converted_dir = bzrdir.BzrDir.open(self.get_url('metadir_weave_branch'))
185
154
self.assertTrue(isinstance(converted_dir._format,
186
155
bzrdir.BzrDirMetaFormat1))
187
156
self.assertTrue(isinstance(converted_dir.open_repository()._format,
188
RepositoryFormatKnitPack1))
157
RepositoryFormatKnit1))
190
159
def test_upgrade_repo(self):
191
self.run_bzr('init-repository --format=pack-0.92 repo')
192
self.run_bzr('upgrade --format=2a repo')
160
self.run_bzr('init-repository --format=metaweave repo')
161
self.run_bzr('upgrade --format=knit repo')
194
163
def assertLegalOption(self, option_str):
195
164
# Confirm that an option is legal. (Lower level tests are
226
195
self.assertTrue(new_perms == old_perms)
228
197
def test_upgrade_with_existing_backup_dir(self):
229
self.make_branch_and_tree("old_format_branch", format="knit")
230
t = self.get_transport("old_format_branch")
198
path = self.make_format_5_branch()
199
t = self.get_transport(path)
232
display_url = t.local_abspath('.')
201
controldir.ControlDirFormat._set_default_format(bzrdir.BzrDirFormat5())
233
202
backup_dir1 = 'backup.bzr.~1~'
234
203
backup_dir2 = 'backup.bzr.~2~'
235
204
# explicitly create backup_dir1. bzr should create the .~2~ directory
237
206
t.mkdir(backup_dir1)
238
207
(out, err) = self.run_bzr(
239
['upgrade', '--format=2a', url])
240
self.assertEqualDiff("""Upgrading branch %s/ ...
241
starting upgrade of %s/
242
making backup of %s/.bzr
244
starting repository conversion
208
['upgrade', '--format=metaweave', url])
209
self.assertEqualDiff("""Upgrading branch %s ...
210
starting upgrade of %s
211
making backup of %s.bzr
213
starting upgrade from format 5 to 6
214
adding prefixes to weaves
215
adding prefixes to revision-store
216
starting upgrade from format 6 to metadir
247
""" % (display_url, display_url, display_url, display_url, backup_dir2), out)
218
""" % (url, url, url, url, backup_dir2), out)
248
219
self.assertEqualDiff("", err)
249
220
self.assertTrue(isinstance(
250
bzrdir.BzrDir.open(self.get_url("old_format_branch"))._format,
221
bzrdir.BzrDir.open(self.get_url(path))._format,
251
222
bzrdir.BzrDirMetaFormat1))
252
223
self.assertTrue(t.has(backup_dir2))
256
227
"""Tests for upgrade over sftp."""
258
229
def test_upgrade_url(self):
259
self.run_bzr('init --format=pack-0.92')
230
self.run_bzr('init --format=weave')
260
231
t = self.get_transport()
262
display_url = urlutils.unescape_for_display(url,
264
out, err = self.run_bzr(['upgrade', '--format=2a', url])
233
out, err = self.run_bzr(['upgrade', '--format=knit', url])
265
234
backup_dir = 'backup.bzr.~1~'
266
235
self.assertEqualDiff("""Upgrading branch %s ...
267
236
starting upgrade of %s
268
237
making backup of %s.bzr
239
starting upgrade from format 6 to metadir
270
240
starting repository conversion
271
241
repository converted
273
""" % (display_url, display_url, display_url, display_url, backup_dir), out)
243
""" % (url, url, url, url,backup_dir), out)
274
244
self.assertEqual('', err)