~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_upgrade.py

  • Committer: Martin
  • Date: 2011-03-02 20:16:03 UTC
  • mto: This revision was merged to the branch mainline in revision 5694.
  • Revision ID: gzlist@googlemail.com-20110302201603-4tf70q41xu1756lh
Gut smart.message._translate_error as it duplicates logic in remote

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
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,
 
29
    tests,
 
30
    upgrade,
34
31
    workingtree,
35
32
    workingtree_4,
36
33
    )
37
 
import bzrlib.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
42
 
 
43
 
 
44
 
class TestUpgrade(TestCaseWithTransport):
45
 
 
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')
 
34
 
 
35
 
 
36
class TestUpgrade(tests.TestCaseWithTransport):
51
37
 
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)
56
 
        upgrade(u'.')
 
42
        upgrade.upgrade(u'.')
57
43
        control = bzrdir.BzrDir.open('.')
58
44
        b = control.open_branch()
59
45
        # tsk, peeking under the covers.
80
66
            rt.unlock()
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('.')
 
70
        t.stat(backup_dir)
 
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')
104
90
 
105
91
    def test_upgrade_with_ghosts(self):
106
92
        """Upgrade v0.0.4 tree containing ghost references.
114
100
        its contents."""
115
101
        eq = self.assertEquals
116
102
        self.build_tree_contents(_ghost_template)
117
 
        upgrade(u'.')
118
 
        b = Branch.open(u'.')
 
103
        upgrade.upgrade(u'.')
 
104
        b = branch.Branch.open(u'.')
119
105
        revision_id = b.revision_history()[1]
120
106
        rev = b.repository.get_revision(revision_id)
121
107
        eq(len(rev.parent_ids), 2)
123
109
 
124
110
    def test_upgrade_makes_dir_weaves(self):
125
111
        self.build_tree_contents(_upgrade_dir_template)
126
 
        old_repodir = bzrlib.bzrdir.BzrDir.open_unsupported('.')
 
112
        old_repodir = bzrdir.BzrDir.open_unsupported('.')
127
113
        old_repo_format = old_repodir.open_repository()._format
128
 
        upgrade('.')
 
114
        upgrade.upgrade('.')
129
115
        # this is the path to the literal file. As format changes
130
116
        # occur it needs to be updated. FIXME: ask the store for the
131
117
        # path.
132
 
        repo = bzrlib.repository.Repository.open('.')
 
118
        repo = repository.Repository.open('.')
133
119
        # it should have changed the format
134
120
        self.assertNotEqual(old_repo_format.__class__, repo._format.__class__)
135
121
        # and we should be able to read the names for the file id
143
129
 
144
130
    def test_upgrade_to_meta_sets_workingtree_last_revision(self):
145
131
        self.build_tree_contents(_upgrade_dir_template)
146
 
        upgrade('.', bzrdir.BzrDirMetaFormat1())
 
132
        upgrade.upgrade('.', bzrdir.BzrDirMetaFormat1())
147
133
        tree = workingtree.WorkingTree.open('.')
148
134
        self.assertEqual([tree.branch.revision_history()[-1]],
149
135
            tree.get_parent_ids())
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
169
155
        # other tests.
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'])
175
161
 
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')
179
 
        upgrade('tree')
 
165
        upgrade.upgrade('tree')
180
166
 
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'))
198
184
 
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)
204
190
 
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())
214
200
 
215
201
    def test_convert_knit_dirstate_empty(self):
216
202
        # test that asking for an upgrade from knit to dirstate works.
275
261
     ('.bzr/README',
276
262
      'This is a Bazaar control directory.\n'
277
263
      'Do not change any files in this directory.\n'
278
 
      'See http://bazaar-vcs.org/ for more information about Bazaar.\n'),
 
264
      'See http://bazaar.canonical.com/ for more information about Bazaar.\n'),
279
265
     ('.bzr/branch-format', 'Bazaar-NG branch, format 0.0.4\n'),
280
266
     ('.bzr/revision-history',
281
267
      'mbp@sourcefrog.net-20051004035611-176b16534b086b3c\n'
317
303
    ( './.bzr/README',
318
304
      'This is a Bazaar control directory.\n'
319
305
      'Do not change any files in this directory.\n'
320
 
      'See http://bazaar-vcs.org/ for more information about Bazaar.\n'
 
306
      'See http://bazaar.canonical.com/ for more information about Bazaar.\n'
321
307
    ),
322
308
    ( './.bzr/branch-format',
323
309
        'Bazaar-NG branch, format 0.0.4\n'
383
369
    ( './.bzr/README',
384
370
      'This is a Bazaar control directory.\n'
385
371
      'Do not change any files in this directory.\n'
386
 
      'See http://bazaar-vcs.org/ for more information about Bazaar.\n'
 
372
      'See http://bazaar.canonical.com/ for more information about Bazaar.\n'
387
373
    ),
388
374
    ( './.bzr/branch-format',
389
375
        'Bazaar-NG branch, format 0.0.4\n'
429
415
    ),
430
416
    ( './dir/', ),
431
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)