1
# Copyright (C) 2006-2010 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""Black box tests for the upgrade ui."""
26
from bzrlib.tests import (
28
TestCaseWithTransport,
30
posix_permissions_feature,
32
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
33
from bzrlib.transport import get_transport
34
from bzrlib.repofmt.knitrepo import (
35
RepositoryFormatKnit1,
39
class TestWithUpgradableBranches(TestCaseWithTransport):
42
super(TestWithUpgradableBranches, self).setUp()
43
self.old_format = bzrdir.BzrDirFormat.get_default_format()
44
self.old_ui_factory = ui.ui_factory
45
self.addCleanup(self.restoreDefaults)
46
ui.ui_factory = TestUIFactory()
48
def restoreDefaults(self):
49
ui.ui_factory = self.old_ui_factory
50
bzrdir.BzrDirFormat._set_default_format(self.old_format)
52
def make_current_format_branch_and_checkout(self):
53
current_tree = self.make_branch_and_tree('current_format_branch',
55
current_tree.branch.create_checkout(
56
self.get_url('current_format_checkout'), lightweight=True)
58
def make_format_5_branch(self):
59
# setup a format 5 branch we can upgrade from.
60
self.make_branch_and_tree('format_5_branch',
61
format=bzrdir.BzrDirFormat5())
63
def make_metadir_weave_branch(self):
64
self.make_branch_and_tree('metadir_weave_branch', format='metaweave')
66
def test_readonly_url_error(self):
67
self.make_format_5_branch()
68
(out, err) = self.run_bzr(
69
['upgrade', self.get_readonly_url('format_5_branch')], retcode=3)
70
self.assertEqual(out, "")
71
self.assertEqual(err, "bzr: ERROR: Upgrade URL cannot work with readonly URLs.\n")
73
def test_upgrade_up_to_date(self):
74
self.make_current_format_branch_and_checkout()
75
# when up to date we should get a message to that effect
76
(out, err) = self.run_bzr('upgrade current_format_branch', retcode=3)
77
self.assertEqual("", out)
78
self.assertEqualDiff("bzr: ERROR: The branch format Meta "
79
"directory format 1 is already at the most "
80
"recent format.\n", err)
82
def test_upgrade_up_to_date_checkout_warns_branch_left_alone(self):
83
self.make_current_format_branch_and_checkout()
84
# when upgrading a checkout, the branch location and a suggestion
85
# to upgrade it should be emitted even if the checkout is up to
87
(out, err) = self.run_bzr('upgrade current_format_checkout', retcode=3)
88
self.assertEqual("This is a checkout. The branch (%s) needs to be "
89
"upgraded separately.\n"
90
% get_transport(self.get_url('current_format_branch')).base,
92
self.assertEqualDiff("bzr: ERROR: The branch format Meta "
93
"directory format 1 is already at the most "
94
"recent format.\n", err)
96
def test_upgrade_checkout(self):
97
# upgrading a checkout should work
100
def test_upgrade_repository_scans_branches(self):
101
# we should get individual upgrade notes for each branch even the
105
def test_ugrade_branch_in_repo(self):
106
# 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
self.make_format_5_branch()
112
url = get_transport(self.get_url('format_5_branch')).base
113
# check --format takes effect
114
bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
115
(out, err) = self.run_bzr(
116
['upgrade', '--format=metaweave', url])
117
self.assertEqualDiff("""starting upgrade of %s
118
making backup of %s.bzr
120
starting upgrade from format 5 to 6
121
adding prefixes to weaves
122
adding prefixes to revision-store
123
starting upgrade from format 6 to metadir
125
""" % (url, url, url), out)
126
self.assertEqualDiff("", err)
127
self.assertTrue(isinstance(
128
bzrdir.BzrDir.open(self.get_url('format_5_branch'))._format,
129
bzrdir.BzrDirMetaFormat1))
131
def test_upgrade_explicit_knit(self):
132
# users can force an upgrade to knit format from a metadir weave
134
self.make_metadir_weave_branch()
135
url = get_transport(self.get_url('metadir_weave_branch')).base
136
# check --format takes effect
137
bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
138
(out, err) = self.run_bzr(
139
['upgrade', '--format=knit', url])
140
self.assertEqualDiff("""starting upgrade of %s
141
making backup of %s.bzr
143
starting repository conversion
146
""" % (url, url, url), out)
147
self.assertEqualDiff("", err)
148
converted_dir = bzrdir.BzrDir.open(self.get_url('metadir_weave_branch'))
149
self.assertTrue(isinstance(converted_dir._format,
150
bzrdir.BzrDirMetaFormat1))
151
self.assertTrue(isinstance(converted_dir.open_repository()._format,
152
RepositoryFormatKnit1))
154
def test_upgrade_repo(self):
155
self.run_bzr('init-repository --format=metaweave repo')
156
self.run_bzr('upgrade --format=knit repo')
158
def test_upgrade_permission_check(self):
159
"""'backup.bzr' should retain permissions of .bzr. Bug #262450"""
160
self.requireFeature(posix_permissions_feature)
162
old_perms = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
163
backup_dir = 'backup.bzr'
164
self.run_bzr('init --format=1.6')
165
os.chmod('.bzr', old_perms)
166
self.run_bzr('upgrade')
167
new_perms = os.stat(backup_dir).st_mode & 0777
168
self.assertTrue(new_perms == old_perms)
171
class SFTPTests(TestCaseWithSFTPServer):
172
"""Tests for upgrade over sftp."""
175
super(SFTPTests, self).setUp()
176
self.old_ui_factory = ui.ui_factory
177
self.addCleanup(self.restoreDefaults)
179
ui.ui_factory = TestUIFactory()
181
def restoreDefaults(self):
182
ui.ui_factory = self.old_ui_factory
184
def test_upgrade_url(self):
185
self.run_bzr('init --format=weave')
186
t = get_transport(self.get_url())
188
out, err = self.run_bzr(['upgrade', '--format=knit', url])
189
self.assertEqualDiff("""starting upgrade of %s
190
making backup of %s.bzr
192
starting upgrade from format 6 to metadir
193
starting repository conversion
196
""" % (url, url, url), out)
197
self.assertEqual('', err)
200
class UpgradeRecommendedTests(TestCaseWithTransport):
202
def test_recommend_upgrade_wt4(self):
203
# using a deprecated format gives a warning
204
self.run_bzr('init --knit a')
205
out, err = self.run_bzr('status a')
206
self.assertContainsRe(err, 'bzr upgrade .*[/\\\\]a')
208
def test_no_upgrade_recommendation_from_bzrdir(self):
209
# we should only get a recommendation to upgrade when we're accessing
210
# the actual workingtree, not when we only open a bzrdir that contains
212
self.run_bzr('init --knit a')
213
out, err = self.run_bzr('revno a')
214
if err.find('upgrade') > -1:
215
self.fail("message shouldn't suggest upgrade:\n%s" % err)
217
def test_upgrade_shared_repo(self):
218
repo = self.make_repository('repo', format='2a', shared=True)
219
branch = self.make_branch_and_tree('repo/branch', format="pack-0.92")
220
self.get_transport('repo/branch/.bzr/repository').delete_tree('.')
221
out, err = self.run_bzr(['upgrade'], working_dir='repo/branch')