~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_upgrade.py

  • Committer: Patch Queue Manager
  • Date: 2016-04-21 04:10:52 UTC
  • mfrom: (6616.1.1 fix-en-user-guide)
  • Revision ID: pqm@pqm.ubuntu.com-20160421041052-clcye7ns1qcl2n7w
(richard-wilbur) Ensure build of English use guide always uses English text
 even when user's locale specifies a different language. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005-2011 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
"""Tests for upgrade of old trees.
 
18
 
 
19
This file contains canned versions of some old trees, which are instantiated
 
20
and then upgraded to the new format."""
 
21
 
 
22
# TODO queue for upgrade:
 
23
# test the error message when upgrading an unknown BzrDir format.
 
24
 
 
25
from bzrlib import (
 
26
    branch,
 
27
    controldir,
 
28
    tests,
 
29
    upgrade,
 
30
    workingtree,
 
31
    workingtree_4,
 
32
    )
 
33
 
 
34
 
 
35
class TestUpgrade(tests.TestCaseWithTransport):
 
36
 
 
37
    def test_upgrade_rich_root(self):
 
38
        tree = self.make_branch_and_tree('tree', format='rich-root')
 
39
        rev_id = tree.commit('first post')
 
40
        upgrade.upgrade('tree')
 
41
 
 
42
    def test_convert_branch5_branch6(self):
 
43
        b = self.make_branch('branch', format='knit')
 
44
        b._set_revision_history(['CD'])
 
45
        b.set_parent('file:///EF')
 
46
        b.set_bound_location('file:///GH')
 
47
        b.set_push_location('file:///IJ')
 
48
        target = controldir.format_registry.make_bzrdir('dirstate-with-subtree')
 
49
        converter = b.bzrdir._format.get_converter(target)
 
50
        converter.convert(b.bzrdir, None)
 
51
        new_branch = branch.Branch.open(self.get_url('branch'))
 
52
        self.assertIs(new_branch.__class__, branch.BzrBranch6)
 
53
        self.assertEqual('CD', new_branch.last_revision())
 
54
        self.assertEqual('file:///EF', new_branch.get_parent())
 
55
        self.assertEqual('file:///GH', new_branch.get_bound_location())
 
56
        branch_config = new_branch.get_config_stack()
 
57
        self.assertEqual('file:///IJ', branch_config.get('push_location'))
 
58
 
 
59
        b2 = self.make_branch('branch2', format='knit')
 
60
        converter = b2.bzrdir._format.get_converter(target)
 
61
        converter.convert(b2.bzrdir, None)
 
62
        b2 = branch.Branch.open(self.get_url('branch'))
 
63
        self.assertIs(b2.__class__, branch.BzrBranch6)
 
64
 
 
65
    def test_convert_branch7_branch8(self):
 
66
        b = self.make_branch('branch', format='1.9')
 
67
        target = controldir.format_registry.make_bzrdir('1.9')
 
68
        target.set_branch_format(branch.BzrBranchFormat8())
 
69
        converter = b.bzrdir._format.get_converter(target)
 
70
        converter.convert(b.bzrdir, None)
 
71
        b = branch.Branch.open(self.get_url('branch'))
 
72
        self.assertIs(b.__class__, branch.BzrBranch8)
 
73
        self.assertEqual({}, b._get_all_reference_info())
 
74
 
 
75
    def test_convert_knit_dirstate_empty(self):
 
76
        # test that asking for an upgrade from knit to dirstate works.
 
77
        tree = self.make_branch_and_tree('tree', format='knit')
 
78
        target = controldir.format_registry.make_bzrdir('dirstate')
 
79
        converter = tree.bzrdir._format.get_converter(target)
 
80
        converter.convert(tree.bzrdir, None)
 
81
        new_tree = workingtree.WorkingTree.open('tree')
 
82
        self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4)
 
83
        self.assertEqual('null:', new_tree.last_revision())
 
84
 
 
85
    def test_convert_knit_dirstate_content(self):
 
86
        # smoke test for dirstate conversion: we call dirstate primitives,
 
87
        # and its there that the core logic is tested.
 
88
        tree = self.make_branch_and_tree('tree', format='knit')
 
89
        self.build_tree(['tree/file'])
 
90
        tree.add(['file'], ['file-id'])
 
91
        target = controldir.format_registry.make_bzrdir('dirstate')
 
92
        converter = tree.bzrdir._format.get_converter(target)
 
93
        converter.convert(tree.bzrdir, None)
 
94
        new_tree = workingtree.WorkingTree.open('tree')
 
95
        self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4)
 
96
        self.assertEqual('null:', new_tree.last_revision())
 
97
 
 
98
    def test_convert_knit_one_parent_dirstate(self):
 
99
        # test that asking for an upgrade from knit to dirstate works.
 
100
        tree = self.make_branch_and_tree('tree', format='knit')
 
101
        rev_id = tree.commit('first post')
 
102
        target = controldir.format_registry.make_bzrdir('dirstate')
 
103
        converter = tree.bzrdir._format.get_converter(target)
 
104
        converter.convert(tree.bzrdir, None)
 
105
        new_tree = workingtree.WorkingTree.open('tree')
 
106
        self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4)
 
107
        self.assertEqual(rev_id, new_tree.last_revision())
 
108
        for path in ['basis-inventory-cache', 'inventory', 'last-revision',
 
109
            'pending-merges', 'stat-cache']:
 
110
            self.assertPathDoesNotExist('tree/.bzr/checkout/' + path)
 
111
 
 
112
    def test_convert_knit_merges_dirstate(self):
 
113
        tree = self.make_branch_and_tree('tree', format='knit')
 
114
        rev_id = tree.commit('first post')
 
115
        merge_tree = tree.bzrdir.sprout('tree2').open_workingtree()
 
116
        rev_id2 = tree.commit('second post')
 
117
        rev_id3 = merge_tree.commit('second merge post')
 
118
        tree.merge_from_branch(merge_tree.branch)
 
119
        target = controldir.format_registry.make_bzrdir('dirstate')
 
120
        converter = tree.bzrdir._format.get_converter(target)
 
121
        converter.convert(tree.bzrdir, None)
 
122
        new_tree = workingtree.WorkingTree.open('tree')
 
123
        self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4)
 
124
        self.assertEqual(rev_id2, new_tree.last_revision())
 
125
        self.assertEqual([rev_id2, rev_id3], new_tree.get_parent_ids())
 
126
        for path in ['basis-inventory-cache', 'inventory', 'last-revision',
 
127
            'pending-merges', 'stat-cache']:
 
128
            self.assertPathDoesNotExist('tree/.bzr/checkout/' + path)
 
129
 
 
130
 
 
131
class TestSmartUpgrade(tests.TestCaseWithTransport):
 
132
 
 
133
    from_format = controldir.format_registry.make_bzrdir("pack-0.92")
 
134
    to_format = controldir.format_registry.make_bzrdir("2a")
 
135
 
 
136
    def make_standalone_branch(self):
 
137
        wt = self.make_branch_and_tree("branch1", format=self.from_format)
 
138
        return wt.bzrdir
 
139
 
 
140
    def test_upgrade_standalone_branch(self):
 
141
        control = self.make_standalone_branch()
 
142
        tried, worked, issues = upgrade.smart_upgrade(
 
143
            [control], format=self.to_format)
 
144
        self.assertLength(1, tried)
 
145
        self.assertEqual(tried[0], control)
 
146
        self.assertLength(1, worked)
 
147
        self.assertEqual(worked[0], control)
 
148
        self.assertLength(0, issues)
 
149
        self.assertPathExists('branch1/backup.bzr.~1~')
 
150
        self.assertEqual(control.open_repository()._format,
 
151
                         self.to_format._repository_format)
 
152
 
 
153
    def test_upgrade_standalone_branch_cleanup(self):
 
154
        control = self.make_standalone_branch()
 
155
        tried, worked, issues = upgrade.smart_upgrade(
 
156
            [control], format=self.to_format, clean_up=True)
 
157
        self.assertLength(1, tried)
 
158
        self.assertEqual(tried[0], control)
 
159
        self.assertLength(1, worked)
 
160
        self.assertEqual(worked[0], control)
 
161
        self.assertLength(0, issues)
 
162
        self.assertPathExists('branch1')
 
163
        self.assertPathExists('branch1/.bzr')
 
164
        self.assertPathDoesNotExist('branch1/backup.bzr.~1~')
 
165
        self.assertEqual(control.open_repository()._format,
 
166
                         self.to_format._repository_format)
 
167
 
 
168
    def make_repo_with_branches(self):
 
169
        repo = self.make_repository('repo', shared=True,
 
170
            format=self.from_format)
 
171
        # Note: self.make_branch() always creates a new repo at the location
 
172
        # so we need to avoid using that here ...
 
173
        b1 = controldir.ControlDir.create_branch_convenience("repo/branch1",
 
174
            format=self.from_format)
 
175
        b2 = controldir.ControlDir.create_branch_convenience("repo/branch2",
 
176
            format=self.from_format)
 
177
        return repo.bzrdir
 
178
 
 
179
    def test_upgrade_repo_with_branches(self):
 
180
        control = self.make_repo_with_branches()
 
181
        tried, worked, issues = upgrade.smart_upgrade(
 
182
            [control], format=self.to_format)
 
183
        self.assertLength(3, tried)
 
184
        self.assertEqual(tried[0], control)
 
185
        self.assertLength(3, worked)
 
186
        self.assertEqual(worked[0], control)
 
187
        self.assertLength(0, issues)
 
188
        self.assertPathExists('repo/backup.bzr.~1~')
 
189
        self.assertPathExists('repo/branch1/backup.bzr.~1~')
 
190
        self.assertPathExists('repo/branch2/backup.bzr.~1~')
 
191
        self.assertEqual(control.open_repository()._format,
 
192
                         self.to_format._repository_format)
 
193
        b1 = branch.Branch.open('repo/branch1')
 
194
        self.assertEqual(b1._format, self.to_format._branch_format)
 
195
 
 
196
    def test_upgrade_repo_with_branches_cleanup(self):
 
197
        control = self.make_repo_with_branches()
 
198
        tried, worked, issues = upgrade.smart_upgrade(
 
199
            [control], format=self.to_format, clean_up=True)
 
200
        self.assertLength(3, tried)
 
201
        self.assertEqual(tried[0], control)
 
202
        self.assertLength(3, worked)
 
203
        self.assertEqual(worked[0], control)
 
204
        self.assertLength(0, issues)
 
205
        self.assertPathExists('repo')
 
206
        self.assertPathExists('repo/.bzr')
 
207
        self.assertPathDoesNotExist('repo/backup.bzr.~1~')
 
208
        self.assertPathDoesNotExist('repo/branch1/backup.bzr.~1~')
 
209
        self.assertPathDoesNotExist('repo/branch2/backup.bzr.~1~')
 
210
        self.assertEqual(control.open_repository()._format,
 
211
                         self.to_format._repository_format)
 
212
        b1 = branch.Branch.open('repo/branch1')
 
213
        self.assertEqual(b1._format, self.to_format._branch_format)