/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 breezy/tests/test_upgrade.py

  • Committer: Jelmer Vernooij
  • Date: 2018-05-19 13:16:11 UTC
  • mto: (6968.4.3 git-archive)
  • mto: This revision was merged to the branch mainline in revision 6972.
  • Revision ID: jelmer@jelmer.uk-20180519131611-l9h9ud41j7qg1m03
Move tar/zip to breezy.archive.

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 .. import (
 
26
    branch,
 
27
    controldir,
 
28
    tests,
 
29
    upgrade,
 
30
    )
 
31
from ..bzr import (
 
32
    branch as bzrbranch,
 
33
    workingtree,
 
34
    workingtree_4,
 
35
    )
 
36
 
 
37
 
 
38
class TestUpgrade(tests.TestCaseWithTransport):
 
39
 
 
40
    def test_upgrade_rich_root(self):
 
41
        tree = self.make_branch_and_tree('tree', format='rich-root')
 
42
        rev_id = tree.commit('first post')
 
43
        upgrade.upgrade('tree')
 
44
 
 
45
    def test_convert_branch5_branch6(self):
 
46
        b = self.make_branch('branch', format='knit')
 
47
        b._set_revision_history(['CD'])
 
48
        b.set_parent('file:///EF')
 
49
        b.set_bound_location('file:///GH')
 
50
        b.set_push_location('file:///IJ')
 
51
        target = controldir.format_registry.make_controldir('dirstate-with-subtree')
 
52
        converter = b.controldir._format.get_converter(target)
 
53
        converter.convert(b.controldir, None)
 
54
        new_branch = branch.Branch.open(self.get_url('branch'))
 
55
        self.assertIs(new_branch.__class__, bzrbranch.BzrBranch6)
 
56
        self.assertEqual('CD', new_branch.last_revision())
 
57
        self.assertEqual('file:///EF', new_branch.get_parent())
 
58
        self.assertEqual('file:///GH', new_branch.get_bound_location())
 
59
        branch_config = new_branch.get_config_stack()
 
60
        self.assertEqual('file:///IJ', branch_config.get('push_location'))
 
61
 
 
62
        b2 = self.make_branch('branch2', format='knit')
 
63
        converter = b2.controldir._format.get_converter(target)
 
64
        converter.convert(b2.controldir, None)
 
65
        b2 = branch.Branch.open(self.get_url('branch'))
 
66
        self.assertIs(b2.__class__, bzrbranch.BzrBranch6)
 
67
 
 
68
    def test_convert_branch7_branch8(self):
 
69
        b = self.make_branch('branch', format='1.9')
 
70
        target = controldir.format_registry.make_controldir('1.9')
 
71
        target.set_branch_format(bzrbranch.BzrBranchFormat8())
 
72
        converter = b.controldir._format.get_converter(target)
 
73
        converter.convert(b.controldir, None)
 
74
        b = branch.Branch.open(self.get_url('branch'))
 
75
        self.assertIs(b.__class__, bzrbranch.BzrBranch8)
 
76
        self.assertEqual({}, b._get_all_reference_info())
 
77
 
 
78
    def test_convert_knit_dirstate_empty(self):
 
79
        # test that asking for an upgrade from knit to dirstate works.
 
80
        tree = self.make_branch_and_tree('tree', format='knit')
 
81
        target = controldir.format_registry.make_controldir('dirstate')
 
82
        converter = tree.controldir._format.get_converter(target)
 
83
        converter.convert(tree.controldir, None)
 
84
        new_tree = workingtree.WorkingTree.open('tree')
 
85
        self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4)
 
86
        self.assertEqual('null:', new_tree.last_revision())
 
87
 
 
88
    def test_convert_knit_dirstate_content(self):
 
89
        # smoke test for dirstate conversion: we call dirstate primitives,
 
90
        # and its there that the core logic is tested.
 
91
        tree = self.make_branch_and_tree('tree', format='knit')
 
92
        self.build_tree(['tree/file'])
 
93
        tree.add(['file'], [b'file-id'])
 
94
        target = controldir.format_registry.make_controldir('dirstate')
 
95
        converter = tree.controldir._format.get_converter(target)
 
96
        converter.convert(tree.controldir, None)
 
97
        new_tree = workingtree.WorkingTree.open('tree')
 
98
        self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4)
 
99
        self.assertEqual(b'null:', new_tree.last_revision())
 
100
 
 
101
    def test_convert_knit_one_parent_dirstate(self):
 
102
        # test that asking for an upgrade from knit to dirstate works.
 
103
        tree = self.make_branch_and_tree('tree', format='knit')
 
104
        rev_id = tree.commit('first post')
 
105
        target = controldir.format_registry.make_controldir('dirstate')
 
106
        converter = tree.controldir._format.get_converter(target)
 
107
        converter.convert(tree.controldir, None)
 
108
        new_tree = workingtree.WorkingTree.open('tree')
 
109
        self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4)
 
110
        self.assertEqual(rev_id, new_tree.last_revision())
 
111
        for path in ['basis-inventory-cache', 'inventory', 'last-revision',
 
112
            'pending-merges', 'stat-cache']:
 
113
            self.assertPathDoesNotExist('tree/.bzr/checkout/' + path)
 
114
 
 
115
    def test_convert_knit_merges_dirstate(self):
 
116
        tree = self.make_branch_and_tree('tree', format='knit')
 
117
        rev_id = tree.commit('first post')
 
118
        merge_tree = tree.controldir.sprout('tree2').open_workingtree()
 
119
        rev_id2 = tree.commit('second post')
 
120
        rev_id3 = merge_tree.commit('second merge post')
 
121
        tree.merge_from_branch(merge_tree.branch)
 
122
        target = controldir.format_registry.make_controldir('dirstate')
 
123
        converter = tree.controldir._format.get_converter(target)
 
124
        converter.convert(tree.controldir, None)
 
125
        new_tree = workingtree.WorkingTree.open('tree')
 
126
        self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4)
 
127
        self.assertEqual(rev_id2, new_tree.last_revision())
 
128
        self.assertEqual([rev_id2, rev_id3], new_tree.get_parent_ids())
 
129
        for path in ['basis-inventory-cache', 'inventory', 'last-revision',
 
130
            'pending-merges', 'stat-cache']:
 
131
            self.assertPathDoesNotExist('tree/.bzr/checkout/' + path)
 
132
 
 
133
 
 
134
class TestSmartUpgrade(tests.TestCaseWithTransport):
 
135
 
 
136
    from_format = controldir.format_registry.make_controldir("pack-0.92")
 
137
    to_format = controldir.format_registry.make_controldir("2a")
 
138
 
 
139
    def make_standalone_branch(self):
 
140
        wt = self.make_branch_and_tree("branch1", format=self.from_format)
 
141
        return wt.controldir
 
142
 
 
143
    def test_upgrade_standalone_branch(self):
 
144
        control = self.make_standalone_branch()
 
145
        tried, worked, issues = upgrade.smart_upgrade(
 
146
            [control], format=self.to_format)
 
147
        self.assertLength(1, tried)
 
148
        self.assertEqual(tried[0], control)
 
149
        self.assertLength(1, worked)
 
150
        self.assertEqual(worked[0], control)
 
151
        self.assertLength(0, issues)
 
152
        self.assertPathExists('branch1/backup.bzr.~1~')
 
153
        self.assertEqual(control.open_repository()._format,
 
154
                         self.to_format._repository_format)
 
155
 
 
156
    def test_upgrade_standalone_branch_cleanup(self):
 
157
        control = self.make_standalone_branch()
 
158
        tried, worked, issues = upgrade.smart_upgrade(
 
159
            [control], format=self.to_format, clean_up=True)
 
160
        self.assertLength(1, tried)
 
161
        self.assertEqual(tried[0], control)
 
162
        self.assertLength(1, worked)
 
163
        self.assertEqual(worked[0], control)
 
164
        self.assertLength(0, issues)
 
165
        self.assertPathExists('branch1')
 
166
        self.assertPathExists('branch1/.bzr')
 
167
        self.assertPathDoesNotExist('branch1/backup.bzr.~1~')
 
168
        self.assertEqual(control.open_repository()._format,
 
169
                         self.to_format._repository_format)
 
170
 
 
171
    def make_repo_with_branches(self):
 
172
        repo = self.make_repository('repo', shared=True,
 
173
            format=self.from_format)
 
174
        # Note: self.make_branch() always creates a new repo at the location
 
175
        # so we need to avoid using that here ...
 
176
        b1 = controldir.ControlDir.create_branch_convenience("repo/branch1",
 
177
            format=self.from_format)
 
178
        b2 = controldir.ControlDir.create_branch_convenience("repo/branch2",
 
179
            format=self.from_format)
 
180
        return repo.controldir
 
181
 
 
182
    def test_upgrade_repo_with_branches(self):
 
183
        control = self.make_repo_with_branches()
 
184
        tried, worked, issues = upgrade.smart_upgrade(
 
185
            [control], format=self.to_format)
 
186
        self.assertLength(3, tried)
 
187
        self.assertEqual(tried[0], control)
 
188
        self.assertLength(3, worked)
 
189
        self.assertEqual(worked[0], control)
 
190
        self.assertLength(0, issues)
 
191
        self.assertPathExists('repo/backup.bzr.~1~')
 
192
        self.assertPathExists('repo/branch1/backup.bzr.~1~')
 
193
        self.assertPathExists('repo/branch2/backup.bzr.~1~')
 
194
        self.assertEqual(control.open_repository()._format,
 
195
                         self.to_format._repository_format)
 
196
        b1 = branch.Branch.open('repo/branch1')
 
197
        self.assertEqual(b1._format, self.to_format._branch_format)
 
198
 
 
199
    def test_upgrade_repo_with_branches_cleanup(self):
 
200
        control = self.make_repo_with_branches()
 
201
        tried, worked, issues = upgrade.smart_upgrade(
 
202
            [control], format=self.to_format, clean_up=True)
 
203
        self.assertLength(3, tried)
 
204
        self.assertEqual(tried[0], control)
 
205
        self.assertLength(3, worked)
 
206
        self.assertEqual(worked[0], control)
 
207
        self.assertLength(0, issues)
 
208
        self.assertPathExists('repo')
 
209
        self.assertPathExists('repo/.bzr')
 
210
        self.assertPathDoesNotExist('repo/backup.bzr.~1~')
 
211
        self.assertPathDoesNotExist('repo/branch1/backup.bzr.~1~')
 
212
        self.assertPathDoesNotExist('repo/branch2/backup.bzr.~1~')
 
213
        self.assertEqual(control.open_repository()._format,
 
214
                         self.to_format._repository_format)
 
215
        b1 = branch.Branch.open('repo/branch1')
 
216
        self.assertEqual(b1._format, self.to_format._branch_format)