~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_upgrade.py

  • Committer: Martin Pool
  • Date: 2005-05-11 10:14:09 UTC
  • Revision ID: mbp@sourcefrog.net-20050511101409-25634506a9caacfd
- move commit code into its own module
- remove some doctest tests in favour of black-box tests
- specific-file parameters for diff and status now cover all
  files inside a directory

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