1
# Copyright (C) 2006 by Canonical Ltd
2
# Authors: Robert Collins <robert.collins@canonical.com>
3
# -*- coding: utf-8 -*-
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
"""Black box tests for the upgrade ui."""
23
import bzrlib.bzrdir as bzrdir
24
import bzrlib.repository as repository
25
from bzrlib.tests import TestCaseWithTransport
26
from bzrlib.tests.blackbox import TestUIFactory
27
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
28
from bzrlib.transport import get_transport
29
import bzrlib.ui as ui
32
class TestWithUpgradableBranches(TestCaseWithTransport):
35
super(TestWithUpgradableBranches, self).setUp()
36
self.old_format = bzrdir.BzrDirFormat.get_default_format()
37
self.old_ui_factory = ui.ui_factory
38
self.addCleanup(self.restoreDefaults)
40
ui.ui_factory = TestUIFactory()
41
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
42
# FIXME RBC 20060120 we should be able to do this via ui calls only.
43
# setup a format 5 branch we can upgrade from.
44
t = get_transport(self.get_url())
45
t.mkdir('format_5_branch')
46
bzrdir.BzrDirFormat5().initialize(self.get_url('format_5_branch'))
47
bzrdir.BzrDir.create_standalone_workingtree('current_format_branch')
48
d = bzrdir.BzrDir.create('metadir_weave_branch')
51
d.create_workingtree()
52
self.run_bzr('checkout',
54
self.get_url('current_format_branch'),
55
'current_format_checkout')
57
def restoreDefaults(self):
58
bzrdir.BzrDirFormat.set_default_format(self.old_format)
59
ui.ui_factory = self.old_ui_factory
61
def test_readonly_url_error(self):
62
(out, err) = self.run_bzr_captured(
63
['upgrade', self.get_readonly_url('format_5_branch')], 3)
64
self.assertEqual(out, "")
65
self.assertEqual(err, "bzr: ERROR: Upgrade URL cannot work with readonly URL's.\n")
67
def test_upgrade_up_to_date(self):
68
# when up to date we should get a message to that effect
69
(out, err) = self.run_bzr_captured(
70
['upgrade', 'current_format_branch'], 3)
71
self.assertEqual("", out)
72
self.assertEqualDiff("bzr: ERROR: The branch format Bazaar-NG meta "
73
"directory, format 1 is already at the most "
74
"recent format.\n", err)
76
def test_upgrade_up_to_date_checkout_warns_branch_left_alone(self):
77
# when upgrading a checkout, the branch location and a suggestion
78
# to upgrade it should be emitted even if the checkout is up to
80
(out, err) = self.run_bzr_captured(
81
['upgrade', 'current_format_checkout'], 3)
82
self.assertEqual("This is a checkout. The branch (%s) needs to be "
83
"upgraded separately.\n"
84
% get_transport(self.get_url('current_format_branch')).base,
86
self.assertEqualDiff("bzr: ERROR: The branch format Bazaar-NG meta "
87
"directory, format 1 is already at the most "
88
"recent format.\n", err)
90
def test_upgrade_checkout(self):
91
# upgrading a checkout should work
94
def test_upgrade_repository_scans_branches(self):
95
# we should get individual upgrade notes for each branch even the
99
def test_ugrade_branch_in_repo(self):
100
# upgrading a branch in a repo should warn about not upgrading the repo
103
def test_upgrade_explicit_metaformat(self):
104
# users can force an upgrade to metadir format.
105
url = get_transport(self.get_url('format_5_branch')).base
106
# check --format takes effect
107
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirFormat5())
108
(out, err) = self.run_bzr_captured(
109
['upgrade', '--format=metadir', url])
110
self.assertEqualDiff("""starting upgrade of %s
111
making backup of tree history
112
%s.bzr has been backed up to %s.bzr.backup
113
if conversion fails, you can move this directory back to .bzr
114
if it succeeds, you can remove this directory if you wish
115
starting upgrade from format 5 to 6
116
adding prefixes to weaves
117
adding prefixes to revision-store
118
starting upgrade from format 6 to metadir
120
""" % (url, url, url), out)
121
self.assertEqualDiff("", err)
122
self.assertTrue(isinstance(
123
bzrdir.BzrDir.open(self.get_url('format_5_branch'))._format,
124
bzrdir.BzrDirMetaFormat1))
126
def test_upgrade_explicit_knit(self):
127
# users can force an upgrade to knit format from a metadir weave
129
url = get_transport(self.get_url('metadir_weave_branch')).base
130
# check --format takes effect
131
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirFormat5())
132
(out, err) = self.run_bzr_captured(
133
['upgrade', '--format=knit', url])
134
self.assertEqualDiff("""starting upgrade of %s
135
making backup of tree history
136
%s.bzr has been backed up to %s.bzr.backup
137
if conversion fails, you can move this directory back to .bzr
138
if it succeeds, you can remove this directory if you wish
139
starting repository conversion
142
""" % (url, url, url), out)
143
self.assertEqualDiff("", err)
144
converted_dir = bzrdir.BzrDir.open(self.get_url('metadir_weave_branch'))
145
self.assertTrue(isinstance(converted_dir._format,
146
bzrdir.BzrDirMetaFormat1))
147
self.assertTrue(isinstance(converted_dir.open_repository()._format,
148
repository.RepositoryFormatKnit1))
150
def test_upgrade_repo(self):
151
self.run_bzr('init-repository', '--format=metadir', 'repo')
152
self.run_bzr('upgrade', '--format=knit', 'repo')
155
class SFTPTests(TestCaseWithSFTPServer):
156
"""Tests for upgrade over sftp."""
159
super(SFTPTests, self).setUp()
160
self.old_ui_factory = ui.ui_factory
161
self.addCleanup(self.restoreDefaults)
163
ui.ui_factory = TestUIFactory()
165
def restoreDefaults(self):
166
ui.ui_factory = self.old_ui_factory
168
def test_upgrade_url(self):
169
self.run_bzr('init', '--format=weave')
170
t = get_transport(self.get_url())
172
out, err = self.run_bzr('upgrade', '--format=knit', url)
173
self.assertEqualDiff("""starting upgrade of %s
174
making backup of tree history
175
%s.bzr has been backed up to %s.bzr.backup
176
if conversion fails, you can move this directory back to .bzr
177
if it succeeds, you can remove this directory if you wish
178
starting upgrade from format 6 to metadir
179
starting repository conversion
182
""" % (url, url, url), out)
183
self.assertEqual('', err)