~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Andrew Bennetts
  • Date: 2011-02-25 08:45:27 UTC
  • mto: This revision was merged to the branch mainline in revision 5695.
  • Revision ID: andrew.bennetts@canonical.com-20110225084527-0ucp7p00d00hoqon
Add another test.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
20
20
 
21
21
from bzrlib import (
22
22
    bzrdir,
23
 
    repository,
 
23
    controldir,
 
24
    transport,
24
25
    )
25
26
from bzrlib.tests import (
26
27
    features,
27
 
    TestCaseInTempDir,
28
28
    TestCaseWithTransport,
29
29
    )
30
30
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
31
 
from bzrlib.transport import get_transport
32
31
from bzrlib.repofmt.knitrepo import (
33
32
    RepositoryFormatKnit1,
34
33
    )
38
37
 
39
38
    def setUp(self):
40
39
        super(TestWithUpgradableBranches, self).setUp()
41
 
        self.addCleanup(bzrdir.BzrDirFormat._set_default_format,
42
 
                        bzrdir.BzrDirFormat.get_default_format())
 
40
        self.addCleanup(controldir.ControlDirFormat._set_default_format,
 
41
                        controldir.ControlDirFormat.get_default_format())
43
42
 
44
43
    def make_current_format_branch_and_checkout(self):
45
44
        current_tree = self.make_branch_and_tree('current_format_branch',
49
48
 
50
49
    def make_format_5_branch(self):
51
50
        # setup a format 5 branch we can upgrade from.
52
 
        self.make_branch_and_tree('format_5_branch',
53
 
                                  format=bzrdir.BzrDirFormat5())
 
51
        path = 'format_5_branch'
 
52
        self.make_branch_and_tree(path, format=bzrdir.BzrDirFormat5())
 
53
        return path
54
54
 
55
55
    def make_metadir_weave_branch(self):
56
56
        self.make_branch_and_tree('metadir_weave_branch', format='metaweave')
57
57
 
58
58
    def test_readonly_url_error(self):
59
 
        self.make_format_5_branch()
 
59
        path = self.make_format_5_branch()
60
60
        (out, err) = self.run_bzr(
61
 
            ['upgrade', self.get_readonly_url('format_5_branch')], retcode=3)
62
 
        self.assertEqual(out, "")
63
 
        self.assertEqual(err, "bzr: ERROR: Upgrade URL cannot work with readonly URLs.\n")
 
61
            ['upgrade', self.get_readonly_url(path)], retcode=3)
 
62
        err_msg = 'Upgrade URL cannot work with readonly URLs.'
 
63
        self.assertEqualDiff('conversion error: %s\nbzr: ERROR: %s\n'
 
64
                             % (err_msg, err_msg),
 
65
                             err)
64
66
 
65
67
    def test_upgrade_up_to_date(self):
66
68
        self.make_current_format_branch_and_checkout()
67
69
        # when up to date we should get a message to that effect
68
70
        (out, err) = self.run_bzr('upgrade current_format_branch', retcode=3)
69
 
        self.assertEqual("", out)
70
 
        self.assertEqualDiff("bzr: ERROR: The branch format Meta "
71
 
                             "directory format 1 is already at the most "
72
 
                             "recent format.\n", err)
 
71
        err_msg = ('The branch format %s is already at the most recent format.'
 
72
                   % ('Meta directory format 1'))
 
73
        self.assertEqualDiff('conversion error: %s\nbzr: ERROR: %s\n'
 
74
                             % (err_msg, err_msg),
 
75
                             err)
73
76
 
74
77
    def test_upgrade_up_to_date_checkout_warns_branch_left_alone(self):
75
78
        self.make_current_format_branch_and_checkout()
76
79
        # when upgrading a checkout, the branch location and a suggestion
77
80
        # to upgrade it should be emitted even if the checkout is up to
78
81
        # date
 
82
        burl = self.get_transport('current_format_branch').base
 
83
        curl = self.get_transport('current_format_checkout').base
79
84
        (out, err) = self.run_bzr('upgrade current_format_checkout', retcode=3)
80
 
        self.assertEqual("This is a checkout. The branch (%s) needs to be "
81
 
                         "upgraded separately.\n"
82
 
                         % get_transport(self.get_url('current_format_branch')).base,
83
 
                         out)
84
 
        self.assertEqualDiff("bzr: ERROR: The branch format Meta "
85
 
                             "directory format 1 is already at the most "
86
 
                             "recent format.\n", err)
 
85
        self.assertEqual(
 
86
            'Upgrading branch %s ...\nThis is a checkout.'
 
87
            ' The branch (%s) needs to be upgraded separately.\n'
 
88
            % (curl, burl),
 
89
            out)
 
90
        msg = 'The branch format %s is already at the most recent format.' % (
 
91
            'Meta directory format 1')
 
92
        self.assertEqualDiff('conversion error: %s\nbzr: ERROR: %s\n'
 
93
                             % (msg, msg),
 
94
                             err)
87
95
 
88
96
    def test_upgrade_checkout(self):
89
97
        # upgrading a checkout should work
94
102
        # anonymous branch
95
103
        pass
96
104
 
97
 
    def test_ugrade_branch_in_repo(self):
 
105
    def test_upgrade_branch_in_repo(self):
98
106
        # upgrading a branch in a repo should warn about not upgrading the repo
99
107
        pass
100
108
 
101
109
    def test_upgrade_explicit_metaformat(self):
102
110
        # users can force an upgrade to metadir format.
103
 
        self.make_format_5_branch()
104
 
        url = get_transport(self.get_url('format_5_branch')).base
 
111
        path = self.make_format_5_branch()
 
112
        url = self.get_transport(path).base
105
113
        # check --format takes effect
106
 
        bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
 
114
        controldir.ControlDirFormat._set_default_format(bzrdir.BzrDirFormat5())
107
115
        backup_dir = 'backup.bzr.~1~'
108
116
        (out, err) = self.run_bzr(
109
117
            ['upgrade', '--format=metaweave', url])
110
 
        self.assertEqualDiff("""starting upgrade of %s
 
118
        self.assertEqualDiff("""Upgrading branch %s ...
 
119
starting upgrade of %s
111
120
making backup of %s.bzr
112
121
  to %s%s
113
122
starting upgrade from format 5 to 6
115
124
adding prefixes to revision-store
116
125
starting upgrade from format 6 to metadir
117
126
finished
118
 
""" % (url, url, url, backup_dir), out)
 
127
""" % (url, url, url, url, backup_dir), out)
119
128
        self.assertEqualDiff("", err)
120
129
        self.assertTrue(isinstance(
121
 
            bzrdir.BzrDir.open(self.get_url('format_5_branch'))._format,
 
130
            bzrdir.BzrDir.open(self.get_url(path))._format,
122
131
            bzrdir.BzrDirMetaFormat1))
123
132
 
124
133
    def test_upgrade_explicit_knit(self):
125
134
        # users can force an upgrade to knit format from a metadir weave
126
135
        # branch
127
136
        self.make_metadir_weave_branch()
128
 
        url = get_transport(self.get_url('metadir_weave_branch')).base
 
137
        url = self.get_transport('metadir_weave_branch').base
129
138
        # check --format takes effect
130
 
        bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
 
139
        controldir.ControlDirFormat._set_default_format(bzrdir.BzrDirFormat5())
131
140
        backup_dir = 'backup.bzr.~1~'
132
141
        (out, err) = self.run_bzr(
133
142
            ['upgrade', '--format=knit', url])
134
 
        self.assertEqualDiff("""starting upgrade of %s
 
143
        self.assertEqualDiff("""Upgrading branch %s ...
 
144
starting upgrade of %s
135
145
making backup of %s.bzr
136
146
  to %s%s
137
147
starting repository conversion
138
148
repository converted
139
149
finished
140
 
""" % (url, url, url, backup_dir), out)
 
150
""" % (url, url, url, url, backup_dir),
 
151
                             out)
141
152
        self.assertEqualDiff("", err)
142
153
        converted_dir = bzrdir.BzrDir.open(self.get_url('metadir_weave_branch'))
143
154
        self.assertTrue(isinstance(converted_dir._format,
149
160
        self.run_bzr('init-repository --format=metaweave repo')
150
161
        self.run_bzr('upgrade --format=knit repo')
151
162
 
 
163
    def assertLegalOption(self, option_str):
 
164
        # Confirm that an option is legal. (Lower level tests are
 
165
        # expected to validate the actual functionality.)
 
166
        self.run_bzr('init --format=pack-0.92 branch-foo')
 
167
        self.run_bzr('upgrade --format=2a branch-foo %s' % (option_str,))
 
168
 
 
169
    def assertBranchFormat(self, dir, format):
 
170
        branch = bzrdir.BzrDir.open_tree_or_branch(self.get_url(dir))[1]
 
171
        branch_format = branch._format
 
172
        meta_format = bzrdir.format_registry.make_bzrdir(format)
 
173
        expected_format = meta_format.get_branch_format()
 
174
        self.assertEqual(expected_format, branch_format)
 
175
 
 
176
    def test_upgrade_clean_supported(self):
 
177
        self.assertLegalOption('--clean')
 
178
        self.assertBranchFormat('branch-foo', '2a')
 
179
        backup_bzr_dir = os.path.join("branch-foo", "backup.bzr.~1~")
 
180
        self.assertFalse(os.path.exists(backup_bzr_dir))
 
181
 
 
182
    def test_upgrade_dry_run_supported(self):
 
183
        self.assertLegalOption('--dry-run')
 
184
        self.assertBranchFormat('branch-foo', 'pack-0.92')
 
185
 
152
186
    def test_upgrade_permission_check(self):
153
187
        """'backup.bzr' should retain permissions of .bzr. Bug #262450"""
154
188
        self.requireFeature(features.posix_permissions_feature)
160
194
        new_perms = os.stat(backup_dir).st_mode & 0777
161
195
        self.assertTrue(new_perms == old_perms)
162
196
 
163
 
 
164
197
    def test_upgrade_with_existing_backup_dir(self):
165
 
        self.make_format_5_branch()
166
 
        transport = get_transport(self.get_url('format_5_branch'))
167
 
        url = transport.base
168
 
        bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
 
198
        path = self.make_format_5_branch()
 
199
        t = self.get_transport(path)
 
200
        url = t.base
 
201
        controldir.ControlDirFormat._set_default_format(bzrdir.BzrDirFormat5())
169
202
        backup_dir1 = 'backup.bzr.~1~'
170
203
        backup_dir2 = 'backup.bzr.~2~'
171
204
        # explicitly create backup_dir1. bzr should create the .~2~ directory
172
205
        # as backup
173
 
        transport.mkdir(backup_dir1)
 
206
        t.mkdir(backup_dir1)
174
207
        (out, err) = self.run_bzr(
175
208
            ['upgrade', '--format=metaweave', url])
176
 
        self.assertEqualDiff("""starting upgrade of %s
 
209
        self.assertEqualDiff("""Upgrading branch %s ...
 
210
starting upgrade of %s
177
211
making backup of %s.bzr
178
212
  to %s%s
179
213
starting upgrade from format 5 to 6
181
215
adding prefixes to revision-store
182
216
starting upgrade from format 6 to metadir
183
217
finished
184
 
""" % (url, url, url, backup_dir2), out)
 
218
""" % (url, url, url, url, backup_dir2), out)
185
219
        self.assertEqualDiff("", err)
186
220
        self.assertTrue(isinstance(
187
 
            bzrdir.BzrDir.open(self.get_url('format_5_branch'))._format,
 
221
            bzrdir.BzrDir.open(self.get_url(path))._format,
188
222
            bzrdir.BzrDirMetaFormat1))
189
 
        self.assertTrue(transport.has(backup_dir2))
 
223
        self.assertTrue(t.has(backup_dir2))
 
224
 
190
225
 
191
226
class SFTPTests(TestCaseWithSFTPServer):
192
227
    """Tests for upgrade over sftp."""
193
228
 
194
229
    def test_upgrade_url(self):
195
230
        self.run_bzr('init --format=weave')
196
 
        t = get_transport(self.get_url())
 
231
        t = self.get_transport()
197
232
        url = t.base
198
233
        out, err = self.run_bzr(['upgrade', '--format=knit', url])
199
234
        backup_dir = 'backup.bzr.~1~'
200
 
        self.assertEqualDiff("""starting upgrade of %s
 
235
        self.assertEqualDiff("""Upgrading branch %s ...
 
236
starting upgrade of %s
201
237
making backup of %s.bzr
202
238
  to %s%s
203
239
starting upgrade from format 6 to metadir
204
240
starting repository conversion
205
241
repository converted
206
242
finished
207
 
""" % (url, url, url,backup_dir), out)
 
243
""" % (url, url, url, url,backup_dir), out)
208
244
        self.assertEqual('', err)
209
245
 
210
246