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.
81
67
# check a backup was made:
82
68
backup_dir = 'backup.bzr.~1~'
83
transport = get_transport(b.base)
84
transport.stat(backup_dir)
85
transport.stat(backup_dir + '/README')
86
transport.stat(backup_dir + '/branch-format')
87
transport.stat(backup_dir + '/revision-history')
88
transport.stat(backup_dir + '/merged-patches')
89
transport.stat(backup_dir + '/pending-merged-patches')
90
transport.stat(backup_dir + '/pending-merges')
91
transport.stat(backup_dir + '/branch-name')
92
transport.stat(backup_dir + '/branch-lock')
93
transport.stat(backup_dir + '/inventory')
94
transport.stat(backup_dir + '/stat-cache')
95
transport.stat(backup_dir + '/text-store')
96
transport.stat(backup_dir + '/text-store/foo-20051004035611-1591048e9dc7c2d4.gz')
97
transport.stat(backup_dir + '/text-store/foo-20051004035756-4081373d897c3453.gz')
98
transport.stat(backup_dir + '/inventory-store/')
99
transport.stat(backup_dir + '/inventory-store/mbp@sourcefrog.net-20051004035611-176b16534b086b3c.gz')
100
transport.stat(backup_dir + '/inventory-store/mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd.gz')
101
transport.stat(backup_dir + '/revision-store/')
102
transport.stat(backup_dir + '/revision-store/mbp@sourcefrog.net-20051004035611-176b16534b086b3c.gz')
103
transport.stat(backup_dir + '/revision-store/mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd.gz')
69
t = self.get_transport('.')
71
t.stat(backup_dir + '/README')
72
t.stat(backup_dir + '/branch-format')
73
t.stat(backup_dir + '/revision-history')
74
t.stat(backup_dir + '/merged-patches')
75
t.stat(backup_dir + '/pending-merged-patches')
76
t.stat(backup_dir + '/pending-merges')
77
t.stat(backup_dir + '/branch-name')
78
t.stat(backup_dir + '/branch-lock')
79
t.stat(backup_dir + '/inventory')
80
t.stat(backup_dir + '/stat-cache')
81
t.stat(backup_dir + '/text-store')
82
t.stat(backup_dir + '/text-store/foo-20051004035611-1591048e9dc7c2d4.gz')
83
t.stat(backup_dir + '/text-store/foo-20051004035756-4081373d897c3453.gz')
84
t.stat(backup_dir + '/inventory-store/')
85
t.stat(backup_dir + '/inventory-store/mbp@sourcefrog.net-20051004035611-176b16534b086b3c.gz')
86
t.stat(backup_dir + '/inventory-store/mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd.gz')
87
t.stat(backup_dir + '/revision-store/')
88
t.stat(backup_dir + '/revision-store/mbp@sourcefrog.net-20051004035611-176b16534b086b3c.gz')
89
t.stat(backup_dir + '/revision-store/mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd.gz')
105
91
def test_upgrade_with_ghosts(self):
106
92
"""Upgrade v0.0.4 tree containing ghost references.
152
138
# Some format6 branches do not have checkout files. Upgrading
153
139
# such a branch to metadir must not setup a working tree.
154
140
self.build_tree_contents(_upgrade1_template)
155
upgrade('.', bzrdir.BzrDirFormat6())
156
transport = get_transport('.')
157
transport.delete_multi(['.bzr/pending-merges', '.bzr/inventory'])
158
self.assertFalse(transport.has('.bzr/stat-cache'))
141
upgrade.upgrade('.', bzrdir.BzrDirFormat6())
142
t = self.get_transport('.')
143
t.delete_multi(['.bzr/pending-merges', '.bzr/inventory'])
144
self.assertFalse(t.has('.bzr/stat-cache'))
159
145
# XXX: upgrade fails if a backup.bzr is already present
160
146
# -- David Allouche 2006-08-11
161
transport.delete_tree('backup.bzr.~1~')
147
t.delete_tree('backup.bzr.~1~')
162
148
# At this point, we have a format6 branch without checkout files.
163
upgrade('.', bzrdir.BzrDirMetaFormat1())
149
upgrade.upgrade('.', bzrdir.BzrDirMetaFormat1())
164
150
# The upgrade should not have set up a working tree.
165
151
control = bzrdir.BzrDir.open('.')
166
152
self.assertFalse(control.has_workingtree())
168
154
# upgrade has not eaten our data, even if it's a bit redundant with
170
156
self.failUnless(isinstance(control._format, bzrdir.BzrDirMetaFormat1))
171
branch = control.open_branch()
172
self.assertEquals(branch.revision_history(),
157
b = control.open_branch()
158
self.assertEquals(b.revision_history(),
173
159
['mbp@sourcefrog.net-20051004035611-176b16534b086b3c',
174
160
'mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd'])
176
162
def test_upgrade_rich_root(self):
177
163
tree = self.make_branch_and_tree('tree', format='rich-root')
178
164
rev_id = tree.commit('first post')
165
upgrade.upgrade('tree')
181
167
def test_convert_branch5_branch6(self):
182
branch = self.make_branch('branch', format='knit')
183
branch.set_revision_history(['AB', 'CD'])
184
branch.set_parent('file:///EF')
185
branch.set_bound_location('file:///GH')
186
branch.set_push_location('file:///IJ')
168
b = self.make_branch('branch', format='knit')
169
b.set_revision_history(['AB', 'CD'])
170
b.set_parent('file:///EF')
171
b.set_bound_location('file:///GH')
172
b.set_push_location('file:///IJ')
187
173
target = bzrdir.format_registry.make_bzrdir('dirstate-with-subtree')
188
converter = branch.bzrdir._format.get_converter(target)
189
converter.convert(branch.bzrdir, None)
190
new_branch = _mod_branch.Branch.open(self.get_url('branch'))
191
self.assertIs(new_branch.__class__, _mod_branch.BzrBranch6)
174
converter = b.bzrdir._format.get_converter(target)
175
converter.convert(b.bzrdir, None)
176
new_branch = branch.Branch.open(self.get_url('branch'))
177
self.assertIs(new_branch.__class__, branch.BzrBranch6)
192
178
self.assertEqual('CD', new_branch.last_revision())
193
179
self.assertEqual('file:///EF', new_branch.get_parent())
194
180
self.assertEqual('file:///GH', new_branch.get_bound_location())
196
182
self.assertEqual('file:///IJ',
197
183
branch_config.get_user_option('push_location'))
199
branch2 = self.make_branch('branch2', format='knit')
200
converter = branch2.bzrdir._format.get_converter(target)
201
converter.convert(branch2.bzrdir, None)
202
branch2 = _mod_branch.Branch.open(self.get_url('branch'))
203
self.assertIs(branch2.__class__, _mod_branch.BzrBranch6)
185
b2 = self.make_branch('branch2', format='knit')
186
converter = b2.bzrdir._format.get_converter(target)
187
converter.convert(b2.bzrdir, None)
188
b2 = branch.Branch.open(self.get_url('branch'))
189
self.assertIs(b2.__class__, branch.BzrBranch6)
205
191
def test_convert_branch7_branch8(self):
206
branch = self.make_branch('branch', format='1.9')
192
b = self.make_branch('branch', format='1.9')
207
193
target = bzrdir.format_registry.make_bzrdir('1.9')
208
target.set_branch_format(_mod_branch.BzrBranchFormat8())
209
converter = branch.bzrdir._format.get_converter(target)
210
converter.convert(branch.bzrdir, None)
211
branch = _mod_branch.Branch.open(self.get_url('branch'))
212
self.assertIs(branch.__class__, _mod_branch.BzrBranch8)
213
self.assertEqual({}, branch._get_all_reference_info())
194
target.set_branch_format(branch.BzrBranchFormat8())
195
converter = b.bzrdir._format.get_converter(target)
196
converter.convert(b.bzrdir, None)
197
b = branch.Branch.open(self.get_url('branch'))
198
self.assertIs(b.__class__, branch.BzrBranch8)
199
self.assertEqual({}, b._get_all_reference_info())
215
201
def test_convert_knit_dirstate_empty(self):
216
202
# test that asking for an upgrade from knit to dirstate works.
420
class TestSmartUpgrade(tests.TestCaseWithTransport):
422
from_format = bzrdir.format_registry.make_bzrdir("pack-0.92")
423
to_format = bzrdir.format_registry.make_bzrdir("2a")
425
def make_standalone_branch(self):
426
wt = self.make_branch_and_tree("branch1", format=self.from_format)
429
def test_upgrade_standalone_branch(self):
430
control = self.make_standalone_branch()
431
tried, worked, issues = upgrade.smart_upgrade(
432
[control], format=self.to_format)
433
self.assertLength(1, tried)
434
self.assertEqual(tried[0], control)
435
self.assertLength(1, worked)
436
self.assertEqual(worked[0], control)
437
self.assertLength(0, issues)
438
self.failUnlessExists('branch1/backup.bzr.~1~')
439
self.assertEqual(control.open_repository()._format,
440
self.to_format._repository_format)
442
def test_upgrade_standalone_branch_cleanup(self):
443
control = self.make_standalone_branch()
444
tried, worked, issues = upgrade.smart_upgrade(
445
[control], format=self.to_format, clean_up=True)
446
self.assertLength(1, tried)
447
self.assertEqual(tried[0], control)
448
self.assertLength(1, worked)
449
self.assertEqual(worked[0], control)
450
self.assertLength(0, issues)
451
self.failUnlessExists('branch1')
452
self.failUnlessExists('branch1/.bzr')
453
self.failIfExists('branch1/backup.bzr.~1~')
454
self.assertEqual(control.open_repository()._format,
455
self.to_format._repository_format)
457
def make_repo_with_branches(self):
458
repo = self.make_repository('repo', shared=True,
459
format=self.from_format)
460
# Note: self.make_branch() always creates a new repo at the location
461
# so we need to avoid using that here ...
462
b1 = bzrdir.BzrDir.create_branch_convenience("repo/branch1",
463
format=self.from_format)
464
b2 = bzrdir.BzrDir.create_branch_convenience("repo/branch2",
465
format=self.from_format)
468
def test_upgrade_repo_with_branches(self):
469
control = self.make_repo_with_branches()
470
tried, worked, issues = upgrade.smart_upgrade(
471
[control], format=self.to_format)
472
self.assertLength(3, tried)
473
self.assertEqual(tried[0], control)
474
self.assertLength(3, worked)
475
self.assertEqual(worked[0], control)
476
self.assertLength(0, issues)
477
self.failUnlessExists('repo/backup.bzr.~1~')
478
self.failUnlessExists('repo/branch1/backup.bzr.~1~')
479
self.failUnlessExists('repo/branch2/backup.bzr.~1~')
480
self.assertEqual(control.open_repository()._format,
481
self.to_format._repository_format)
482
b1 = branch.Branch.open('repo/branch1')
483
self.assertEqual(b1._format, self.to_format._branch_format)
485
def test_upgrade_repo_with_branches_cleanup(self):
486
control = self.make_repo_with_branches()
487
tried, worked, issues = upgrade.smart_upgrade(
488
[control], format=self.to_format, clean_up=True)
489
self.assertLength(3, tried)
490
self.assertEqual(tried[0], control)
491
self.assertLength(3, worked)
492
self.assertEqual(worked[0], control)
493
self.assertLength(0, issues)
494
self.failUnlessExists('repo')
495
self.failUnlessExists('repo/.bzr')
496
self.failIfExists('repo/backup.bzr.~1~')
497
self.failIfExists('repo/branch1/backup.bzr.~1~')
498
self.failIfExists('repo/branch2/backup.bzr.~1~')
499
self.assertEqual(control.open_repository()._format,
500
self.to_format._repository_format)
501
b1 = branch.Branch.open('repo/branch1')
502
self.assertEqual(b1._format, self.to_format._branch_format)