1
# Copyright (C) 2006 by Canonical Ltd
2
# Authors: Robert Collins <robert.collins@canonical.com>
3
# -*- coding: utf-8 -*-
1
# Copyright (C) 2006, 2007, 2009 Canonical Ltd
5
3
# This program is free software; you can redistribute it and/or modify
6
4
# it under the terms of the GNU General Public License as published by
7
5
# the Free Software Foundation; either version 2 of the License, or
8
6
# (at your option) any later version.
10
8
# This program is distributed in the hope that it will be useful,
11
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
11
# GNU General Public License for more details.
15
13
# You should have received a copy of the GNU General Public License
16
14
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
17
"""Black box tests for the upgrade ui."""
24
import bzrlib.bzrdir as bzrdir
25
import bzrlib.repository as repository
26
from bzrlib.tests import TestCaseWithTransport
27
from bzrlib.tests.blackbox import TestUIFactory
26
from bzrlib.tests import (
28
TestCaseWithTransport,
28
31
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
29
32
from bzrlib.transport import get_transport
30
import bzrlib.ui as ui
33
from bzrlib.repofmt.knitrepo import (
34
RepositoryFormatKnit1,
33
38
class TestWithUpgradableBranches(TestCaseWithTransport):
36
41
super(TestWithUpgradableBranches, self).setUp()
37
42
self.old_format = bzrdir.BzrDirFormat.get_default_format()
38
self.old_repo_format = \
39
bzrlib.repository.RepositoryFormat.get_default_format()
40
43
self.old_ui_factory = ui.ui_factory
41
44
self.addCleanup(self.restoreDefaults)
43
46
ui.ui_factory = TestUIFactory()
44
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
45
bzrlib.repository.RepositoryFormat.set_default_format(
46
bzrlib.repository.RepositoryFormat7())
47
# FIXME RBC 20060120 we should be able to do this via ui calls only.
48
47
# setup a format 5 branch we can upgrade from.
49
t = get_transport(self.get_url())
50
t.mkdir('format_5_branch')
51
bzrdir.BzrDirFormat5().initialize(self.get_url('format_5_branch'))
52
bzrdir.BzrDir.create_standalone_workingtree('current_format_branch')
53
d = bzrdir.BzrDir.create('metadir_weave_branch')
56
d.create_workingtree()
57
self.run_bzr('checkout',
59
self.get_url('current_format_branch'),
60
'current_format_checkout')
48
self.make_branch_and_tree('format_5_branch',
49
format=bzrdir.BzrDirFormat5())
51
current_tree = self.make_branch_and_tree('current_format_branch',
53
self.make_branch_and_tree('metadir_weave_branch', format='metaweave')
54
current_tree.branch.create_checkout(
55
self.get_url('current_format_checkout'), lightweight=True)
62
57
def restoreDefaults(self):
63
bzrdir.BzrDirFormat.set_default_format(self.old_format)
64
bzrlib.repository.RepositoryFormat.set_default_format(
66
58
ui.ui_factory = self.old_ui_factory
59
bzrdir.BzrDirFormat._set_default_format(self.old_format)
68
61
def test_readonly_url_error(self):
69
(out, err) = self.run_bzr_captured(
70
['upgrade', self.get_readonly_url('format_5_branch')], 3)
62
(out, err) = self.run_bzr(
63
['upgrade', self.get_readonly_url('format_5_branch')], retcode=3)
71
64
self.assertEqual(out, "")
72
self.assertEqual(err, "bzr: ERROR: Upgrade URL cannot work with readonly URL's.\n")
65
self.assertEqual(err, "bzr: ERROR: Upgrade URL cannot work with readonly URLs.\n")
74
67
def test_upgrade_up_to_date(self):
75
68
# when up to date we should get a message to that effect
76
(out, err) = self.run_bzr_captured(
77
['upgrade', 'current_format_branch'], 3)
69
(out, err) = self.run_bzr('upgrade current_format_branch', retcode=3)
78
70
self.assertEqual("", out)
79
self.assertEqualDiff("bzr: ERROR: The branch format Bazaar-NG meta "
80
"directory, format 1 is already at the most "
71
self.assertEqualDiff("bzr: ERROR: The branch format Meta "
72
"directory format 1 is already at the most "
81
73
"recent format.\n", err)
83
75
def test_upgrade_up_to_date_checkout_warns_branch_left_alone(self):
84
76
# when upgrading a checkout, the branch location and a suggestion
85
# to upgrade it should be emitted even if the checkout is up to
77
# to upgrade it should be emitted even if the checkout is up to
87
(out, err) = self.run_bzr_captured(
88
['upgrade', 'current_format_checkout'], 3)
79
(out, err) = self.run_bzr('upgrade current_format_checkout', retcode=3)
89
80
self.assertEqual("This is a checkout. The branch (%s) needs to be "
90
"upgraded separately.\n"
81
"upgraded separately.\n"
91
82
% get_transport(self.get_url('current_format_branch')).base,
93
self.assertEqualDiff("bzr: ERROR: The branch format Bazaar-NG meta "
94
"directory, format 1 is already at the most "
84
self.assertEqualDiff("bzr: ERROR: The branch format Meta "
85
"directory format 1 is already at the most "
95
86
"recent format.\n", err)
97
88
def test_upgrade_checkout(self):
111
102
# users can force an upgrade to metadir format.
112
103
url = get_transport(self.get_url('format_5_branch')).base
113
104
# check --format takes effect
114
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirFormat5())
115
(out, err) = self.run_bzr_captured(
105
bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
106
(out, err) = self.run_bzr(
116
107
['upgrade', '--format=metaweave', url])
117
108
self.assertEqualDiff("""starting upgrade of %s
118
making backup of tree history
119
%s.bzr has been backed up to %s.bzr.backup
120
if conversion fails, you can move this directory back to .bzr
121
if it succeeds, you can remove this directory if you wish
109
making backup of %s.bzr
122
111
starting upgrade from format 5 to 6
123
112
adding prefixes to weaves
124
113
adding prefixes to revision-store
131
120
bzrdir.BzrDirMetaFormat1))
133
122
def test_upgrade_explicit_knit(self):
134
# users can force an upgrade to knit format from a metadir weave
123
# users can force an upgrade to knit format from a metadir weave
136
125
url = get_transport(self.get_url('metadir_weave_branch')).base
137
126
# check --format takes effect
138
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirFormat5())
139
(out, err) = self.run_bzr_captured(
127
bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
128
(out, err) = self.run_bzr(
140
129
['upgrade', '--format=knit', url])
141
130
self.assertEqualDiff("""starting upgrade of %s
142
making backup of tree history
143
%s.bzr has been backed up to %s.bzr.backup
144
if conversion fails, you can move this directory back to .bzr
145
if it succeeds, you can remove this directory if you wish
131
making backup of %s.bzr
146
133
starting repository conversion
147
134
repository converted
152
139
self.assertTrue(isinstance(converted_dir._format,
153
140
bzrdir.BzrDirMetaFormat1))
154
141
self.assertTrue(isinstance(converted_dir.open_repository()._format,
155
repository.RepositoryFormatKnit1))
142
RepositoryFormatKnit1))
157
144
def test_upgrade_repo(self):
158
self.run_bzr('init-repository', '--format=metaweave', 'repo')
159
self.run_bzr('upgrade', '--format=knit', 'repo')
145
self.run_bzr('init-repository --format=metaweave repo')
146
self.run_bzr('upgrade --format=knit repo')
162
149
class SFTPTests(TestCaseWithSFTPServer):
173
160
ui.ui_factory = self.old_ui_factory
175
162
def test_upgrade_url(self):
176
self.run_bzr('init', '--format=weave')
163
self.run_bzr('init --format=weave')
177
164
t = get_transport(self.get_url())
179
out, err = self.run_bzr('upgrade', '--format=knit', url)
166
out, err = self.run_bzr(['upgrade', '--format=knit', url])
180
167
self.assertEqualDiff("""starting upgrade of %s
181
making backup of tree history
182
%s.bzr has been backed up to %s.bzr.backup
183
if conversion fails, you can move this directory back to .bzr
184
if it succeeds, you can remove this directory if you wish
168
making backup of %s.bzr
185
170
starting upgrade from format 6 to metadir
186
171
starting repository conversion
187
172
repository converted
189
174
""" % (url, url, url), out)
190
175
self.assertEqual('', err)
178
class UpgradeRecommendedTests(TestCaseInTempDir):
180
def test_recommend_upgrade_wt4(self):
181
# using a deprecated format gives a warning
182
self.run_bzr('init --knit a')
183
out, err = self.run_bzr('status a')
184
self.assertContainsRe(err, 'bzr upgrade .*[/\\\\]a')
186
def test_no_upgrade_recommendation_from_bzrdir(self):
187
# we should only get a recommendation to upgrade when we're accessing
188
# the actual workingtree, not when we only open a bzrdir that contains
190
self.run_bzr('init --knit a')
191
out, err = self.run_bzr('revno a')
192
if err.find('upgrade') > -1:
193
self.fail("message shouldn't suggest upgrade:\n%s" % err)