40
39
super(TestWithUpgradableBranches, self).setUp()
41
self.addCleanup(bzrdir.BzrDirFormat._set_default_format,
42
bzrdir.BzrDirFormat.get_default_format())
40
self.addCleanup(controldir.ControlDirFormat._set_default_format,
41
controldir.ControlDirFormat.get_default_format())
44
43
def make_current_format_branch_and_checkout(self):
45
44
current_tree = self.make_branch_and_tree('current_format_branch',
50
49
def make_format_5_branch(self):
51
50
# setup a format 5 branch we can upgrade from.
52
self.make_branch_and_tree('format_5_branch',
53
format=bzrdir.BzrDirFormat5())
51
path = 'format_5_branch'
52
self.make_branch_and_tree(path, format=bzrdir.BzrDirFormat5())
55
55
def make_metadir_weave_branch(self):
56
56
self.make_branch_and_tree('metadir_weave_branch', format='metaweave')
58
58
def test_readonly_url_error(self):
59
self.make_format_5_branch()
59
path = self.make_format_5_branch()
60
60
(out, err) = self.run_bzr(
61
['upgrade', self.get_readonly_url('format_5_branch')], retcode=3)
62
self.assertEqual(out, "")
63
self.assertEqual(err, "bzr: ERROR: Upgrade URL cannot work with readonly URLs.\n")
61
['upgrade', self.get_readonly_url(path)], retcode=3)
62
err_msg = 'Upgrade URL cannot work with readonly URLs.'
63
self.assertEqualDiff('conversion error: %s\nbzr: ERROR: %s\n'
65
67
def test_upgrade_up_to_date(self):
66
68
self.make_current_format_branch_and_checkout()
67
69
# when up to date we should get a message to that effect
68
70
(out, err) = self.run_bzr('upgrade current_format_branch', retcode=3)
69
self.assertEqual("", out)
70
self.assertEqualDiff("bzr: ERROR: The branch format Meta "
71
"directory format 1 is already at the most "
72
"recent format.\n", err)
71
err_msg = ('The branch format %s is already at the most recent format.'
72
% ('Meta directory format 1'))
73
self.assertEqualDiff('conversion error: %s\nbzr: ERROR: %s\n'
74
77
def test_upgrade_up_to_date_checkout_warns_branch_left_alone(self):
75
78
self.make_current_format_branch_and_checkout()
76
79
# when upgrading a checkout, the branch location and a suggestion
77
80
# to upgrade it should be emitted even if the checkout is up to
82
burl = self.get_transport('current_format_branch').base
83
curl = self.get_transport('current_format_checkout').base
79
84
(out, err) = self.run_bzr('upgrade current_format_checkout', retcode=3)
80
self.assertEqual("This is a checkout. The branch (%s) needs to be "
81
"upgraded separately.\n"
82
% get_transport(self.get_url('current_format_branch')).base,
84
self.assertEqualDiff("bzr: ERROR: The branch format Meta "
85
"directory format 1 is already at the most "
86
"recent format.\n", err)
86
'Upgrading branch %s ...\nThis is a checkout.'
87
' The branch (%s) needs to be upgraded separately.\n'
90
msg = 'The branch format %s is already at the most recent format.' % (
91
'Meta directory format 1')
92
self.assertEqualDiff('conversion error: %s\nbzr: ERROR: %s\n'
88
96
def test_upgrade_checkout(self):
89
97
# upgrading a checkout should work
94
102
# anonymous branch
97
def test_ugrade_branch_in_repo(self):
105
def test_upgrade_branch_in_repo(self):
98
106
# upgrading a branch in a repo should warn about not upgrading the repo
101
109
def test_upgrade_explicit_metaformat(self):
102
110
# users can force an upgrade to metadir format.
103
self.make_format_5_branch()
104
url = get_transport(self.get_url('format_5_branch')).base
111
path = self.make_format_5_branch()
112
url = self.get_transport(path).base
105
113
# check --format takes effect
106
bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
114
controldir.ControlDirFormat._set_default_format(bzrdir.BzrDirFormat5())
107
115
backup_dir = 'backup.bzr.~1~'
108
116
(out, err) = self.run_bzr(
109
117
['upgrade', '--format=metaweave', url])
110
self.assertEqualDiff("""starting upgrade of %s
118
self.assertEqualDiff("""Upgrading branch %s ...
119
starting upgrade of %s
111
120
making backup of %s.bzr
113
122
starting upgrade from format 5 to 6
115
124
adding prefixes to revision-store
116
125
starting upgrade from format 6 to metadir
118
""" % (url, url, url, backup_dir), out)
127
""" % (url, url, url, url, backup_dir), out)
119
128
self.assertEqualDiff("", err)
120
129
self.assertTrue(isinstance(
121
bzrdir.BzrDir.open(self.get_url('format_5_branch'))._format,
130
bzrdir.BzrDir.open(self.get_url(path))._format,
122
131
bzrdir.BzrDirMetaFormat1))
124
133
def test_upgrade_explicit_knit(self):
125
134
# users can force an upgrade to knit format from a metadir weave
127
136
self.make_metadir_weave_branch()
128
url = get_transport(self.get_url('metadir_weave_branch')).base
137
url = self.get_transport('metadir_weave_branch').base
129
138
# check --format takes effect
130
bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
139
controldir.ControlDirFormat._set_default_format(bzrdir.BzrDirFormat5())
131
140
backup_dir = 'backup.bzr.~1~'
132
141
(out, err) = self.run_bzr(
133
142
['upgrade', '--format=knit', url])
134
self.assertEqualDiff("""starting upgrade of %s
143
self.assertEqualDiff("""Upgrading branch %s ...
144
starting upgrade of %s
135
145
making backup of %s.bzr
137
147
starting repository conversion
138
148
repository converted
140
""" % (url, url, url, backup_dir), out)
150
""" % (url, url, url, url, backup_dir),
141
152
self.assertEqualDiff("", err)
142
153
converted_dir = bzrdir.BzrDir.open(self.get_url('metadir_weave_branch'))
143
154
self.assertTrue(isinstance(converted_dir._format,
149
160
self.run_bzr('init-repository --format=metaweave repo')
150
161
self.run_bzr('upgrade --format=knit repo')
163
def assertLegalOption(self, option_str):
164
# Confirm that an option is legal. (Lower level tests are
165
# expected to validate the actual functionality.)
166
self.run_bzr('init --format=pack-0.92 branch-foo')
167
self.run_bzr('upgrade --format=2a branch-foo %s' % (option_str,))
169
def assertBranchFormat(self, dir, format):
170
branch = bzrdir.BzrDir.open_tree_or_branch(self.get_url(dir))[1]
171
branch_format = branch._format
172
meta_format = bzrdir.format_registry.make_bzrdir(format)
173
expected_format = meta_format.get_branch_format()
174
self.assertEqual(expected_format, branch_format)
176
def test_upgrade_clean_supported(self):
177
self.assertLegalOption('--clean')
178
self.assertBranchFormat('branch-foo', '2a')
179
backup_bzr_dir = os.path.join("branch-foo", "backup.bzr.~1~")
180
self.assertFalse(os.path.exists(backup_bzr_dir))
182
def test_upgrade_dry_run_supported(self):
183
self.assertLegalOption('--dry-run')
184
self.assertBranchFormat('branch-foo', 'pack-0.92')
152
186
def test_upgrade_permission_check(self):
153
187
"""'backup.bzr' should retain permissions of .bzr. Bug #262450"""
154
188
self.requireFeature(features.posix_permissions_feature)
160
194
new_perms = os.stat(backup_dir).st_mode & 0777
161
195
self.assertTrue(new_perms == old_perms)
164
197
def test_upgrade_with_existing_backup_dir(self):
165
self.make_format_5_branch()
166
transport = get_transport(self.get_url('format_5_branch'))
168
bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
198
path = self.make_format_5_branch()
199
t = self.get_transport(path)
201
controldir.ControlDirFormat._set_default_format(bzrdir.BzrDirFormat5())
169
202
backup_dir1 = 'backup.bzr.~1~'
170
203
backup_dir2 = 'backup.bzr.~2~'
171
204
# explicitly create backup_dir1. bzr should create the .~2~ directory
173
transport.mkdir(backup_dir1)
174
207
(out, err) = self.run_bzr(
175
208
['upgrade', '--format=metaweave', url])
176
self.assertEqualDiff("""starting upgrade of %s
209
self.assertEqualDiff("""Upgrading branch %s ...
210
starting upgrade of %s
177
211
making backup of %s.bzr
179
213
starting upgrade from format 5 to 6
181
215
adding prefixes to revision-store
182
216
starting upgrade from format 6 to metadir
184
""" % (url, url, url, backup_dir2), out)
218
""" % (url, url, url, url, backup_dir2), out)
185
219
self.assertEqualDiff("", err)
186
220
self.assertTrue(isinstance(
187
bzrdir.BzrDir.open(self.get_url('format_5_branch'))._format,
221
bzrdir.BzrDir.open(self.get_url(path))._format,
188
222
bzrdir.BzrDirMetaFormat1))
189
self.assertTrue(transport.has(backup_dir2))
223
self.assertTrue(t.has(backup_dir2))
191
226
class SFTPTests(TestCaseWithSFTPServer):
192
227
"""Tests for upgrade over sftp."""
194
229
def test_upgrade_url(self):
195
230
self.run_bzr('init --format=weave')
196
t = get_transport(self.get_url())
231
t = self.get_transport()
198
233
out, err = self.run_bzr(['upgrade', '--format=knit', url])
199
234
backup_dir = 'backup.bzr.~1~'
200
self.assertEqualDiff("""starting upgrade of %s
235
self.assertEqualDiff("""Upgrading branch %s ...
236
starting upgrade of %s
201
237
making backup of %s.bzr
203
239
starting upgrade from format 6 to metadir
204
240
starting repository conversion
205
241
repository converted
207
""" % (url, url, url,backup_dir), out)
243
""" % (url, url, url, url,backup_dir), out)
208
244
self.assertEqual('', err)