~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_upgrade.py

  • Committer: Olaf Conradi
  • Date: 2006-03-28 23:30:02 UTC
  • mto: (1661.1.1 bzr.mbp.remember)
  • mto: This revision was merged to the branch mainline in revision 1663.
  • Revision ID: olaf@conradi.org-20060328233002-f6262df0e19c1963
Added testcases for using pull with --remember. Moved remember code to
beginning of cmd_pull. This remembers the location in case of a failure
during pull.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
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, 6)
 
51
        self.build_tree_contents(_upgrade1_template)
 
52
        upgrade(u'.')
 
53
        control = bzrdir.BzrDir.open('.')
 
54
        b = control.open_branch()
 
55
        r = control.open_repository()
 
56
        t = control.open_workingtree()
 
57
        # tsk, peeking under the covers.
 
58
        self.failUnless(isinstance(control._format, bzrdir.BzrDirFormat6))
 
59
        self.failUnless(isinstance(b._format, bzrlib.branch.BzrBranchFormat4))
 
60
        self.failUnless(isinstance(r._format, repository.RepositoryFormat6))
 
61
        self.failUnless(isinstance(t._format, workingtree.WorkingTreeFormat2))
48
62
        rh = b.revision_history()
49
63
        eq(rh,
50
64
           ['mbp@sourcefrog.net-20051004035611-176b16534b086b3c',
51
65
            'mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd'])
52
 
        t = b.revision_tree(rh[0])
 
66
        rt = b.repository.revision_tree(rh[0])
53
67
        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')
 
68
        eq(rt.get_file_text(foo_id), 'initial contents\n')
 
69
        rt = b.repository.revision_tree(rh[1])
 
70
        eq(rt.get_file_text(foo_id), 'new contents\n')
 
71
        # check a backup was made:
 
72
        transport = get_transport(b.base)
 
73
        transport.stat('.bzr.backup')
 
74
        transport.stat('.bzr.backup/README')
 
75
        transport.stat('.bzr.backup/branch-format')
 
76
        transport.stat('.bzr.backup/revision-history')
 
77
        transport.stat('.bzr.backup/merged-patches')
 
78
        transport.stat('.bzr.backup/pending-merged-patches')
 
79
        transport.stat('.bzr.backup/pending-merges')
 
80
        transport.stat('.bzr.backup/branch-name')
 
81
        transport.stat('.bzr.backup/branch-lock')
 
82
        transport.stat('.bzr.backup/inventory')
 
83
        transport.stat('.bzr.backup/stat-cache')
 
84
        transport.stat('.bzr.backup/text-store')
 
85
        transport.stat('.bzr.backup/text-store/foo-20051004035611-1591048e9dc7c2d4.gz')
 
86
        transport.stat('.bzr.backup/text-store/foo-20051004035756-4081373d897c3453.gz')
 
87
        transport.stat('.bzr.backup/inventory-store/')
 
88
        transport.stat('.bzr.backup/inventory-store/mbp@sourcefrog.net-20051004035611-176b16534b086b3c.gz')
 
89
        transport.stat('.bzr.backup/inventory-store/mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd.gz')
 
90
        transport.stat('.bzr.backup/revision-store/')
 
91
        transport.stat('.bzr.backup/revision-store/mbp@sourcefrog.net-20051004035611-176b16534b086b3c.gz')
 
92
        transport.stat('.bzr.backup/revision-store/mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd.gz')
57
93
 
58
94
    def test_upgrade_with_ghosts(self):
59
95
        """Upgrade v0.0.4 tree containing ghost references.
60
96
 
61
97
        That is, some of the parents of revisions mentioned in the branch
62
 
        aren't present in the branches storage. 
 
98
        aren't present in the branch's storage. 
63
99
 
64
100
        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 
 
101
        bzr, but can happen in branches imported from baz and arch, or from
 
102
        other systems, where the importer knows about a revision but not 
67
103
        its contents."""
68
104
        eq = self.assertEquals
69
 
        build_tree_contents(_ghost_template)
70
 
        upgrade('.')
71
 
        b = Branch.open('.')
 
105
        self.build_tree_contents(_ghost_template)
 
106
        upgrade(u'.')
 
107
        b = Branch.open(u'.')
72
108
        revision_id = b.revision_history()[1]
73
 
        rev = b.get_revision(revision_id)
 
109
        rev = b.repository.get_revision(revision_id)
74
110
        eq(len(rev.parent_ids), 2)
75
111
        eq(rev.parent_ids[1], 'wibble@wobble-2')
76
112
 
77
113
    def test_upgrade_makes_dir_weaves(self):
78
 
        build_tree_contents(_upgrade_dir_template)
 
114
        self.build_tree_contents(_upgrade_dir_template)
79
115
        upgrade('.')
80
116
        # this is the path to the literal file. As format changes 
81
117
        # occur it needs to be updated. FIXME: ask the store for the
83
119
        self.failUnlessExists(
84
120
            '.bzr/weaves/de/dir-20051005095101-da1441ea3fa6917a.weave')
85
121
 
 
122
    def test_upgrade_to_meta_sets_workingtree_last_revision(self):
 
123
        self.build_tree_contents(_upgrade_dir_template)
 
124
        upgrade('.', bzrdir.BzrDirMetaFormat1())
 
125
        tree = workingtree.WorkingTree.open('.')
 
126
        self.assertEqual(tree.last_revision(),
 
127
                         tree.branch.revision_history()[-1])
 
128
 
86
129
 
87
130
_upgrade1_template = \
88
131
     [