/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
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
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
25
from .. 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,
6670.4.1 by Jelmer Vernooij
Update imports.
30
    )
31
from ..bzr import (
32
    branch as bzrbranch,
2255.12.1 by Robert Collins
Implement upgrade for working trees.
33
    workingtree,
34
    workingtree_4,
2230.3.29 by Aaron Bentley
Implement conversion to branch 6
35
    )
2255.12.1 by Robert Collins
Implement upgrade for working trees.
36
37
4360.10.47 by Vincent Ladeuil
Some cleanup.
38
class TestUpgrade(tests.TestCaseWithTransport):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
39
4119.7.1 by Jelmer Vernooij
Make upgrade default to a rich-root-capable format if the source format uses rich roots.
40
    def test_upgrade_rich_root(self):
41
        tree = self.make_branch_and_tree('tree', format='rich-root')
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
42
        tree.commit('first post')
4360.10.48 by Vincent Ladeuil
And some more cleanup.
43
        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.
44
2230.3.29 by Aaron Bentley
Implement conversion to branch 6
45
    def test_convert_branch5_branch6(self):
4360.10.47 by Vincent Ladeuil
Some cleanup.
46
        b = self.make_branch('branch', format='knit')
7045.4.1 by Jelmer Vernooij
Some brz-git fixes.
47
        b._set_revision_history([b'CD'])
4360.10.47 by Vincent Ladeuil
Some cleanup.
48
        b.set_parent('file:///EF')
49
        b.set_bound_location('file:///GH')
50
        b.set_push_location('file:///IJ')
7143.15.2 by Jelmer Vernooij
Run autopep8.
51
        target = controldir.format_registry.make_controldir(
52
            'dirstate-with-subtree')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
53
        converter = b.controldir._format.get_converter(target)
54
        converter.convert(b.controldir, None)
4360.10.47 by Vincent Ladeuil
Some cleanup.
55
        new_branch = branch.Branch.open(self.get_url('branch'))
6653.1.6 by Jelmer Vernooij
Fix some more imports.
56
        self.assertIs(new_branch.__class__, bzrbranch.BzrBranch6)
7045.4.1 by Jelmer Vernooij
Some brz-git fixes.
57
        self.assertEqual(b'CD', new_branch.last_revision())
2230.3.29 by Aaron Bentley
Implement conversion to branch 6
58
        self.assertEqual('file:///EF', new_branch.get_parent())
59
        self.assertEqual('file:///GH', new_branch.get_bound_location())
6421.3.1 by Vincent Ladeuil
Migrate more branch options to config stacks.
60
        branch_config = new_branch.get_config_stack()
61
        self.assertEqual('file:///IJ', branch_config.get('push_location'))
2230.3.29 by Aaron Bentley
Implement conversion to branch 6
62
4360.10.47 by Vincent Ladeuil
Some cleanup.
63
        b2 = self.make_branch('branch2', format='knit')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
64
        converter = b2.controldir._format.get_converter(target)
65
        converter.convert(b2.controldir, None)
4360.10.47 by Vincent Ladeuil
Some cleanup.
66
        b2 = branch.Branch.open(self.get_url('branch'))
6653.1.6 by Jelmer Vernooij
Fix some more imports.
67
        self.assertIs(b2.__class__, bzrbranch.BzrBranch6)
2255.12.1 by Robert Collins
Implement upgrade for working trees.
68
4273.1.13 by Aaron Bentley
Implement upgrade from branch format 7 to 8.
69
    def test_convert_branch7_branch8(self):
4360.10.47 by Vincent Ladeuil
Some cleanup.
70
        b = self.make_branch('branch', format='1.9')
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
71
        target = controldir.format_registry.make_controldir('1.9')
6653.1.6 by Jelmer Vernooij
Fix some more imports.
72
        target.set_branch_format(bzrbranch.BzrBranchFormat8())
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
73
        converter = b.controldir._format.get_converter(target)
74
        converter.convert(b.controldir, None)
4360.10.47 by Vincent Ladeuil
Some cleanup.
75
        b = branch.Branch.open(self.get_url('branch'))
6653.1.6 by Jelmer Vernooij
Fix some more imports.
76
        self.assertIs(b.__class__, bzrbranch.BzrBranch8)
4360.10.47 by Vincent Ladeuil
Some cleanup.
77
        self.assertEqual({}, b._get_all_reference_info())
4273.1.13 by Aaron Bentley
Implement upgrade from branch format 7 to 8.
78
2255.12.1 by Robert Collins
Implement upgrade for working trees.
79
    def test_convert_knit_dirstate_empty(self):
80
        # test that asking for an upgrade from knit to dirstate works.
81
        tree = self.make_branch_and_tree('tree', format='knit')
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
82
        target = controldir.format_registry.make_controldir('dirstate')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
83
        converter = tree.controldir._format.get_converter(target)
84
        converter.convert(tree.controldir, None)
2255.12.1 by Robert Collins
Implement upgrade for working trees.
85
        new_tree = workingtree.WorkingTree.open('tree')
86
        self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4)
6973.14.6 by Jelmer Vernooij
Fix some more tests.
87
        self.assertEqual(b'null:', new_tree.last_revision())
2255.12.1 by Robert Collins
Implement upgrade for working trees.
88
89
    def test_convert_knit_dirstate_content(self):
90
        # smoke test for dirstate conversion: we call dirstate primitives,
91
        # and its there that the core logic is tested.
92
        tree = self.make_branch_and_tree('tree', format='knit')
93
        self.build_tree(['tree/file'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
94
        tree.add(['file'], [b'file-id'])
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
95
        target = controldir.format_registry.make_controldir('dirstate')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
96
        converter = tree.controldir._format.get_converter(target)
97
        converter.convert(tree.controldir, None)
2255.12.1 by Robert Collins
Implement upgrade for working trees.
98
        new_tree = workingtree.WorkingTree.open('tree')
99
        self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4)
6855.4.1 by Jelmer Vernooij
Yet more bees.
100
        self.assertEqual(b'null:', new_tree.last_revision())
2255.12.1 by Robert Collins
Implement upgrade for working trees.
101
102
    def test_convert_knit_one_parent_dirstate(self):
103
        # test that asking for an upgrade from knit to dirstate works.
104
        tree = self.make_branch_and_tree('tree', format='knit')
105
        rev_id = tree.commit('first post')
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
106
        target = controldir.format_registry.make_controldir('dirstate')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
107
        converter = tree.controldir._format.get_converter(target)
108
        converter.convert(tree.controldir, None)
2255.12.1 by Robert Collins
Implement upgrade for working trees.
109
        new_tree = workingtree.WorkingTree.open('tree')
110
        self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4)
111
        self.assertEqual(rev_id, new_tree.last_revision())
112
        for path in ['basis-inventory-cache', 'inventory', 'last-revision',
7143.15.2 by Jelmer Vernooij
Run autopep8.
113
                     'pending-merges', 'stat-cache']:
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
114
            self.assertPathDoesNotExist('tree/.bzr/checkout/' + path)
2255.12.1 by Robert Collins
Implement upgrade for working trees.
115
116
    def test_convert_knit_merges_dirstate(self):
117
        tree = self.make_branch_and_tree('tree', format='knit')
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
118
        tree.commit('first post')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
119
        merge_tree = tree.controldir.sprout('tree2').open_workingtree()
2255.12.1 by Robert Collins
Implement upgrade for working trees.
120
        rev_id2 = tree.commit('second post')
121
        rev_id3 = merge_tree.commit('second merge post')
122
        tree.merge_from_branch(merge_tree.branch)
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
123
        target = controldir.format_registry.make_controldir('dirstate')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
124
        converter = tree.controldir._format.get_converter(target)
125
        converter.convert(tree.controldir, None)
2255.12.1 by Robert Collins
Implement upgrade for working trees.
126
        new_tree = workingtree.WorkingTree.open('tree')
127
        self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4)
128
        self.assertEqual(rev_id2, new_tree.last_revision())
129
        self.assertEqual([rev_id2, rev_id3], new_tree.get_parent_ids())
130
        for path in ['basis-inventory-cache', 'inventory', 'last-revision',
7143.15.2 by Jelmer Vernooij
Run autopep8.
131
                     'pending-merges', 'stat-cache']:
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
132
            self.assertPathDoesNotExist('tree/.bzr/checkout/' + path)
2230.3.29 by Aaron Bentley
Implement conversion to branch 6
133
1393.1.31 by Martin Pool
- add simple test for upgrade
134
4360.10.47 by Vincent Ladeuil
Some cleanup.
135
class TestSmartUpgrade(tests.TestCaseWithTransport):
4360.10.1 by Ian Clatworthy
initial cut at smarter upgrades
136
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
137
    from_format = controldir.format_registry.make_controldir("pack-0.92")
138
    to_format = controldir.format_registry.make_controldir("2a")
4360.10.1 by Ian Clatworthy
initial cut at smarter upgrades
139
140
    def make_standalone_branch(self):
141
        wt = self.make_branch_and_tree("branch1", format=self.from_format)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
142
        return wt.controldir
4360.10.1 by Ian Clatworthy
initial cut at smarter upgrades
143
144
    def test_upgrade_standalone_branch(self):
145
        control = self.make_standalone_branch()
4360.10.48 by Vincent Ladeuil
And some more cleanup.
146
        tried, worked, issues = upgrade.smart_upgrade(
147
            [control], format=self.to_format)
4360.10.39 by Vincent Ladeuil
Use assertLength as it provides a better ouput to debug tests.
148
        self.assertLength(1, tried)
4360.10.33 by Matthew Fuller
The smart upgrade recurses and returns lists of what it tried and
149
        self.assertEqual(tried[0], control)
4360.10.39 by Vincent Ladeuil
Use assertLength as it provides a better ouput to debug tests.
150
        self.assertLength(1, worked)
4360.10.33 by Matthew Fuller
The smart upgrade recurses and returns lists of what it tried and
151
        self.assertEqual(worked[0], control)
4360.10.39 by Vincent Ladeuil
Use assertLength as it provides a better ouput to debug tests.
152
        self.assertLength(0, issues)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
153
        self.assertPathExists('branch1/backup.bzr.~1~')
4360.10.32 by Matthew Fuller
Add some additional assertions into the TestSmartUpgrade tests to
154
        self.assertEqual(control.open_repository()._format,
155
                         self.to_format._repository_format)
4360.10.1 by Ian Clatworthy
initial cut at smarter upgrades
156
157
    def test_upgrade_standalone_branch_cleanup(self):
158
        control = self.make_standalone_branch()
4360.10.48 by Vincent Ladeuil
And some more cleanup.
159
        tried, worked, issues = upgrade.smart_upgrade(
160
            [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.
161
        self.assertLength(1, tried)
4360.10.33 by Matthew Fuller
The smart upgrade recurses and returns lists of what it tried and
162
        self.assertEqual(tried[0], control)
4360.10.39 by Vincent Ladeuil
Use assertLength as it provides a better ouput to debug tests.
163
        self.assertLength(1, worked)
4360.10.33 by Matthew Fuller
The smart upgrade recurses and returns lists of what it tried and
164
        self.assertEqual(worked[0], control)
4360.10.39 by Vincent Ladeuil
Use assertLength as it provides a better ouput to debug tests.
165
        self.assertLength(0, issues)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
166
        self.assertPathExists('branch1')
167
        self.assertPathExists('branch1/.bzr')
168
        self.assertPathDoesNotExist('branch1/backup.bzr.~1~')
4360.10.32 by Matthew Fuller
Add some additional assertions into the TestSmartUpgrade tests to
169
        self.assertEqual(control.open_repository()._format,
170
                         self.to_format._repository_format)
4360.10.1 by Ian Clatworthy
initial cut at smarter upgrades
171
4360.10.2 by Ian Clatworthy
drop stacked vs unstacked logic; support multiple URLs
172
    def make_repo_with_branches(self):
4360.10.1 by Ian Clatworthy
initial cut at smarter upgrades
173
        repo = self.make_repository('repo', shared=True,
7143.15.2 by Jelmer Vernooij
Run autopep8.
174
                                    format=self.from_format)
4360.10.20 by Ian Clatworthy
fix tests to truly use a shared repository, not standalone branches inside one
175
        # Note: self.make_branch() always creates a new repo at the location
176
        # so we need to avoid using that here ...
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
177
        controldir.ControlDir.create_branch_convenience(
178
            "repo/branch1", format=self.from_format)
179
        b2 = controldir.ControlDir.create_branch_convenience(
180
            "repo/branch2", format=self.from_format)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
181
        return repo.controldir
4360.10.1 by Ian Clatworthy
initial cut at smarter upgrades
182
183
    def test_upgrade_repo_with_branches(self):
184
        control = self.make_repo_with_branches()
4360.10.48 by Vincent Ladeuil
And some more cleanup.
185
        tried, worked, issues = upgrade.smart_upgrade(
186
            [control], format=self.to_format)
4360.10.39 by Vincent Ladeuil
Use assertLength as it provides a better ouput to debug tests.
187
        self.assertLength(3, tried)
4360.10.33 by Matthew Fuller
The smart upgrade recurses and returns lists of what it tried and
188
        self.assertEqual(tried[0], control)
4360.10.39 by Vincent Ladeuil
Use assertLength as it provides a better ouput to debug tests.
189
        self.assertLength(3, worked)
4360.10.33 by Matthew Fuller
The smart upgrade recurses and returns lists of what it tried and
190
        self.assertEqual(worked[0], control)
4360.10.39 by Vincent Ladeuil
Use assertLength as it provides a better ouput to debug tests.
191
        self.assertLength(0, issues)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
192
        self.assertPathExists('repo/backup.bzr.~1~')
193
        self.assertPathExists('repo/branch1/backup.bzr.~1~')
194
        self.assertPathExists('repo/branch2/backup.bzr.~1~')
4360.10.32 by Matthew Fuller
Add some additional assertions into the TestSmartUpgrade tests to
195
        self.assertEqual(control.open_repository()._format,
196
                         self.to_format._repository_format)
4360.10.47 by Vincent Ladeuil
Some cleanup.
197
        b1 = branch.Branch.open('repo/branch1')
4360.10.32 by Matthew Fuller
Add some additional assertions into the TestSmartUpgrade tests to
198
        self.assertEqual(b1._format, self.to_format._branch_format)
4360.10.1 by Ian Clatworthy
initial cut at smarter upgrades
199
4360.10.2 by Ian Clatworthy
drop stacked vs unstacked logic; support multiple URLs
200
    def test_upgrade_repo_with_branches_cleanup(self):
201
        control = self.make_repo_with_branches()
4360.10.48 by Vincent Ladeuil
And some more cleanup.
202
        tried, worked, issues = upgrade.smart_upgrade(
203
            [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.
204
        self.assertLength(3, tried)
4360.10.33 by Matthew Fuller
The smart upgrade recurses and returns lists of what it tried and
205
        self.assertEqual(tried[0], control)
4360.10.39 by Vincent Ladeuil
Use assertLength as it provides a better ouput to debug tests.
206
        self.assertLength(3, worked)
4360.10.33 by Matthew Fuller
The smart upgrade recurses and returns lists of what it tried and
207
        self.assertEqual(worked[0], control)
4360.10.39 by Vincent Ladeuil
Use assertLength as it provides a better ouput to debug tests.
208
        self.assertLength(0, issues)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
209
        self.assertPathExists('repo')
210
        self.assertPathExists('repo/.bzr')
211
        self.assertPathDoesNotExist('repo/backup.bzr.~1~')
212
        self.assertPathDoesNotExist('repo/branch1/backup.bzr.~1~')
213
        self.assertPathDoesNotExist('repo/branch2/backup.bzr.~1~')
4360.10.32 by Matthew Fuller
Add some additional assertions into the TestSmartUpgrade tests to
214
        self.assertEqual(control.open_repository()._format,
215
                         self.to_format._repository_format)
4360.10.47 by Vincent Ladeuil
Some cleanup.
216
        b1 = branch.Branch.open('repo/branch1')
4360.10.32 by Matthew Fuller
Add some additional assertions into the TestSmartUpgrade tests to
217
        self.assertEqual(b1._format, self.to_format._branch_format)