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.
172
167
['mbp@sourcefrog.net-20051004035611-176b16534b086b3c',
173
168
'mbp@sourcefrog.net-20051004035756-235f2b7dcdddd8dd'])
170
def test_upgrade_rich_root(self):
171
tree = self.make_branch_and_tree('tree', format='rich-root')
172
rev_id = tree.commit('first post')
175
175
def test_convert_branch5_branch6(self):
176
176
branch = self.make_branch('branch', format='knit')
177
177
branch.set_revision_history(['AB', 'CD'])
180
180
branch.set_push_location('file:///IJ')
181
181
target = bzrdir.format_registry.make_bzrdir('dirstate-with-subtree')
182
182
converter = branch.bzrdir._format.get_converter(target)
183
converter.convert(branch.bzrdir, progress.DummyProgress())
183
converter.convert(branch.bzrdir, None)
184
184
new_branch = _mod_branch.Branch.open(self.get_url('branch'))
185
185
self.assertIs(new_branch.__class__, _mod_branch.BzrBranch6)
186
186
self.assertEqual('CD', new_branch.last_revision())
193
193
branch2 = self.make_branch('branch2', format='knit')
194
194
converter = branch2.bzrdir._format.get_converter(target)
195
converter.convert(branch2.bzrdir, progress.DummyProgress())
195
converter.convert(branch2.bzrdir, None)
196
196
branch2 = _mod_branch.Branch.open(self.get_url('branch'))
197
197
self.assertIs(branch2.__class__, _mod_branch.BzrBranch6)
199
def test_convert_branch7_branch8(self):
200
branch = self.make_branch('branch', format='1.9')
201
target = bzrdir.format_registry.make_bzrdir('1.9')
202
target.set_branch_format(_mod_branch.BzrBranchFormat8())
203
converter = branch.bzrdir._format.get_converter(target)
204
converter.convert(branch.bzrdir, None)
205
branch = _mod_branch.Branch.open(self.get_url('branch'))
206
self.assertIs(branch.__class__, _mod_branch.BzrBranch8)
207
self.assertEqual({}, branch._get_all_reference_info())
199
209
def test_convert_knit_dirstate_empty(self):
200
210
# test that asking for an upgrade from knit to dirstate works.
201
211
tree = self.make_branch_and_tree('tree', format='knit')
202
212
target = bzrdir.format_registry.make_bzrdir('dirstate')
203
213
converter = tree.bzrdir._format.get_converter(target)
204
converter.convert(tree.bzrdir, progress.DummyProgress())
214
converter.convert(tree.bzrdir, None)
205
215
new_tree = workingtree.WorkingTree.open('tree')
206
216
self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4)
207
217
self.assertEqual('null:', new_tree.last_revision())
214
224
tree.add(['file'], ['file-id'])
215
225
target = bzrdir.format_registry.make_bzrdir('dirstate')
216
226
converter = tree.bzrdir._format.get_converter(target)
217
converter.convert(tree.bzrdir, progress.DummyProgress())
227
converter.convert(tree.bzrdir, None)
218
228
new_tree = workingtree.WorkingTree.open('tree')
219
229
self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4)
220
230
self.assertEqual('null:', new_tree.last_revision())
225
235
rev_id = tree.commit('first post')
226
236
target = bzrdir.format_registry.make_bzrdir('dirstate')
227
237
converter = tree.bzrdir._format.get_converter(target)
228
converter.convert(tree.bzrdir, progress.DummyProgress())
238
converter.convert(tree.bzrdir, None)
229
239
new_tree = workingtree.WorkingTree.open('tree')
230
240
self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4)
231
241
self.assertEqual(rev_id, new_tree.last_revision())
242
252
tree.merge_from_branch(merge_tree.branch)
243
253
target = bzrdir.format_registry.make_bzrdir('dirstate')
244
254
converter = tree.bzrdir._format.get_converter(target)
245
converter.convert(tree.bzrdir, progress.DummyProgress())
255
converter.convert(tree.bzrdir, None)
246
256
new_tree = workingtree.WorkingTree.open('tree')
247
257
self.assertIs(new_tree.__class__, workingtree_4.WorkingTree4)
248
258
self.assertEqual(rev_id2, new_tree.last_revision())