37
38
import bzrlib.branch
38
39
from bzrlib.branch import Branch
39
40
from bzrlib.tests import TestCaseWithTransport
40
from bzrlib.transport import get_transport
41
41
from bzrlib.upgrade import upgrade
44
44
class TestUpgrade(TestCaseWithTransport):
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')
52
46
def test_upgrade_simple(self):
53
47
"""Upgrade simple v0.0.4 format to latest format"""
54
48
eq = self.assertEquals
81
75
# check a backup was made:
82
transport = get_transport(b.base)
83
transport.stat('backup.bzr')
84
transport.stat('backup.bzr/README')
85
transport.stat('backup.bzr/branch-format')
86
transport.stat('backup.bzr/revision-history')
87
transport.stat('backup.bzr/merged-patches')
88
transport.stat('backup.bzr/pending-merged-patches')
89
transport.stat('backup.bzr/pending-merges')
90
transport.stat('backup.bzr/branch-name')
91
transport.stat('backup.bzr/branch-lock')
92
transport.stat('backup.bzr/inventory')
93
transport.stat('backup.bzr/stat-cache')
94
transport.stat('backup.bzr/text-store')
95
transport.stat('backup.bzr/text-store/foo-20051004035611-1591048e9dc7c2d4.gz')
96
transport.stat('backup.bzr/text-store/foo-20051004035756-4081373d897c3453.gz')
97
transport.stat('backup.bzr/inventory-store/')
98
transport.stat('backup.bzr/inventory-store/mbp@sourcefrog.net-20051004035611-176b16534b086b3c.gz')
99
transport.stat('backup.bzr/inventory-store/mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd.gz')
100
transport.stat('backup.bzr/revision-store/')
101
transport.stat('backup.bzr/revision-store/mbp@sourcefrog.net-20051004035611-176b16534b086b3c.gz')
102
transport.stat('backup.bzr/revision-store/mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd.gz')
76
backup_dir = 'backup.bzr.~1~'
77
t = transport.get_transport(b.base)
79
t.stat(backup_dir + '/README')
80
t.stat(backup_dir + '/branch-format')
81
t.stat(backup_dir + '/revision-history')
82
t.stat(backup_dir + '/merged-patches')
83
t.stat(backup_dir + '/pending-merged-patches')
84
t.stat(backup_dir + '/pending-merges')
85
t.stat(backup_dir + '/branch-name')
86
t.stat(backup_dir + '/branch-lock')
87
t.stat(backup_dir + '/inventory')
88
t.stat(backup_dir + '/stat-cache')
89
t.stat(backup_dir + '/text-store')
90
t.stat(backup_dir + '/text-store/foo-20051004035611-1591048e9dc7c2d4.gz')
91
t.stat(backup_dir + '/text-store/foo-20051004035756-4081373d897c3453.gz')
92
t.stat(backup_dir + '/inventory-store/')
93
t.stat(backup_dir + '/inventory-store/mbp@sourcefrog.net-20051004035611-176b16534b086b3c.gz')
94
t.stat(backup_dir + '/inventory-store/mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd.gz')
95
t.stat(backup_dir + '/revision-store/')
96
t.stat(backup_dir + '/revision-store/mbp@sourcefrog.net-20051004035611-176b16534b086b3c.gz')
97
t.stat(backup_dir + '/revision-store/mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd.gz')
104
99
def test_upgrade_with_ghosts(self):
105
100
"""Upgrade v0.0.4 tree containing ghost references.
152
147
# such a branch to metadir must not setup a working tree.
153
148
self.build_tree_contents(_upgrade1_template)
154
149
upgrade('.', bzrdir.BzrDirFormat6())
155
transport = get_transport('.')
156
transport.delete_multi(['.bzr/pending-merges', '.bzr/inventory'])
157
self.assertFalse(transport.has('.bzr/stat-cache'))
150
t = transport.get_transport('.')
151
t.delete_multi(['.bzr/pending-merges', '.bzr/inventory'])
152
self.assertFalse(t.has('.bzr/stat-cache'))
158
153
# XXX: upgrade fails if a backup.bzr is already present
159
154
# -- David Allouche 2006-08-11
160
transport.delete_tree('backup.bzr')
155
t.delete_tree('backup.bzr.~1~')
161
156
# At this point, we have a format6 branch without checkout files.
162
157
upgrade('.', bzrdir.BzrDirMetaFormat1())
163
158
# The upgrade should not have set up a working tree.
185
180
branch.set_push_location('file:///IJ')
186
181
target = bzrdir.format_registry.make_bzrdir('dirstate-with-subtree')
187
182
converter = branch.bzrdir._format.get_converter(target)
188
converter.convert(branch.bzrdir, progress.DummyProgress())
183
converter.convert(branch.bzrdir, None)
189
184
new_branch = _mod_branch.Branch.open(self.get_url('branch'))
190
185
self.assertIs(new_branch.__class__, _mod_branch.BzrBranch6)
191
186
self.assertEqual('CD', new_branch.last_revision())
198
193
branch2 = self.make_branch('branch2', format='knit')
199
194
converter = branch2.bzrdir._format.get_converter(target)
200
converter.convert(branch2.bzrdir, progress.DummyProgress())
195
converter.convert(branch2.bzrdir, None)
201
196
branch2 = _mod_branch.Branch.open(self.get_url('branch'))
202
197
self.assertIs(branch2.__class__, _mod_branch.BzrBranch6)
206
201
target = bzrdir.format_registry.make_bzrdir('1.9')
207
202
target.set_branch_format(_mod_branch.BzrBranchFormat8())
208
203
converter = branch.bzrdir._format.get_converter(target)
209
converter.convert(branch.bzrdir, progress.DummyProgress())
204
converter.convert(branch.bzrdir, None)
210
205
branch = _mod_branch.Branch.open(self.get_url('branch'))
211
206
self.assertIs(branch.__class__, _mod_branch.BzrBranch8)
212
207
self.assertEqual({}, branch._get_all_reference_info())
216
211
tree = self.make_branch_and_tree('tree', format='knit')
217
212
target = bzrdir.format_registry.make_bzrdir('dirstate')
218
213
converter = tree.bzrdir._format.get_converter(target)
219
converter.convert(tree.bzrdir, progress.DummyProgress())
214
converter.convert(tree.bzrdir, None)
220
215
new_tree = workingtree.WorkingTree.open('tree')
221
216
self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4)
222
217
self.assertEqual('null:', new_tree.last_revision())
229
224
tree.add(['file'], ['file-id'])
230
225
target = bzrdir.format_registry.make_bzrdir('dirstate')
231
226
converter = tree.bzrdir._format.get_converter(target)
232
converter.convert(tree.bzrdir, progress.DummyProgress())
227
converter.convert(tree.bzrdir, None)
233
228
new_tree = workingtree.WorkingTree.open('tree')
234
229
self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4)
235
230
self.assertEqual('null:', new_tree.last_revision())
240
235
rev_id = tree.commit('first post')
241
236
target = bzrdir.format_registry.make_bzrdir('dirstate')
242
237
converter = tree.bzrdir._format.get_converter(target)
243
converter.convert(tree.bzrdir, progress.DummyProgress())
238
converter.convert(tree.bzrdir, None)
244
239
new_tree = workingtree.WorkingTree.open('tree')
245
240
self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4)
246
241
self.assertEqual(rev_id, new_tree.last_revision())
257
252
tree.merge_from_branch(merge_tree.branch)
258
253
target = bzrdir.format_registry.make_bzrdir('dirstate')
259
254
converter = tree.bzrdir._format.get_converter(target)
260
converter.convert(tree.bzrdir, progress.DummyProgress())
255
converter.convert(tree.bzrdir, None)
261
256
new_tree = workingtree.WorkingTree.open('tree')
262
257
self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4)
263
258
self.assertEqual(rev_id2, new_tree.last_revision())