~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_upgrade.py

merge with bzr.dev revno.1860

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2005 by 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
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
 
 
7
#
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
 
 
 
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
19
This file contains canned versions of some old trees, which are instantiated 
20
20
and then upgraded to the new format."""
21
21
 
 
22
# TODO queue for upgrade:
 
23
# test the error message when upgrading an unknown BzrDir format.
 
24
 
22
25
import base64
23
26
import os
24
27
import sys
25
28
 
26
 
from bzrlib.selftest import TestCase, TestCaseInTempDir
 
29
import bzrlib.branch
27
30
from bzrlib.branch import Branch
 
31
import bzrlib.bzrdir as bzrdir
 
32
import bzrlib.repository as repository
28
33
from bzrlib.revision import is_ancestor
 
34
from bzrlib.tests import TestCase, TestCaseInTempDir
 
35
from bzrlib.transport import get_transport
29
36
from bzrlib.upgrade import upgrade
30
 
from bzrlib.selftest.treeshape import build_tree_contents
 
37
import bzrlib.workingtree as workingtree
31
38
 
32
39
 
33
40
class TestUpgrade(TestCaseInTempDir):
34
41
    
35
42
    def test_build_tree(self):
36
43
        """Test tree-building test helper"""
37
 
        build_tree_contents(_upgrade1_template)
 
44
        self.build_tree_contents(_upgrade1_template)
38
45
        self.failUnlessExists('foo')
39
46
        self.failUnlessExists('.bzr/README')
40
47
 
41
48
    def test_upgrade_simple(self):
42
 
        """Upgrade simple v0.0.4 format to v5"""
 
49
        """Upgrade simple v0.0.4 format to v6"""
43
50
        eq = self.assertEquals
44
 
        build_tree_contents(_upgrade1_template)
45
 
        upgrade('.')
46
 
        b = Branch.open('.')
47
 
        eq(b._branch_format, 5)
 
51
        self.build_tree_contents(_upgrade1_template)
 
52
        upgrade(u'.')
 
53
        control = bzrdir.BzrDir.open('.')
 
54
        b = control.open_branch()
 
55
        # tsk, peeking under the covers.
 
56
        self.failUnless(
 
57
            isinstance(
 
58
                control._format,
 
59
                bzrdir.BzrDirFormat.get_default_format().__class__))
48
60
        rh = b.revision_history()
49
61
        eq(rh,
50
62
           ['mbp@sourcefrog.net-20051004035611-176b16534b086b3c',
51
63
            'mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd'])
52
 
        t = b.revision_tree(rh[0])
 
64
        rt = b.repository.revision_tree(rh[0])
53
65
        foo_id = 'foo-20051004035605-91e788d1875603ae'
54
 
        eq(t.get_file_text(foo_id), 'initial contents\n')
55
 
        t = b.revision_tree(rh[1])
56
 
        eq(t.get_file_text(foo_id), 'new contents\n')
 
66
        eq(rt.get_file_text(foo_id), 'initial contents\n')
 
67
        rt = b.repository.revision_tree(rh[1])
 
68
        eq(rt.get_file_text(foo_id), 'new contents\n')
 
69
        # check a backup was made:
 
70
        transport = get_transport(b.base)
 
71
        transport.stat('.bzr.backup')
 
72
        transport.stat('.bzr.backup/README')
 
73
        transport.stat('.bzr.backup/branch-format')
 
74
        transport.stat('.bzr.backup/revision-history')
 
75
        transport.stat('.bzr.backup/merged-patches')
 
76
        transport.stat('.bzr.backup/pending-merged-patches')
 
77
        transport.stat('.bzr.backup/pending-merges')
 
78
        transport.stat('.bzr.backup/branch-name')
 
79
        transport.stat('.bzr.backup/branch-lock')
 
80
        transport.stat('.bzr.backup/inventory')
 
81
        transport.stat('.bzr.backup/stat-cache')
 
82
        transport.stat('.bzr.backup/text-store')
 
83
        transport.stat('.bzr.backup/text-store/foo-20051004035611-1591048e9dc7c2d4.gz')
 
84
        transport.stat('.bzr.backup/text-store/foo-20051004035756-4081373d897c3453.gz')
 
85
        transport.stat('.bzr.backup/inventory-store/')
 
86
        transport.stat('.bzr.backup/inventory-store/mbp@sourcefrog.net-20051004035611-176b16534b086b3c.gz')
 
87
        transport.stat('.bzr.backup/inventory-store/mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd.gz')
 
88
        transport.stat('.bzr.backup/revision-store/')
 
89
        transport.stat('.bzr.backup/revision-store/mbp@sourcefrog.net-20051004035611-176b16534b086b3c.gz')
 
90
        transport.stat('.bzr.backup/revision-store/mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd.gz')
57
91
 
58
92
    def test_upgrade_with_ghosts(self):
59
93
        """Upgrade v0.0.4 tree containing ghost references.
60
94
 
61
95
        That is, some of the parents of revisions mentioned in the branch
62
 
        aren't present in the branches storage. 
 
96
        aren't present in the branch's storage. 
63
97
 
64
98
        This shouldn't normally happen in branches created entirely in 
65
 
        bzr but can happen in imports from baz and arch, or from other  
66
 
        systems, where the importer knows about a revision but not 
 
99
        bzr, but can happen in branches imported from baz and arch, or from
 
100
        other systems, where the importer knows about a revision but not 
67
101
        its contents."""
68
102
        eq = self.assertEquals
69
 
        build_tree_contents(_ghost_template)
70
 
        upgrade('.')
71
 
        b = Branch.open('.')
 
103
        self.build_tree_contents(_ghost_template)
 
104
        upgrade(u'.')
 
105
        b = Branch.open(u'.')
72
106
        revision_id = b.revision_history()[1]
73
 
        rev = b.get_revision(revision_id)
 
107
        rev = b.repository.get_revision(revision_id)
74
108
        eq(len(rev.parent_ids), 2)
75
109
        eq(rev.parent_ids[1], 'wibble@wobble-2')
76
110
 
77
111
    def test_upgrade_makes_dir_weaves(self):
78
 
        build_tree_contents(_upgrade_dir_template)
 
112
        self.build_tree_contents(_upgrade_dir_template)
 
113
        old_repodir = bzrlib.bzrdir.BzrDir.open_unsupported('.')
 
114
        old_repo_format = old_repodir.open_repository()._format
79
115
        upgrade('.')
80
 
        self.failUnlessExists(
81
 
            '.bzr/weaves/dir-20051005095101-da1441ea3fa6917a.weave')
 
116
        # this is the path to the literal file. As format changes 
 
117
        # occur it needs to be updated. FIXME: ask the store for the
 
118
        # path.
 
119
        repo = bzrlib.repository.Repository.open('.')
 
120
        # it should have changed the format
 
121
        self.assertNotEqual(old_repo_format.__class__, repo._format.__class__)
 
122
        # and we should be able to read the names for the file id 
 
123
        # 'dir-20051005095101-da1441ea3fa6917a'
 
124
        self.assertNotEqual(
 
125
            [],
 
126
            repo.text_store.get_weave(
 
127
                'dir-20051005095101-da1441ea3fa6917a',
 
128
                repo.get_transaction()))
 
129
 
 
130
    def test_upgrade_to_meta_sets_workingtree_last_revision(self):
 
131
        self.build_tree_contents(_upgrade_dir_template)
 
132
        upgrade('.', bzrdir.BzrDirMetaFormat1())
 
133
        tree = workingtree.WorkingTree.open('.')
 
134
        self.assertEqual(tree.last_revision(),
 
135
                         tree.branch.revision_history()[-1])
82
136
 
83
137
 
84
138
_upgrade1_template = \