22
22
# TODO queue for upgrade:
23
23
# test the error message when upgrading an unknown BzrDir format.
29
25
from bzrlib import (
30
branch as _mod_branch,
38
from bzrlib.branch import Branch
39
from bzrlib.tests import TestCaseWithTransport
40
from bzrlib.transport import get_transport
41
from bzrlib.upgrade import upgrade
44
class TestUpgrade(TestCaseWithTransport):
46
def test_build_tree(self):
47
"""Test tree-building test helper"""
48
self.build_tree_contents(_upgrade1_template)
49
self.failUnlessExists('foo')
50
self.failUnlessExists('.bzr/README')
36
class TestUpgrade(tests.TestCaseWithTransport):
52
38
def test_upgrade_simple(self):
53
39
"""Upgrade simple v0.0.4 format to latest format"""
54
40
eq = self.assertEquals
55
41
self.build_tree_contents(_upgrade1_template)
57
43
control = bzrdir.BzrDir.open('.')
58
44
b = control.open_branch()
59
45
# tsk, peeking under the covers.
46
self.assertIsInstance(
63
bzrdir.BzrDirFormat.get_default_format().__class__))
48
bzrdir.BzrDirFormat.get_default_format().__class__)
64
49
rh = b.revision_history()
66
51
['mbp@sourcefrog.net-20051004035611-176b16534b086b3c',
81
66
# check a backup was made:
82
transport = get_transport(b.base)
83
transport.stat('backup.bzr')
84
transport.stat('backup.bzr/README')
85
transport.stat('backup.bzr/branch-format')
86
transport.stat('backup.bzr/revision-history')
87
transport.stat('backup.bzr/merged-patches')
88
transport.stat('backup.bzr/pending-merged-patches')
89
transport.stat('backup.bzr/pending-merges')
90
transport.stat('backup.bzr/branch-name')
91
transport.stat('backup.bzr/branch-lock')
92
transport.stat('backup.bzr/inventory')
93
transport.stat('backup.bzr/stat-cache')
94
transport.stat('backup.bzr/text-store')
95
transport.stat('backup.bzr/text-store/foo-20051004035611-1591048e9dc7c2d4.gz')
96
transport.stat('backup.bzr/text-store/foo-20051004035756-4081373d897c3453.gz')
97
transport.stat('backup.bzr/inventory-store/')
98
transport.stat('backup.bzr/inventory-store/mbp@sourcefrog.net-20051004035611-176b16534b086b3c.gz')
99
transport.stat('backup.bzr/inventory-store/mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd.gz')
100
transport.stat('backup.bzr/revision-store/')
101
transport.stat('backup.bzr/revision-store/mbp@sourcefrog.net-20051004035611-176b16534b086b3c.gz')
102
transport.stat('backup.bzr/revision-store/mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd.gz')
67
backup_dir = 'backup.bzr.~1~'
68
t = self.get_transport('.')
70
t.stat(backup_dir + '/README')
71
t.stat(backup_dir + '/branch-format')
72
t.stat(backup_dir + '/revision-history')
73
t.stat(backup_dir + '/merged-patches')
74
t.stat(backup_dir + '/pending-merged-patches')
75
t.stat(backup_dir + '/pending-merges')
76
t.stat(backup_dir + '/branch-name')
77
t.stat(backup_dir + '/branch-lock')
78
t.stat(backup_dir + '/inventory')
79
t.stat(backup_dir + '/stat-cache')
80
t.stat(backup_dir + '/text-store')
81
t.stat(backup_dir + '/text-store/foo-20051004035611-1591048e9dc7c2d4.gz')
82
t.stat(backup_dir + '/text-store/foo-20051004035756-4081373d897c3453.gz')
83
t.stat(backup_dir + '/inventory-store/')
84
t.stat(backup_dir + '/inventory-store/mbp@sourcefrog.net-20051004035611-176b16534b086b3c.gz')
85
t.stat(backup_dir + '/inventory-store/mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd.gz')
86
t.stat(backup_dir + '/revision-store/')
87
t.stat(backup_dir + '/revision-store/mbp@sourcefrog.net-20051004035611-176b16534b086b3c.gz')
88
t.stat(backup_dir + '/revision-store/mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd.gz')
104
90
def test_upgrade_with_ghosts(self):
105
91
"""Upgrade v0.0.4 tree containing ghost references.
151
137
# Some format6 branches do not have checkout files. Upgrading
152
138
# such a branch to metadir must not setup a working tree.
153
139
self.build_tree_contents(_upgrade1_template)
154
upgrade('.', bzrdir.BzrDirFormat6())
155
transport = get_transport('.')
156
transport.delete_multi(['.bzr/pending-merges', '.bzr/inventory'])
157
self.assertFalse(transport.has('.bzr/stat-cache'))
140
upgrade.upgrade('.', bzrdir.BzrDirFormat6())
141
t = self.get_transport('.')
142
t.delete_multi(['.bzr/pending-merges', '.bzr/inventory'])
143
self.assertFalse(t.has('.bzr/stat-cache'))
158
144
# XXX: upgrade fails if a backup.bzr is already present
159
145
# -- David Allouche 2006-08-11
160
transport.delete_tree('backup.bzr')
146
t.delete_tree('backup.bzr.~1~')
161
147
# At this point, we have a format6 branch without checkout files.
162
upgrade('.', bzrdir.BzrDirMetaFormat1())
148
upgrade.upgrade('.', bzrdir.BzrDirMetaFormat1())
163
149
# The upgrade should not have set up a working tree.
164
150
control = bzrdir.BzrDir.open('.')
165
151
self.assertFalse(control.has_workingtree())
166
152
# We have covered the scope of this test, we may as well check that
167
153
# upgrade has not eaten our data, even if it's a bit redundant with
169
self.failUnless(isinstance(control._format, bzrdir.BzrDirMetaFormat1))
170
branch = control.open_branch()
171
self.assertEquals(branch.revision_history(),
155
self.assertIsInstance(control._format, bzrdir.BzrDirMetaFormat1)
156
b = control.open_branch()
157
self.assertEquals(b.revision_history(),
172
158
['mbp@sourcefrog.net-20051004035611-176b16534b086b3c',
173
159
'mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd'])
175
161
def test_upgrade_rich_root(self):
176
162
tree = self.make_branch_and_tree('tree', format='rich-root')
177
163
rev_id = tree.commit('first post')
164
upgrade.upgrade('tree')
180
166
def test_convert_branch5_branch6(self):
181
branch = self.make_branch('branch', format='knit')
182
branch.set_revision_history(['AB', 'CD'])
183
branch.set_parent('file:///EF')
184
branch.set_bound_location('file:///GH')
185
branch.set_push_location('file:///IJ')
167
b = self.make_branch('branch', format='knit')
168
b.set_revision_history(['AB', 'CD'])
169
b.set_parent('file:///EF')
170
b.set_bound_location('file:///GH')
171
b.set_push_location('file:///IJ')
186
172
target = bzrdir.format_registry.make_bzrdir('dirstate-with-subtree')
187
converter = branch.bzrdir._format.get_converter(target)
188
converter.convert(branch.bzrdir, progress.DummyProgress())
189
new_branch = _mod_branch.Branch.open(self.get_url('branch'))
190
self.assertIs(new_branch.__class__, _mod_branch.BzrBranch6)
173
converter = b.bzrdir._format.get_converter(target)
174
converter.convert(b.bzrdir, None)
175
new_branch = branch.Branch.open(self.get_url('branch'))
176
self.assertIs(new_branch.__class__, branch.BzrBranch6)
191
177
self.assertEqual('CD', new_branch.last_revision())
192
178
self.assertEqual('file:///EF', new_branch.get_parent())
193
179
self.assertEqual('file:///GH', new_branch.get_bound_location())
195
181
self.assertEqual('file:///IJ',
196
182
branch_config.get_user_option('push_location'))
198
branch2 = self.make_branch('branch2', format='knit')
199
converter = branch2.bzrdir._format.get_converter(target)
200
converter.convert(branch2.bzrdir, progress.DummyProgress())
201
branch2 = _mod_branch.Branch.open(self.get_url('branch'))
202
self.assertIs(branch2.__class__, _mod_branch.BzrBranch6)
184
b2 = self.make_branch('branch2', format='knit')
185
converter = b2.bzrdir._format.get_converter(target)
186
converter.convert(b2.bzrdir, None)
187
b2 = branch.Branch.open(self.get_url('branch'))
188
self.assertIs(b2.__class__, branch.BzrBranch6)
204
190
def test_convert_branch7_branch8(self):
205
branch = self.make_branch('branch', format='1.9')
191
b = self.make_branch('branch', format='1.9')
206
192
target = bzrdir.format_registry.make_bzrdir('1.9')
207
target.set_branch_format(_mod_branch.BzrBranchFormat8())
208
converter = branch.bzrdir._format.get_converter(target)
209
converter.convert(branch.bzrdir, progress.DummyProgress())
210
branch = _mod_branch.Branch.open(self.get_url('branch'))
211
self.assertIs(branch.__class__, _mod_branch.BzrBranch8)
212
self.assertEqual({}, branch._get_all_reference_info())
193
target.set_branch_format(branch.BzrBranchFormat8())
194
converter = b.bzrdir._format.get_converter(target)
195
converter.convert(b.bzrdir, None)
196
b = branch.Branch.open(self.get_url('branch'))
197
self.assertIs(b.__class__, branch.BzrBranch8)
198
self.assertEqual({}, b._get_all_reference_info())
214
200
def test_convert_knit_dirstate_empty(self):
215
201
# test that asking for an upgrade from knit to dirstate works.
216
202
tree = self.make_branch_and_tree('tree', format='knit')
217
203
target = bzrdir.format_registry.make_bzrdir('dirstate')
218
204
converter = tree.bzrdir._format.get_converter(target)
219
converter.convert(tree.bzrdir, progress.DummyProgress())
205
converter.convert(tree.bzrdir, None)
220
206
new_tree = workingtree.WorkingTree.open('tree')
221
207
self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4)
222
208
self.assertEqual('null:', new_tree.last_revision())
240
226
rev_id = tree.commit('first post')
241
227
target = bzrdir.format_registry.make_bzrdir('dirstate')
242
228
converter = tree.bzrdir._format.get_converter(target)
243
converter.convert(tree.bzrdir, progress.DummyProgress())
229
converter.convert(tree.bzrdir, None)
244
230
new_tree = workingtree.WorkingTree.open('tree')
245
231
self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4)
246
232
self.assertEqual(rev_id, new_tree.last_revision())
247
233
for path in ['basis-inventory-cache', 'inventory', 'last-revision',
248
234
'pending-merges', 'stat-cache']:
249
self.failIfExists('tree/.bzr/checkout/' + path)
235
self.assertPathDoesNotExist('tree/.bzr/checkout/' + path)
251
237
def test_convert_knit_merges_dirstate(self):
252
238
tree = self.make_branch_and_tree('tree', format='knit')
257
243
tree.merge_from_branch(merge_tree.branch)
258
244
target = bzrdir.format_registry.make_bzrdir('dirstate')
259
245
converter = tree.bzrdir._format.get_converter(target)
260
converter.convert(tree.bzrdir, progress.DummyProgress())
246
converter.convert(tree.bzrdir, None)
261
247
new_tree = workingtree.WorkingTree.open('tree')
262
248
self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4)
263
249
self.assertEqual(rev_id2, new_tree.last_revision())
264
250
self.assertEqual([rev_id2, rev_id3], new_tree.get_parent_ids())
265
251
for path in ['basis-inventory-cache', 'inventory', 'last-revision',
266
252
'pending-merges', 'stat-cache']:
267
self.failIfExists('tree/.bzr/checkout/' + path)
253
self.assertPathDoesNotExist('tree/.bzr/checkout/' + path)
270
256
_upgrade1_template = \
419
class TestSmartUpgrade(tests.TestCaseWithTransport):
421
from_format = bzrdir.format_registry.make_bzrdir("pack-0.92")
422
to_format = bzrdir.format_registry.make_bzrdir("2a")
424
def make_standalone_branch(self):
425
wt = self.make_branch_and_tree("branch1", format=self.from_format)
428
def test_upgrade_standalone_branch(self):
429
control = self.make_standalone_branch()
430
tried, worked, issues = upgrade.smart_upgrade(
431
[control], format=self.to_format)
432
self.assertLength(1, tried)
433
self.assertEqual(tried[0], control)
434
self.assertLength(1, worked)
435
self.assertEqual(worked[0], control)
436
self.assertLength(0, issues)
437
self.assertPathExists('branch1/backup.bzr.~1~')
438
self.assertEqual(control.open_repository()._format,
439
self.to_format._repository_format)
441
def test_upgrade_standalone_branch_cleanup(self):
442
control = self.make_standalone_branch()
443
tried, worked, issues = upgrade.smart_upgrade(
444
[control], format=self.to_format, clean_up=True)
445
self.assertLength(1, tried)
446
self.assertEqual(tried[0], control)
447
self.assertLength(1, worked)
448
self.assertEqual(worked[0], control)
449
self.assertLength(0, issues)
450
self.assertPathExists('branch1')
451
self.assertPathExists('branch1/.bzr')
452
self.assertPathDoesNotExist('branch1/backup.bzr.~1~')
453
self.assertEqual(control.open_repository()._format,
454
self.to_format._repository_format)
456
def make_repo_with_branches(self):
457
repo = self.make_repository('repo', shared=True,
458
format=self.from_format)
459
# Note: self.make_branch() always creates a new repo at the location
460
# so we need to avoid using that here ...
461
b1 = bzrdir.BzrDir.create_branch_convenience("repo/branch1",
462
format=self.from_format)
463
b2 = bzrdir.BzrDir.create_branch_convenience("repo/branch2",
464
format=self.from_format)
467
def test_upgrade_repo_with_branches(self):
468
control = self.make_repo_with_branches()
469
tried, worked, issues = upgrade.smart_upgrade(
470
[control], format=self.to_format)
471
self.assertLength(3, tried)
472
self.assertEqual(tried[0], control)
473
self.assertLength(3, worked)
474
self.assertEqual(worked[0], control)
475
self.assertLength(0, issues)
476
self.assertPathExists('repo/backup.bzr.~1~')
477
self.assertPathExists('repo/branch1/backup.bzr.~1~')
478
self.assertPathExists('repo/branch2/backup.bzr.~1~')
479
self.assertEqual(control.open_repository()._format,
480
self.to_format._repository_format)
481
b1 = branch.Branch.open('repo/branch1')
482
self.assertEqual(b1._format, self.to_format._branch_format)
484
def test_upgrade_repo_with_branches_cleanup(self):
485
control = self.make_repo_with_branches()
486
tried, worked, issues = upgrade.smart_upgrade(
487
[control], format=self.to_format, clean_up=True)
488
self.assertLength(3, tried)
489
self.assertEqual(tried[0], control)
490
self.assertLength(3, worked)
491
self.assertEqual(worked[0], control)
492
self.assertLength(0, issues)
493
self.assertPathExists('repo')
494
self.assertPathExists('repo/.bzr')
495
self.assertPathDoesNotExist('repo/backup.bzr.~1~')
496
self.assertPathDoesNotExist('repo/branch1/backup.bzr.~1~')
497
self.assertPathDoesNotExist('repo/branch2/backup.bzr.~1~')
498
self.assertEqual(control.open_repository()._format,
499
self.to_format._repository_format)
500
b1 = branch.Branch.open('repo/branch1')
501
self.assertEqual(b1._format, self.to_format._branch_format)