146
138
# Some format6 branches do not have checkout files. Upgrading
147
139
# such a branch to metadir must not setup a working tree.
148
140
self.build_tree_contents(_upgrade1_template)
149
upgrade('.', bzrdir.BzrDirFormat6())
150
t = transport.get_transport('.')
141
upgrade.upgrade('.', bzrdir.BzrDirFormat6())
142
t = self.get_transport('.')
151
143
t.delete_multi(['.bzr/pending-merges', '.bzr/inventory'])
152
144
self.assertFalse(t.has('.bzr/stat-cache'))
153
145
# XXX: upgrade fails if a backup.bzr is already present
154
146
# -- David Allouche 2006-08-11
155
147
t.delete_tree('backup.bzr.~1~')
156
148
# At this point, we have a format6 branch without checkout files.
157
upgrade('.', bzrdir.BzrDirMetaFormat1())
149
upgrade.upgrade('.', bzrdir.BzrDirMetaFormat1())
158
150
# The upgrade should not have set up a working tree.
159
151
control = bzrdir.BzrDir.open('.')
160
152
self.assertFalse(control.has_workingtree())
162
154
# upgrade has not eaten our data, even if it's a bit redundant with
164
156
self.failUnless(isinstance(control._format, bzrdir.BzrDirMetaFormat1))
165
branch = control.open_branch()
166
self.assertEquals(branch.revision_history(),
157
b = control.open_branch()
158
self.assertEquals(b.revision_history(),
167
159
['mbp@sourcefrog.net-20051004035611-176b16534b086b3c',
168
160
'mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd'])
170
162
def test_upgrade_rich_root(self):
171
163
tree = self.make_branch_and_tree('tree', format='rich-root')
172
164
rev_id = tree.commit('first post')
165
upgrade.upgrade('tree')
175
167
def test_convert_branch5_branch6(self):
176
branch = self.make_branch('branch', format='knit')
177
branch.set_revision_history(['AB', 'CD'])
178
branch.set_parent('file:///EF')
179
branch.set_bound_location('file:///GH')
180
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')
181
173
target = bzrdir.format_registry.make_bzrdir('dirstate-with-subtree')
182
converter = branch.bzrdir._format.get_converter(target)
183
converter.convert(branch.bzrdir, None)
184
new_branch = _mod_branch.Branch.open(self.get_url('branch'))
185
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)
186
178
self.assertEqual('CD', new_branch.last_revision())
187
179
self.assertEqual('file:///EF', new_branch.get_parent())
188
180
self.assertEqual('file:///GH', new_branch.get_bound_location())
190
182
self.assertEqual('file:///IJ',
191
183
branch_config.get_user_option('push_location'))
193
branch2 = self.make_branch('branch2', format='knit')
194
converter = branch2.bzrdir._format.get_converter(target)
195
converter.convert(branch2.bzrdir, None)
196
branch2 = _mod_branch.Branch.open(self.get_url('branch'))
197
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)
199
191
def test_convert_branch7_branch8(self):
200
branch = self.make_branch('branch', format='1.9')
192
b = self.make_branch('branch', format='1.9')
201
193
target = bzrdir.format_registry.make_bzrdir('1.9')
202
target.set_branch_format(_mod_branch.BzrBranchFormat8())
203
converter = branch.bzrdir._format.get_converter(target)
204
converter.convert(branch.bzrdir, None)
205
branch = _mod_branch.Branch.open(self.get_url('branch'))
206
self.assertIs(branch.__class__, _mod_branch.BzrBranch8)
207
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())
209
201
def test_convert_knit_dirstate_empty(self):
210
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)