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