/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_upgrade.py

  • Committer: Robert Collins
  • Date: 2007-04-19 02:27:44 UTC
  • mto: This revision was merged to the branch mainline in revision 2426.
  • Revision ID: robertc@robertcollins.net-20070419022744-pfdqz42kp1wizh43
``make docs`` now creates a man page at ``man1/bzr.1`` fixing bug 107388.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 2006, 2007 Canonical Ltd
 
2
# Authors: Robert Collins <robert.collins@canonical.com>
 
3
#          and others
2
4
#
3
5
# This program is free software; you can redistribute it and/or modify
4
6
# it under the terms of the GNU General Public License as published by
12
14
#
13
15
# You should have received a copy of the GNU General Public License
14
16
# 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
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
18
 
17
19
"""Black box tests for the upgrade ui."""
 
20
 
18
21
import os
19
 
import stat
20
22
 
21
23
from bzrlib import (
22
24
    bzrdir,
23
 
    controldir,
24
 
    lockable_files,
 
25
    repository,
25
26
    ui,
26
27
    )
27
28
from bzrlib.tests import (
28
 
    features,
 
29
    TestCaseInTempDir,
29
30
    TestCaseWithTransport,
 
31
    TestUIFactory,
30
32
    )
31
33
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
32
 
from bzrlib.repofmt.knitpack_repo import RepositoryFormatKnitPack1
33
 
 
34
 
 
35
 
class OldBzrDir(bzrdir.BzrDirMeta1):
36
 
    """An test bzr dir implementation"""
37
 
 
38
 
    def needs_format_conversion(self, format):
39
 
        return not isinstance(format, self.__class__)
40
 
 
41
 
 
42
 
class ConvertOldTestToMeta(controldir.Converter):
43
 
    """A trivial converter, used for testing."""
44
 
 
45
 
    def convert(self, to_convert, pb):
46
 
        ui.ui_factory.note('starting upgrade from old test format to 2a')
47
 
        to_convert.control_transport.put_bytes(
48
 
            'branch-format',
49
 
            bzrdir.BzrDirMetaFormat1().get_format_string(),
50
 
            mode=to_convert._get_file_mode())
51
 
        return bzrdir.BzrDir.open(to_convert.user_url)
52
 
 
53
 
 
54
 
class OldBzrDirFormat(bzrdir.BzrDirMetaFormat1):
55
 
 
56
 
    _lock_class = lockable_files.TransportLock
57
 
 
58
 
    def get_converter(self, format=None):
59
 
        return ConvertOldTestToMeta()
60
 
 
61
 
    def get_format_string(self):
62
 
        return "Ancient Test Format"
63
 
 
64
 
    def _open(self, transport):
65
 
        return OldBzrDir(transport, self)
 
34
from bzrlib.transport import get_transport
 
35
from bzrlib.repofmt.knitrepo import (
 
36
    RepositoryFormatKnit1,
 
37
    )
66
38
 
67
39
 
68
40
class TestWithUpgradableBranches(TestCaseWithTransport):
69
41
 
70
42
    def setUp(self):
71
43
        super(TestWithUpgradableBranches, self).setUp()
72
 
 
73
 
    def make_current_format_branch_and_checkout(self):
 
44
        self.old_format = bzrdir.BzrDirFormat.get_default_format()
 
45
        self.old_ui_factory = ui.ui_factory
 
46
        self.addCleanup(self.restoreDefaults)
 
47
 
 
48
        ui.ui_factory = TestUIFactory()
 
49
        # setup a format 5 branch we can upgrade from.
 
50
        self.make_branch_and_tree('format_5_branch',
 
51
                                  format=bzrdir.BzrDirFormat5())
 
52
 
74
53
        current_tree = self.make_branch_and_tree('current_format_branch',
75
54
                                                 format='default')
 
55
        self.make_branch_and_tree('metadir_weave_branch', format='metaweave')
76
56
        current_tree.branch.create_checkout(
77
57
            self.get_url('current_format_checkout'), lightweight=True)
78
58
 
 
59
    def restoreDefaults(self):
 
60
        ui.ui_factory = self.old_ui_factory
 
61
        bzrdir.BzrDirFormat._set_default_format(self.old_format)
 
62
 
79
63
    def test_readonly_url_error(self):
80
 
        self.make_branch_and_tree("old_format_branch", format="knit")
81
 
        (out, err) = self.run_bzr(
82
 
            ['upgrade', self.get_readonly_url("old_format_branch")], retcode=3)
83
 
        err_msg = 'Upgrade URL cannot work with readonly URLs.'
84
 
        self.assertEqualDiff('conversion error: %s\nbzr: ERROR: %s\n'
85
 
                             % (err_msg, err_msg),
86
 
                             err)
 
64
        (out, err) = self.run_bzr_captured(
 
65
            ['upgrade', self.get_readonly_url('format_5_branch')], 3)
 
66
        self.assertEqual(out, "")
 
67
        self.assertEqual(err, "bzr: ERROR: Upgrade URL cannot work with readonly URLs.\n")
87
68
 
88
69
    def test_upgrade_up_to_date(self):
89
 
        self.make_current_format_branch_and_checkout()
90
70
        # when up to date we should get a message to that effect
91
 
        (out, err) = self.run_bzr('upgrade current_format_branch', retcode=3)
92
 
        err_msg = ('The branch format %s is already at the most recent format.'
93
 
                   % ('Meta directory format 1'))
94
 
        self.assertEqualDiff('conversion error: %s\nbzr: ERROR: %s\n'
95
 
                             % (err_msg, err_msg),
96
 
                             err)
 
71
        (out, err) = self.run_bzr_captured(
 
72
            ['upgrade', 'current_format_branch'], 3)
 
73
        self.assertEqual("", out)
 
74
        self.assertEqualDiff("bzr: ERROR: The branch format Bazaar-NG meta "
 
75
                             "directory, format 1 is already at the most "
 
76
                             "recent format.\n", err)
97
77
 
98
78
    def test_upgrade_up_to_date_checkout_warns_branch_left_alone(self):
99
 
        self.make_current_format_branch_and_checkout()
100
79
        # when upgrading a checkout, the branch location and a suggestion
101
 
        # to upgrade it should be emitted even if the checkout is up to
 
80
        # to upgrade it should be emitted even if the checkout is up to 
102
81
        # date
103
 
        burl = self.get_transport('current_format_branch').base
104
 
        curl = self.get_transport('current_format_checkout').base
105
 
        (out, err) = self.run_bzr('upgrade current_format_checkout', retcode=3)
106
 
        self.assertEqual(
107
 
            'Upgrading branch %s ...\nThis is a checkout.'
108
 
            ' The branch (%s) needs to be upgraded separately.\n'
109
 
            % (curl, burl),
110
 
            out)
111
 
        msg = 'The branch format %s is already at the most recent format.' % (
112
 
            'Meta directory format 1')
113
 
        self.assertEqualDiff('conversion error: %s\nbzr: ERROR: %s\n'
114
 
                             % (msg, msg),
115
 
                             err)
 
82
        (out, err) = self.run_bzr_captured(
 
83
            ['upgrade', 'current_format_checkout'], 3)
 
84
        self.assertEqual("This is a checkout. The branch (%s) needs to be "
 
85
                         "upgraded separately.\n" 
 
86
                         % get_transport(self.get_url('current_format_branch')).base,
 
87
                         out)
 
88
        self.assertEqualDiff("bzr: ERROR: The branch format Bazaar-NG meta "
 
89
                             "directory, format 1 is already at the most "
 
90
                             "recent format.\n", err)
116
91
 
117
92
    def test_upgrade_checkout(self):
118
93
        # upgrading a checkout should work
119
94
        pass
120
95
 
121
96
    def test_upgrade_repository_scans_branches(self):
122
 
        # we should get individual upgrade notes for each branch even the
 
97
        # we should get individual upgrade notes for each branch even the 
123
98
        # anonymous branch
124
99
        pass
125
100
 
126
 
    def test_upgrade_branch_in_repo(self):
 
101
    def test_ugrade_branch_in_repo(self):
127
102
        # upgrading a branch in a repo should warn about not upgrading the repo
128
103
        pass
129
104
 
130
 
    def test_upgrade_control_dir(self):
131
 
        old_format = OldBzrDirFormat()
132
 
        self.addCleanup(bzrdir.BzrProber.formats.remove,
133
 
            old_format.get_format_string())
134
 
        bzrdir.BzrProber.formats.register(old_format.get_format_string(),
135
 
            old_format)
136
 
        self.addCleanup(controldir.ControlDirFormat._set_default_format,
137
 
                        controldir.ControlDirFormat.get_default_format())
138
 
 
139
 
        # setup an old format branch we can upgrade from.
140
 
        path = 'old_format_branch'
141
 
        self.make_branch_and_tree(path, format=old_format)
142
 
        url = self.get_transport(path).base
 
105
    def test_upgrade_explicit_metaformat(self):
 
106
        # users can force an upgrade to metadir format.
 
107
        url = get_transport(self.get_url('format_5_branch')).base
143
108
        # check --format takes effect
144
 
        controldir.ControlDirFormat._set_default_format(old_format)
145
 
        backup_dir = 'backup.bzr.~1~'
146
 
        (out, err) = self.run_bzr(
147
 
            ['upgrade', '--format=2a', url])
148
 
        self.assertEqualDiff("""Upgrading branch %s ...
149
 
starting upgrade of %s
150
 
making backup of %s.bzr
151
 
  to %s%s
152
 
starting upgrade from old test format to 2a
 
109
        bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
 
110
        (out, err) = self.run_bzr_captured(
 
111
            ['upgrade', '--format=metaweave', url])
 
112
        self.assertEqualDiff("""starting upgrade of %s
 
113
making backup of tree history
 
114
%s.bzr has been backed up to %s.bzr.backup
 
115
if conversion fails, you can move this directory back to .bzr
 
116
if it succeeds, you can remove this directory if you wish
 
117
starting upgrade from format 5 to 6
 
118
adding prefixes to weaves
 
119
adding prefixes to revision-store
 
120
starting upgrade from format 6 to metadir
153
121
finished
154
 
""" % (url, url, url, url, backup_dir), out)
 
122
""" % (url, url, url), out)
155
123
        self.assertEqualDiff("", err)
156
124
        self.assertTrue(isinstance(
157
 
            bzrdir.BzrDir.open(self.get_url(path))._format,
 
125
            bzrdir.BzrDir.open(self.get_url('format_5_branch'))._format,
158
126
            bzrdir.BzrDirMetaFormat1))
159
127
 
160
128
    def test_upgrade_explicit_knit(self):
161
 
        # users can force an upgrade to knit format from a metadir pack 0.92
162
 
        # branch to a 2a branch.
163
 
        self.make_branch_and_tree('branch', format='knit')
164
 
        url = self.get_transport('branch').base
 
129
        # users can force an upgrade to knit format from a metadir weave 
 
130
        # branch
 
131
        url = get_transport(self.get_url('metadir_weave_branch')).base
165
132
        # check --format takes effect
166
 
        backup_dir = 'backup.bzr.~1~'
167
 
        (out, err) = self.run_bzr(
168
 
            ['upgrade', '--format=pack-0.92', url])
169
 
        self.assertEqualDiff("""Upgrading branch %s ...
170
 
starting upgrade of %s
171
 
making backup of %s.bzr
172
 
  to %s%s
 
133
        bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
 
134
        (out, err) = self.run_bzr_captured(
 
135
            ['upgrade', '--format=knit', url])
 
136
        self.assertEqualDiff("""starting upgrade of %s
 
137
making backup of tree history
 
138
%s.bzr has been backed up to %s.bzr.backup
 
139
if conversion fails, you can move this directory back to .bzr
 
140
if it succeeds, you can remove this directory if you wish
173
141
starting repository conversion
174
142
repository converted
175
143
finished
176
 
""" % (url, url, url, url, backup_dir),
177
 
                             out)
 
144
""" % (url, url, url), out)
178
145
        self.assertEqualDiff("", err)
179
 
        converted_dir = bzrdir.BzrDir.open(self.get_url('branch'))
 
146
        converted_dir = bzrdir.BzrDir.open(self.get_url('metadir_weave_branch'))
180
147
        self.assertTrue(isinstance(converted_dir._format,
181
148
                                   bzrdir.BzrDirMetaFormat1))
182
149
        self.assertTrue(isinstance(converted_dir.open_repository()._format,
183
 
                                   RepositoryFormatKnitPack1))
 
150
                                   RepositoryFormatKnit1))
184
151
 
185
152
    def test_upgrade_repo(self):
186
 
        self.run_bzr('init-repository --format=pack-0.92 repo')
187
 
        self.run_bzr('upgrade --format=2a repo')
188
 
 
189
 
    def assertLegalOption(self, option_str):
190
 
        # Confirm that an option is legal. (Lower level tests are
191
 
        # expected to validate the actual functionality.)
192
 
        self.run_bzr('init --format=pack-0.92 branch-foo')
193
 
        self.run_bzr('upgrade --format=2a branch-foo %s' % (option_str,))
194
 
 
195
 
    def assertBranchFormat(self, dir, format):
196
 
        branch = bzrdir.BzrDir.open_tree_or_branch(self.get_url(dir))[1]
197
 
        branch_format = branch._format
198
 
        meta_format = bzrdir.format_registry.make_bzrdir(format)
199
 
        expected_format = meta_format.get_branch_format()
200
 
        self.assertEqual(expected_format, branch_format)
201
 
 
202
 
    def test_upgrade_clean_supported(self):
203
 
        self.assertLegalOption('--clean')
204
 
        self.assertBranchFormat('branch-foo', '2a')
205
 
        backup_bzr_dir = os.path.join("branch-foo", "backup.bzr.~1~")
206
 
        self.assertFalse(os.path.exists(backup_bzr_dir))
207
 
 
208
 
    def test_upgrade_dry_run_supported(self):
209
 
        self.assertLegalOption('--dry-run')
210
 
        self.assertBranchFormat('branch-foo', 'pack-0.92')
211
 
 
212
 
    def test_upgrade_permission_check(self):
213
 
        """'backup.bzr' should retain permissions of .bzr. Bug #262450"""
214
 
        self.requireFeature(features.posix_permissions_feature)
215
 
        old_perms = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
216
 
        backup_dir = 'backup.bzr.~1~'
217
 
        self.run_bzr('init --format=1.6')
218
 
        os.chmod('.bzr', old_perms)
219
 
        self.run_bzr('upgrade')
220
 
        new_perms = os.stat(backup_dir).st_mode & 0777
221
 
        self.assertTrue(new_perms == old_perms)
222
 
 
223
 
    def test_upgrade_with_existing_backup_dir(self):
224
 
        self.make_branch_and_tree("old_format_branch", format="knit")
225
 
        t = self.get_transport("old_format_branch")
226
 
        url = t.base
227
 
        backup_dir1 = 'backup.bzr.~1~'
228
 
        backup_dir2 = 'backup.bzr.~2~'
229
 
        # explicitly create backup_dir1. bzr should create the .~2~ directory
230
 
        # as backup
231
 
        t.mkdir(backup_dir1)
232
 
        (out, err) = self.run_bzr(
233
 
            ['upgrade', '--format=2a', url])
234
 
        self.assertEqualDiff("""Upgrading branch %s ...
235
 
starting upgrade of %s
236
 
making backup of %s.bzr
237
 
  to %s%s
238
 
starting repository conversion
239
 
repository converted
240
 
finished
241
 
""" % (url, url, url, url, backup_dir2), out)
242
 
        self.assertEqualDiff("", err)
243
 
        self.assertTrue(isinstance(
244
 
            bzrdir.BzrDir.open(self.get_url("old_format_branch"))._format,
245
 
            bzrdir.BzrDirMetaFormat1))
246
 
        self.assertTrue(t.has(backup_dir2))
 
153
        self.run_bzr('init-repository', '--format=metaweave', 'repo')
 
154
        self.run_bzr('upgrade', '--format=knit', 'repo')
247
155
 
248
156
 
249
157
class SFTPTests(TestCaseWithSFTPServer):
250
158
    """Tests for upgrade over sftp."""
251
159
 
 
160
    def setUp(self):
 
161
        super(SFTPTests, self).setUp()
 
162
        self.old_ui_factory = ui.ui_factory
 
163
        self.addCleanup(self.restoreDefaults)
 
164
 
 
165
        ui.ui_factory = TestUIFactory()
 
166
 
 
167
    def restoreDefaults(self):
 
168
        ui.ui_factory = self.old_ui_factory
 
169
 
252
170
    def test_upgrade_url(self):
253
 
        self.run_bzr('init --format=pack-0.92')
254
 
        t = self.get_transport()
 
171
        self.run_bzr('init', '--format=weave')
 
172
        t = get_transport(self.get_url())
255
173
        url = t.base
256
 
        out, err = self.run_bzr(['upgrade', '--format=2a', url])
257
 
        backup_dir = 'backup.bzr.~1~'
258
 
        self.assertEqualDiff("""Upgrading branch %s ...
259
 
starting upgrade of %s
260
 
making backup of %s.bzr
261
 
  to %s%s
 
174
        out, err = self.run_bzr('upgrade', '--format=knit', url)
 
175
        self.assertEqualDiff("""starting upgrade of %s
 
176
making backup of tree history
 
177
%s.bzr has been backed up to %s.bzr.backup
 
178
if conversion fails, you can move this directory back to .bzr
 
179
if it succeeds, you can remove this directory if you wish
 
180
starting upgrade from format 6 to metadir
262
181
starting repository conversion
263
182
repository converted
264
183
finished
265
 
""" % (url, url, url, url,backup_dir), out)
 
184
""" % (url, url, url), out)
266
185
        self.assertEqual('', err)
267
186
 
268
187
 
269
 
class UpgradeRecommendedTests(TestCaseWithTransport):
 
188
class UpgradeRecommendedTests(TestCaseInTempDir):
270
189
 
271
190
    def test_recommend_upgrade_wt4(self):
272
191
        # using a deprecated format gives a warning
273
 
        self.run_bzr('init --knit a')
274
 
        out, err = self.run_bzr('status a')
 
192
        self.run_bzr('init', '--knit', 'a')
 
193
        out, err = self.run_bzr('status', 'a')
275
194
        self.assertContainsRe(err, 'bzr upgrade .*[/\\\\]a')
276
195
 
277
196
    def test_no_upgrade_recommendation_from_bzrdir(self):
278
197
        # we should only get a recommendation to upgrade when we're accessing
279
198
        # the actual workingtree, not when we only open a bzrdir that contains
280
199
        # an old workngtree
281
 
        self.run_bzr('init --knit a')
282
 
        out, err = self.run_bzr('revno a')
 
200
        self.run_bzr('init', '--knit', 'a')
 
201
        out, err = self.run_bzr('checkout', 'a', 'b')
283
202
        if err.find('upgrade') > -1:
284
203
            self.fail("message shouldn't suggest upgrade:\n%s" % err)
285
 
 
286
 
    def test_upgrade_shared_repo(self):
287
 
        repo = self.make_repository('repo', format='2a', shared=True)
288
 
        branch = self.make_branch_and_tree('repo/branch', format="pack-0.92")
289
 
        self.get_transport('repo/branch/.bzr/repository').delete_tree('.')
290
 
        out, err = self.run_bzr(['upgrade'], working_dir='repo/branch')