15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
"""Black box tests for the upgrade ui."""
21
19
from bzrlib import (
26
23
from bzrlib.tests import (
29
25
TestCaseWithTransport,
31
27
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
28
from bzrlib.transport import get_transport
32
29
from bzrlib.repofmt.knitrepo import (
33
30
RepositoryFormatKnit1,
79
76
(out, err) = self.run_bzr('upgrade current_format_checkout', retcode=3)
80
77
self.assertEqual("This is a checkout. The branch (%s) needs to be "
81
78
"upgraded separately.\n"
82
% transport.get_transport(
83
self.get_url('current_format_branch')).base,
79
% get_transport(self.get_url('current_format_branch')).base,
85
81
self.assertEqualDiff("bzr: ERROR: The branch format Meta "
86
82
"directory format 1 is already at the most "
102
98
def test_upgrade_explicit_metaformat(self):
103
99
# users can force an upgrade to metadir format.
104
100
self.make_format_5_branch()
105
url = transport.get_transport(self.get_url('format_5_branch')).base
101
url = get_transport(self.get_url('format_5_branch')).base
106
102
# check --format takes effect
107
103
bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
108
backup_dir = 'backup.bzr.~1~'
109
104
(out, err) = self.run_bzr(
110
105
['upgrade', '--format=metaweave', url])
111
106
self.assertEqualDiff("""starting upgrade of %s
112
107
making backup of %s.bzr
114
109
starting upgrade from format 5 to 6
115
110
adding prefixes to weaves
116
111
adding prefixes to revision-store
117
112
starting upgrade from format 6 to metadir
119
""" % (url, url, url, backup_dir), out)
114
""" % (url, url, url), out)
120
115
self.assertEqualDiff("", err)
121
116
self.assertTrue(isinstance(
122
117
bzrdir.BzrDir.open(self.get_url('format_5_branch'))._format,
126
121
# users can force an upgrade to knit format from a metadir weave
128
123
self.make_metadir_weave_branch()
129
url = transport.get_transport(self.get_url('metadir_weave_branch')).base
124
url = get_transport(self.get_url('metadir_weave_branch')).base
130
125
# check --format takes effect
131
126
bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
132
backup_dir = 'backup.bzr.~1~'
133
127
(out, err) = self.run_bzr(
134
128
['upgrade', '--format=knit', url])
135
129
self.assertEqualDiff("""starting upgrade of %s
136
130
making backup of %s.bzr
138
132
starting repository conversion
139
133
repository converted
141
""" % (url, url, url, backup_dir), out)
135
""" % (url, url, url), out)
142
136
self.assertEqualDiff("", err)
143
137
converted_dir = bzrdir.BzrDir.open(self.get_url('metadir_weave_branch'))
144
138
self.assertTrue(isinstance(converted_dir._format,
150
144
self.run_bzr('init-repository --format=metaweave repo')
151
145
self.run_bzr('upgrade --format=knit repo')
153
def test_upgrade_permission_check(self):
154
"""'backup.bzr' should retain permissions of .bzr. Bug #262450"""
155
self.requireFeature(features.posix_permissions_feature)
156
old_perms = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
157
backup_dir = 'backup.bzr.~1~'
158
self.run_bzr('init --format=1.6')
159
os.chmod('.bzr', old_perms)
160
self.run_bzr('upgrade')
161
new_perms = os.stat(backup_dir).st_mode & 0777
162
self.assertTrue(new_perms == old_perms)
165
def test_upgrade_with_existing_backup_dir(self):
166
self.make_format_5_branch()
167
t = transport.get_transport(self.get_url('format_5_branch'))
169
bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
170
backup_dir1 = 'backup.bzr.~1~'
171
backup_dir2 = 'backup.bzr.~2~'
172
# explicitly create backup_dir1. bzr should create the .~2~ directory
175
(out, err) = self.run_bzr(
176
['upgrade', '--format=metaweave', url])
177
self.assertEqualDiff("""starting upgrade of %s
178
making backup of %s.bzr
180
starting upgrade from format 5 to 6
181
adding prefixes to weaves
182
adding prefixes to revision-store
183
starting upgrade from format 6 to metadir
185
""" % (url, url, url, backup_dir2), out)
186
self.assertEqualDiff("", err)
187
self.assertTrue(isinstance(
188
bzrdir.BzrDir.open(self.get_url('format_5_branch'))._format,
189
bzrdir.BzrDirMetaFormat1))
190
self.assertTrue(t.has(backup_dir2))
192
148
class SFTPTests(TestCaseWithSFTPServer):
193
149
"""Tests for upgrade over sftp."""
195
151
def test_upgrade_url(self):
196
152
self.run_bzr('init --format=weave')
197
t = transport.get_transport(self.get_url())
153
t = get_transport(self.get_url())
199
155
out, err = self.run_bzr(['upgrade', '--format=knit', url])
200
backup_dir = 'backup.bzr.~1~'
201
156
self.assertEqualDiff("""starting upgrade of %s
202
157
making backup of %s.bzr
204
159
starting upgrade from format 6 to metadir
205
160
starting repository conversion
206
161
repository converted
208
""" % (url, url, url,backup_dir), out)
163
""" % (url, url, url), out)
209
164
self.assertEqual('', err)