38
46
self.failUnlessExists('.bzr/README')
40
48
def test_upgrade_simple(self):
41
"""Upgrade simple v0.0.4 format to v6"""
49
"""Upgrade simple v0.0.4 format to latest format"""
42
50
eq = self.assertEquals
43
51
self.build_tree_contents(_upgrade1_template)
46
eq(b._branch_format, 6)
53
control = bzrdir.BzrDir.open('.')
54
b = control.open_branch()
55
# tsk, peeking under the covers.
59
bzrdir.BzrDirFormat.get_default_format().__class__))
47
60
rh = b.revision_history()
49
62
['mbp@sourcefrog.net-20051004035611-176b16534b086b3c',
50
63
'mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd'])
51
t = b.revision_tree(rh[0])
64
rt = b.repository.revision_tree(rh[0])
52
65
foo_id = 'foo-20051004035605-91e788d1875603ae'
53
eq(t.get_file_text(foo_id), 'initial contents\n')
54
t = b.revision_tree(rh[1])
55
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
92
def test_upgrade_with_ghosts(self):
58
93
"""Upgrade v0.0.4 tree containing ghost references.
60
95
That is, some of the parents of revisions mentioned in the branch
61
aren't present in the branches storage.
96
aren't present in the branch's storage.
63
98
This shouldn't normally happen in branches created entirely in
64
bzr but can happen in imports from baz and arch, or from other
65
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
102
eq = self.assertEquals
68
103
self.build_tree_contents(_ghost_template)
70
105
b = Branch.open(u'.')
71
106
revision_id = b.revision_history()[1]
72
rev = b.get_revision(revision_id)
107
rev = b.repository.get_revision(revision_id)
73
108
eq(len(rev.parent_ids), 2)
74
109
eq(rev.parent_ids[1], 'wibble@wobble-2')
76
111
def test_upgrade_makes_dir_weaves(self):
77
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
116
# this is the path to the literal file. As format changes
80
117
# occur it needs to be updated. FIXME: ask the store for the
82
self.failUnlessExists(
83
'.bzr/weaves/de/dir-20051005095101-da1441ea3fa6917a.weave')
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'
126
repo.text_store.get_weave(
127
'dir-20051005095101-da1441ea3fa6917a',
128
repo.get_transaction()))
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])
137
def test_upgrade_v6_to_meta_no_workingtree(self):
138
# Some format6 branches do not have checkout files. Upgrading
139
# such a branch to metadir must not setup a working tree.
140
self.build_tree_contents(_upgrade1_template)
141
upgrade('.', bzrdir.BzrDirFormat6())
142
transport = get_transport('.')
143
transport.delete_multi(['.bzr/pending-merges', '.bzr/inventory'])
144
assert not transport.has('.bzr/stat-cache')
145
# XXX: upgrade fails if a .bzr.backup is already present
146
# -- David Allouche 2006-08-11
147
transport.delete_tree('.bzr.backup')
148
# At this point, we have a format6 branch without checkout files.
149
upgrade('.', bzrdir.BzrDirMetaFormat1())
150
# The upgrade should not have set up a working tree.
151
control = bzrdir.BzrDir.open('.')
152
self.assertFalse(control.has_workingtree())
153
# We have covered the scope of this test, we may as well check that
154
# upgrade has not eaten our data, even if it's a bit redundant with
156
self.failUnless(isinstance(control._format, bzrdir.BzrDirMetaFormat1))
157
branch = control.open_branch()
158
self.assertEquals(branch.revision_history(),
159
['mbp@sourcefrog.net-20051004035611-176b16534b086b3c',
160
'mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd'])
86
163
_upgrade1_template = \