~bzr-pqm/bzr/bzr.dev

5557.1.7 by John Arbash Meinel
Merge in the bzr.dev 5582
1
# Copyright (C) 2005-2011 Canonical Ltd
1417.1.2 by Robert Collins
add sample test
2
#
1393.1.31 by Martin Pool
- add simple test for upgrade
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.
1417.1.2 by Robert Collins
add sample test
7
#
1393.1.31 by Martin Pool
- add simple test for upgrade
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.
1417.1.2 by Robert Collins
add sample test
12
#
1393.1.31 by Martin Pool
- add simple test for upgrade
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1393.1.31 by Martin Pool
- add simple test for upgrade
16
17
"""Tests for upgrade of old trees.
18
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
19
This file contains canned versions of some old trees, which are instantiated
1393.1.31 by Martin Pool
- add simple test for upgrade
20
and then upgraded to the new format."""
21
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
22
# TODO queue for upgrade:
23
# test the error message when upgrading an unknown BzrDir format.
24
2230.3.29 by Aaron Bentley
Implement conversion to branch 6
25
from bzrlib import (
4360.10.47 by Vincent Ladeuil
Some cleanup.
26
    branch,
6472.2.1 by Jelmer Vernooij
Use bzrdir.controldir for generic access to control directories.
27
    controldir,
4360.10.47 by Vincent Ladeuil
Some cleanup.
28
    tests,
4360.10.48 by Vincent Ladeuil
And some more cleanup.
29
    upgrade,
2255.12.1 by Robert Collins
Implement upgrade for working trees.
30
    workingtree,
31
    workingtree_4,
2230.3.29 by Aaron Bentley
Implement conversion to branch 6
32
    )
2255.12.1 by Robert Collins
Implement upgrade for working trees.
33
34
4360.10.47 by Vincent Ladeuil
Some cleanup.
35
class TestUpgrade(tests.TestCaseWithTransport):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
36
4119.7.1 by Jelmer Vernooij
Make upgrade default to a rich-root-capable format if the source format uses rich roots.
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')
4360.10.48 by Vincent Ladeuil
And some more cleanup.
40
        upgrade.upgrade('tree')
4119.7.1 by Jelmer Vernooij
Make upgrade default to a rich-root-capable format if the source format uses rich roots.
41
2230.3.29 by Aaron Bentley
Implement conversion to branch 6
42
    def test_convert_branch5_branch6(self):
4360.10.47 by Vincent Ladeuil
Some cleanup.
43
        b = self.make_branch('branch', format='knit')
5718.7.11 by Jelmer Vernooij
Fix set_revision_history.
44
        b._set_revision_history(['CD'])
4360.10.47 by Vincent Ladeuil
Some cleanup.
45
        b.set_parent('file:///EF')
46
        b.set_bound_location('file:///GH')
47
        b.set_push_location('file:///IJ')
6472.2.1 by Jelmer Vernooij
Use bzrdir.controldir for generic access to control directories.
48
        target = controldir.format_registry.make_bzrdir('dirstate-with-subtree')
4360.10.47 by Vincent Ladeuil
Some cleanup.
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)
2230.3.29 by Aaron Bentley
Implement conversion to branch 6
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())
6421.3.1 by Vincent Ladeuil
Migrate more branch options to config stacks.
56
        branch_config = new_branch.get_config_stack()
57
        self.assertEqual('file:///IJ', branch_config.get('push_location'))
2230.3.29 by Aaron Bentley
Implement conversion to branch 6
58
4360.10.47 by Vincent Ladeuil
Some cleanup.
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)
2255.12.1 by Robert Collins
Implement upgrade for working trees.
64
4273.1.13 by Aaron Bentley
Implement upgrade from branch format 7 to 8.
65
    def test_convert_branch7_branch8(self):
4360.10.47 by Vincent Ladeuil
Some cleanup.
66
        b = self.make_branch('branch', format='1.9')
6472.2.1 by Jelmer Vernooij
Use bzrdir.controldir for generic access to control directories.
67
        target = controldir.format_registry.make_bzrdir('1.9')
4360.10.47 by Vincent Ladeuil
Some cleanup.
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())
4273.1.13 by Aaron Bentley
Implement upgrade from branch format 7 to 8.
74
2255.12.1 by Robert Collins
Implement upgrade for working trees.
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')
6472.2.1 by Jelmer Vernooij
Use bzrdir.controldir for generic access to control directories.
78
        target = controldir.format_registry.make_bzrdir('dirstate')
2255.12.1 by Robert Collins
Implement upgrade for working trees.
79
        converter = tree.bzrdir._format.get_converter(target)
4961.2.9 by Martin Pool
Rip out most remaining uses of DummyProgressBar
80
        converter.convert(tree.bzrdir, None)
2255.12.1 by Robert Collins
Implement upgrade for working trees.
81
        new_tree = workingtree.WorkingTree.open('tree')
82
        self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4)
2598.5.10 by Aaron Bentley
Return NULL_REVISION instead of None for the null revision
83
        self.assertEqual('null:', new_tree.last_revision())
2255.12.1 by Robert Collins
Implement upgrade for working trees.
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'])
6472.2.1 by Jelmer Vernooij
Use bzrdir.controldir for generic access to control directories.
91
        target = controldir.format_registry.make_bzrdir('dirstate')
2255.12.1 by Robert Collins
Implement upgrade for working trees.
92
        converter = tree.bzrdir._format.get_converter(target)
4961.2.9 by Martin Pool
Rip out most remaining uses of DummyProgressBar
93
        converter.convert(tree.bzrdir, None)
2255.12.1 by Robert Collins
Implement upgrade for working trees.
94
        new_tree = workingtree.WorkingTree.open('tree')
95
        self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4)
2598.5.10 by Aaron Bentley
Return NULL_REVISION instead of None for the null revision
96
        self.assertEqual('null:', new_tree.last_revision())
2255.12.1 by Robert Collins
Implement upgrade for working trees.
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')
6472.2.1 by Jelmer Vernooij
Use bzrdir.controldir for generic access to control directories.
102
        target = controldir.format_registry.make_bzrdir('dirstate')
2255.12.1 by Robert Collins
Implement upgrade for working trees.
103
        converter = tree.bzrdir._format.get_converter(target)
4961.2.9 by Martin Pool
Rip out most remaining uses of DummyProgressBar
104
        converter.convert(tree.bzrdir, None)
2255.12.1 by Robert Collins
Implement upgrade for working trees.
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']:
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
110
            self.assertPathDoesNotExist('tree/.bzr/checkout/' + path)
2255.12.1 by Robert Collins
Implement upgrade for working trees.
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)
6472.2.1 by Jelmer Vernooij
Use bzrdir.controldir for generic access to control directories.
119
        target = controldir.format_registry.make_bzrdir('dirstate')
2255.12.1 by Robert Collins
Implement upgrade for working trees.
120
        converter = tree.bzrdir._format.get_converter(target)
4961.2.9 by Martin Pool
Rip out most remaining uses of DummyProgressBar
121
        converter.convert(tree.bzrdir, None)
2255.12.1 by Robert Collins
Implement upgrade for working trees.
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']:
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
128
            self.assertPathDoesNotExist('tree/.bzr/checkout/' + path)
2230.3.29 by Aaron Bentley
Implement conversion to branch 6
129
1393.1.31 by Martin Pool
- add simple test for upgrade
130
4360.10.47 by Vincent Ladeuil
Some cleanup.
131
class TestSmartUpgrade(tests.TestCaseWithTransport):
4360.10.1 by Ian Clatworthy
initial cut at smarter upgrades
132
6472.2.1 by Jelmer Vernooij
Use bzrdir.controldir for generic access to control directories.
133
    from_format = controldir.format_registry.make_bzrdir("pack-0.92")
134
    to_format = controldir.format_registry.make_bzrdir("2a")
4360.10.1 by Ian Clatworthy
initial cut at smarter upgrades
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()
4360.10.48 by Vincent Ladeuil
And some more cleanup.
142
        tried, worked, issues = upgrade.smart_upgrade(
143
            [control], format=self.to_format)
4360.10.39 by Vincent Ladeuil
Use assertLength as it provides a better ouput to debug tests.
144
        self.assertLength(1, tried)
4360.10.33 by Matthew Fuller
The smart upgrade recurses and returns lists of what it tried and
145
        self.assertEqual(tried[0], control)
4360.10.39 by Vincent Ladeuil
Use assertLength as it provides a better ouput to debug tests.
146
        self.assertLength(1, worked)
4360.10.33 by Matthew Fuller
The smart upgrade recurses and returns lists of what it tried and
147
        self.assertEqual(worked[0], control)
4360.10.39 by Vincent Ladeuil
Use assertLength as it provides a better ouput to debug tests.
148
        self.assertLength(0, issues)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
149
        self.assertPathExists('branch1/backup.bzr.~1~')
4360.10.32 by Matthew Fuller
Add some additional assertions into the TestSmartUpgrade tests to
150
        self.assertEqual(control.open_repository()._format,
151
                         self.to_format._repository_format)
4360.10.1 by Ian Clatworthy
initial cut at smarter upgrades
152
153
    def test_upgrade_standalone_branch_cleanup(self):
154
        control = self.make_standalone_branch()
4360.10.48 by Vincent Ladeuil
And some more cleanup.
155
        tried, worked, issues = upgrade.smart_upgrade(
156
            [control], format=self.to_format, clean_up=True)
4360.10.39 by Vincent Ladeuil
Use assertLength as it provides a better ouput to debug tests.
157
        self.assertLength(1, tried)
4360.10.33 by Matthew Fuller
The smart upgrade recurses and returns lists of what it tried and
158
        self.assertEqual(tried[0], control)
4360.10.39 by Vincent Ladeuil
Use assertLength as it provides a better ouput to debug tests.
159
        self.assertLength(1, worked)
4360.10.33 by Matthew Fuller
The smart upgrade recurses and returns lists of what it tried and
160
        self.assertEqual(worked[0], control)
4360.10.39 by Vincent Ladeuil
Use assertLength as it provides a better ouput to debug tests.
161
        self.assertLength(0, issues)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
162
        self.assertPathExists('branch1')
163
        self.assertPathExists('branch1/.bzr')
164
        self.assertPathDoesNotExist('branch1/backup.bzr.~1~')
4360.10.32 by Matthew Fuller
Add some additional assertions into the TestSmartUpgrade tests to
165
        self.assertEqual(control.open_repository()._format,
166
                         self.to_format._repository_format)
4360.10.1 by Ian Clatworthy
initial cut at smarter upgrades
167
4360.10.2 by Ian Clatworthy
drop stacked vs unstacked logic; support multiple URLs
168
    def make_repo_with_branches(self):
4360.10.1 by Ian Clatworthy
initial cut at smarter upgrades
169
        repo = self.make_repository('repo', shared=True,
170
            format=self.from_format)
4360.10.20 by Ian Clatworthy
fix tests to truly use a shared repository, not standalone branches inside one
171
        # Note: self.make_branch() always creates a new repo at the location
172
        # so we need to avoid using that here ...
6472.2.1 by Jelmer Vernooij
Use bzrdir.controldir for generic access to control directories.
173
        b1 = controldir.ControlDir.create_branch_convenience("repo/branch1",
4360.10.20 by Ian Clatworthy
fix tests to truly use a shared repository, not standalone branches inside one
174
            format=self.from_format)
6472.2.1 by Jelmer Vernooij
Use bzrdir.controldir for generic access to control directories.
175
        b2 = controldir.ControlDir.create_branch_convenience("repo/branch2",
4360.10.20 by Ian Clatworthy
fix tests to truly use a shared repository, not standalone branches inside one
176
            format=self.from_format)
4360.10.1 by Ian Clatworthy
initial cut at smarter upgrades
177
        return repo.bzrdir
178
179
    def test_upgrade_repo_with_branches(self):
180
        control = self.make_repo_with_branches()
4360.10.48 by Vincent Ladeuil
And some more cleanup.
181
        tried, worked, issues = upgrade.smart_upgrade(
182
            [control], format=self.to_format)
4360.10.39 by Vincent Ladeuil
Use assertLength as it provides a better ouput to debug tests.
183
        self.assertLength(3, tried)
4360.10.33 by Matthew Fuller
The smart upgrade recurses and returns lists of what it tried and
184
        self.assertEqual(tried[0], control)
4360.10.39 by Vincent Ladeuil
Use assertLength as it provides a better ouput to debug tests.
185
        self.assertLength(3, worked)
4360.10.33 by Matthew Fuller
The smart upgrade recurses and returns lists of what it tried and
186
        self.assertEqual(worked[0], control)
4360.10.39 by Vincent Ladeuil
Use assertLength as it provides a better ouput to debug tests.
187
        self.assertLength(0, issues)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
188
        self.assertPathExists('repo/backup.bzr.~1~')
189
        self.assertPathExists('repo/branch1/backup.bzr.~1~')
190
        self.assertPathExists('repo/branch2/backup.bzr.~1~')
4360.10.32 by Matthew Fuller
Add some additional assertions into the TestSmartUpgrade tests to
191
        self.assertEqual(control.open_repository()._format,
192
                         self.to_format._repository_format)
4360.10.47 by Vincent Ladeuil
Some cleanup.
193
        b1 = branch.Branch.open('repo/branch1')
4360.10.32 by Matthew Fuller
Add some additional assertions into the TestSmartUpgrade tests to
194
        self.assertEqual(b1._format, self.to_format._branch_format)
4360.10.1 by Ian Clatworthy
initial cut at smarter upgrades
195
4360.10.2 by Ian Clatworthy
drop stacked vs unstacked logic; support multiple URLs
196
    def test_upgrade_repo_with_branches_cleanup(self):
197
        control = self.make_repo_with_branches()
4360.10.48 by Vincent Ladeuil
And some more cleanup.
198
        tried, worked, issues = upgrade.smart_upgrade(
199
            [control], format=self.to_format, clean_up=True)
4360.10.39 by Vincent Ladeuil
Use assertLength as it provides a better ouput to debug tests.
200
        self.assertLength(3, tried)
4360.10.33 by Matthew Fuller
The smart upgrade recurses and returns lists of what it tried and
201
        self.assertEqual(tried[0], control)
4360.10.39 by Vincent Ladeuil
Use assertLength as it provides a better ouput to debug tests.
202
        self.assertLength(3, worked)
4360.10.33 by Matthew Fuller
The smart upgrade recurses and returns lists of what it tried and
203
        self.assertEqual(worked[0], control)
4360.10.39 by Vincent Ladeuil
Use assertLength as it provides a better ouput to debug tests.
204
        self.assertLength(0, issues)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
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~')
4360.10.32 by Matthew Fuller
Add some additional assertions into the TestSmartUpgrade tests to
210
        self.assertEqual(control.open_repository()._format,
211
                         self.to_format._repository_format)
4360.10.47 by Vincent Ladeuil
Some cleanup.
212
        b1 = branch.Branch.open('repo/branch1')
4360.10.32 by Matthew Fuller
Add some additional assertions into the TestSmartUpgrade tests to
213
        self.assertEqual(b1._format, self.to_format._branch_format)