/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1534.4.13 by Robert Collins
Give a reasonable warning on attempts to upgrade a readonly url.
1
# Copyright (C) 2006 by Canonical Ltd
2
# Authors: Robert Collins <robert.collins@canonical.com>
3
# -*- coding: utf-8 -*-
4
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.
9
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.
14
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
18
19
"""Black box tests for the upgrade ui."""
20
21
import os
22
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
23
import bzrlib.bzrdir as bzrdir
1556.1.4 by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same.
24
import bzrlib.repository as repository
1534.4.13 by Robert Collins
Give a reasonable warning on attempts to upgrade a readonly url.
25
from bzrlib.tests import TestCaseWithTransport
1570.1.2 by Robert Collins
Import bzrtools' 'fix' command as 'bzr reconcile.'
26
from bzrlib.tests.blackbox import TestUIFactory
1666.1.3 by Robert Collins
Fix and test upgrades from bzrdir 6 over SFTP.
27
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
1534.4.13 by Robert Collins
Give a reasonable warning on attempts to upgrade a readonly url.
28
from bzrlib.transport import get_transport
1534.5.9 by Robert Collins
Advise users running upgrade on a checkout to also run it on the branch.
29
import bzrlib.ui as ui
30
31
1534.5.6 by Robert Collins
split out converter logic into per-format objects.
32
class TestWithUpgradableBranches(TestCaseWithTransport):
1534.4.13 by Robert Collins
Give a reasonable warning on attempts to upgrade a readonly url.
33
34
    def setUp(self):
1534.5.6 by Robert Collins
split out converter logic into per-format objects.
35
        super(TestWithUpgradableBranches, self).setUp()
36
        self.old_format = bzrdir.BzrDirFormat.get_default_format()
1534.5.9 by Robert Collins
Advise users running upgrade on a checkout to also run it on the branch.
37
        self.old_ui_factory = ui.ui_factory
38
        self.addCleanup(self.restoreDefaults)
39
40
        ui.ui_factory = TestUIFactory()
1534.5.6 by Robert Collins
split out converter logic into per-format objects.
41
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
1534.4.13 by Robert Collins
Give a reasonable warning on attempts to upgrade a readonly url.
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())
1534.5.6 by Robert Collins
split out converter logic into per-format objects.
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')
1556.1.4 by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same.
48
        d = bzrdir.BzrDir.create('metadir_weave_branch')
49
        d.create_repository()
50
        d.create_branch()
51
        d.create_workingtree()
1534.5.9 by Robert Collins
Advise users running upgrade on a checkout to also run it on the branch.
52
        self.run_bzr('checkout',
1587.1.14 by Robert Collins
Make bound branch creation happen via 'checkout'
53
                     '--lightweight',
1534.5.9 by Robert Collins
Advise users running upgrade on a checkout to also run it on the branch.
54
                     self.get_url('current_format_branch'),
55
                     'current_format_checkout')
1534.5.6 by Robert Collins
split out converter logic into per-format objects.
56
1534.5.9 by Robert Collins
Advise users running upgrade on a checkout to also run it on the branch.
57
    def restoreDefaults(self):
1534.5.6 by Robert Collins
split out converter logic into per-format objects.
58
        bzrdir.BzrDirFormat.set_default_format(self.old_format)
1534.5.9 by Robert Collins
Advise users running upgrade on a checkout to also run it on the branch.
59
        ui.ui_factory = self.old_ui_factory
1534.4.13 by Robert Collins
Give a reasonable warning on attempts to upgrade a readonly url.
60
61
    def test_readonly_url_error(self):
62
        (out, err) = self.run_bzr_captured(
1534.5.6 by Robert Collins
split out converter logic into per-format objects.
63
            ['upgrade', self.get_readonly_url('format_5_branch')], 3)
1534.4.13 by Robert Collins
Give a reasonable warning on attempts to upgrade a readonly url.
64
        self.assertEqual(out, "")
65
        self.assertEqual(err, "bzr: ERROR: Upgrade URL cannot work with readonly URL's.\n")
1534.5.6 by Robert Collins
split out converter logic into per-format objects.
66
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)
1534.5.7 by Robert Collins
Start factoring out the upgrade policy logic.
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)
1534.5.6 by Robert Collins
split out converter logic into per-format objects.
75
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 
79
        # date
1534.5.9 by Robert Collins
Advise users running upgrade on a checkout to also run it on the branch.
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,
85
                         out)
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)
1534.5.6 by Robert Collins
split out converter logic into per-format objects.
89
90
    def test_upgrade_checkout(self):
91
        # upgrading a checkout should work
92
        pass
93
94
    def test_upgrade_repository_scans_branches(self):
95
        # we should get individual upgrade notes for each branch even the 
96
        # anonymous branch
97
        pass
98
99
    def test_ugrade_branch_in_repo(self):
100
        # upgrading a branch in a repo should warn about not upgrading the repo
101
        pass
1534.5.13 by Robert Collins
Correct buggy test.
102
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
119
finished
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))
1556.1.4 by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same.
125
126
    def test_upgrade_explicit_knit(self):
127
        # users can force an upgrade to knit format from a metadir weave 
128
        # branch
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
140
repository converted
141
finished
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))
1558.7.2 by Aaron Bentley
Upgrade works in repositories
149
150
    def test_upgrade_repo(self):
1558.7.3 by Aaron Bentley
Future-proofed the test_upgrade_repo test
151
        self.run_bzr('init-repository', '--format=metadir', 'repo')
1558.7.2 by Aaron Bentley
Upgrade works in repositories
152
        self.run_bzr('upgrade', '--format=knit', 'repo')
1666.1.3 by Robert Collins
Fix and test upgrades from bzrdir 6 over SFTP.
153
154
155
class SFTPTests(TestCaseWithSFTPServer):
156
    """Tests for upgrade over sftp."""
157
158
    def setUp(self):
159
        super(SFTPTests, self).setUp()
160
        self.old_ui_factory = ui.ui_factory
161
        self.addCleanup(self.restoreDefaults)
162
163
        ui.ui_factory = TestUIFactory()
164
165
    def restoreDefaults(self):
166
        ui.ui_factory = self.old_ui_factory
167
168
    def test_upgrade_url(self):
169
        self.run_bzr('init', '--format=weave')
170
        t = get_transport(self.get_url())
171
        url = t.base
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
180
repository converted
181
finished
182
""" % (url, url, url), out)
183
        self.assertEqual('', err)