~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_upgrade.py

  • Committer: Vincent Ladeuil
  • Date: 2010-12-20 12:01:56 UTC
  • mfrom: (4360.10.50 smooth-upgrades)
  • mto: This revision was merged to the branch mainline in revision 5576.
  • Revision ID: v.ladeuil+lp@free.fr-20101220120156-0rje08csoeuszd93
Smoother upgrades

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
# TODO queue for upgrade:
23
23
# test the error message when upgrading an unknown BzrDir format.
24
24
 
25
 
import base64
26
 
import os
27
 
import sys
28
 
 
29
25
from bzrlib import (
30
 
    branch as _mod_branch,
 
26
    branch,
31
27
    bzrdir,
32
 
    progress,
33
28
    repository,
34
 
    transport,
 
29
    tests,
 
30
    upgrade,
35
31
    workingtree,
36
32
    workingtree_4,
37
33
    )
38
 
import bzrlib.branch
39
 
from bzrlib.branch import Branch
40
 
from bzrlib.tests import TestCaseWithTransport
41
 
from bzrlib.upgrade import upgrade
42
 
 
43
 
 
44
 
class TestUpgrade(TestCaseWithTransport):
 
34
 
 
35
 
 
36
class TestUpgrade(tests.TestCaseWithTransport):
45
37
 
46
38
    def test_upgrade_simple(self):
47
39
        """Upgrade simple v0.0.4 format to latest format"""
48
40
        eq = self.assertEquals
49
41
        self.build_tree_contents(_upgrade1_template)
50
 
        upgrade(u'.')
 
42
        upgrade.upgrade(u'.')
51
43
        control = bzrdir.BzrDir.open('.')
52
44
        b = control.open_branch()
53
45
        # tsk, peeking under the covers.
74
66
            rt.unlock()
75
67
        # check a backup was made:
76
68
        backup_dir = 'backup.bzr.~1~'
77
 
        t = transport.get_transport(b.base)
 
69
        t = self.get_transport('.')
78
70
        t.stat(backup_dir)
79
71
        t.stat(backup_dir + '/README')
80
72
        t.stat(backup_dir + '/branch-format')
108
100
        its contents."""
109
101
        eq = self.assertEquals
110
102
        self.build_tree_contents(_ghost_template)
111
 
        upgrade(u'.')
112
 
        b = Branch.open(u'.')
 
103
        upgrade.upgrade(u'.')
 
104
        b = branch.Branch.open(u'.')
113
105
        revision_id = b.revision_history()[1]
114
106
        rev = b.repository.get_revision(revision_id)
115
107
        eq(len(rev.parent_ids), 2)
117
109
 
118
110
    def test_upgrade_makes_dir_weaves(self):
119
111
        self.build_tree_contents(_upgrade_dir_template)
120
 
        old_repodir = bzrlib.bzrdir.BzrDir.open_unsupported('.')
 
112
        old_repodir = bzrdir.BzrDir.open_unsupported('.')
121
113
        old_repo_format = old_repodir.open_repository()._format
122
 
        upgrade('.')
 
114
        upgrade.upgrade('.')
123
115
        # this is the path to the literal file. As format changes
124
116
        # occur it needs to be updated. FIXME: ask the store for the
125
117
        # path.
126
 
        repo = bzrlib.repository.Repository.open('.')
 
118
        repo = repository.Repository.open('.')
127
119
        # it should have changed the format
128
120
        self.assertNotEqual(old_repo_format.__class__, repo._format.__class__)
129
121
        # and we should be able to read the names for the file id
137
129
 
138
130
    def test_upgrade_to_meta_sets_workingtree_last_revision(self):
139
131
        self.build_tree_contents(_upgrade_dir_template)
140
 
        upgrade('.', bzrdir.BzrDirMetaFormat1())
 
132
        upgrade.upgrade('.', bzrdir.BzrDirMetaFormat1())
141
133
        tree = workingtree.WorkingTree.open('.')
142
134
        self.assertEqual([tree.branch.revision_history()[-1]],
143
135
            tree.get_parent_ids())
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
163
155
        # other tests.
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'])
169
161
 
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')
173
 
        upgrade('tree')
 
165
        upgrade.upgrade('tree')
174
166
 
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'))
192
184
 
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)
198
190
 
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())
208
200
 
209
201
    def test_convert_knit_dirstate_empty(self):
210
202
        # test that asking for an upgrade from knit to dirstate works.
423
415
    ),
424
416
    ( './dir/', ),
425
417
]
 
418
 
 
419
 
 
420
class TestSmartUpgrade(tests.TestCaseWithTransport):
 
421
 
 
422
    from_format = bzrdir.format_registry.make_bzrdir("pack-0.92")
 
423
    to_format = bzrdir.format_registry.make_bzrdir("2a")
 
424
 
 
425
    def make_standalone_branch(self):
 
426
        wt = self.make_branch_and_tree("branch1", format=self.from_format)
 
427
        return wt.bzrdir
 
428
 
 
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)
 
441
 
 
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)
 
456
 
 
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)
 
466
        return repo.bzrdir
 
467
 
 
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)
 
484
 
 
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)