68
67
def test_get_set_default_format(self):
69
68
old_format = workingtree.format_registry.get_default()
71
self.assertTrue(isinstance(old_format, workingtree_4.WorkingTreeFormat6))
70
self.assertTrue(isinstance(
71
old_format, workingtree_4.WorkingTreeFormat6))
72
72
workingtree.format_registry.set_default(SampleTreeFormat())
74
74
# the default branch format is used by the meta dir format
86
86
self.assertIsInstance(
87
87
SampleTreeFormat.from_string(b"Sample tree format."),
89
self.assertRaises(AssertionError,
90
SampleTreeFormat.from_string, b"Different format string.")
90
AssertionError, SampleTreeFormat.from_string,
91
b"Different format string.")
92
93
def test_get_set_default_format_by_key(self):
93
94
old_format = workingtree.format_registry.get_default()
95
96
format = SampleTreeFormat()
96
97
workingtree.format_registry.register(format)
97
98
self.addCleanup(workingtree.format_registry.remove, format)
98
self.assertTrue(isinstance(old_format, workingtree_4.WorkingTreeFormat6))
99
self.assertTrue(isinstance(
100
old_format, workingtree_4.WorkingTreeFormat6))
99
101
workingtree.format_registry.set_default_key(format.get_format_string())
101
103
# the default branch format is used by the meta dir format
125
127
open_no_args, relpath = workingtree.WorkingTree.open_containing()
126
128
self.assertEqual(tree.basedir, open_no_args.basedir)
127
129
self.assertEqual('', relpath)
128
open_subdir, relpath = workingtree.WorkingTree.open_containing('subdir')
130
open_subdir, relpath = workingtree.WorkingTree.open_containing(
129
132
self.assertEqual(tree.basedir, open_subdir.basedir)
130
133
self.assertEqual('subdir', relpath)
182
185
def test_find_format_string(self):
183
186
# is the right format object found for a working tree?
184
187
branch = self.make_branch('branch')
185
self.assertRaises(errors.NoWorkingTree,
186
bzrworkingtree.WorkingTreeFormatMetaDir.find_format_string, branch.controldir)
189
errors.NoWorkingTree,
190
bzrworkingtree.WorkingTreeFormatMetaDir.find_format_string,
187
192
transport = branch.controldir.get_workingtree_transport(None)
188
193
transport.mkdir('.')
189
194
transport.put_bytes("format", b"some format name")
190
195
# The format does not have to be known by Bazaar,
191
196
# find_format_string just retrieves the name
192
self.assertEqual(b"some format name",
193
bzrworkingtree.WorkingTreeFormatMetaDir.find_format_string(branch.controldir))
199
bzrworkingtree.WorkingTreeFormatMetaDir.find_format_string(
195
202
def test_find_format(self):
196
203
# is the right format object found for a working tree?
197
204
# create a branch with a few known format objects.
198
205
self.build_tree(["foo/", "bar/"])
199
207
def check_format(format, url):
200
208
dir = format._matchingcontroldir.initialize(url)
201
209
dir.create_repository()
202
210
dir.create_branch()
203
211
format.initialize(dir)
204
t = transport.get_transport(url)
205
found_format = bzrworkingtree.WorkingTreeFormatMetaDir.find_format(dir)
212
found_format = bzrworkingtree.WorkingTreeFormatMetaDir.find_format(
206
214
self.assertIsInstance(found_format, format.__class__)
207
215
check_format(workingtree_3.WorkingTreeFormat3(), "bar")
229
237
self.assertIsInstance(found_format, workingtree.WorkingTreeFormat)
230
238
self.assertEqual(found_format.features.get(b"name"), b"necessity")
231
self.assertRaises(bzrdir.MissingFeature, found_format.check_support_status,
233
self.addCleanup(bzrworkingtree.WorkingTreeFormatMetaDir.unregister_feature,
240
bzrdir.MissingFeature, found_format.check_support_status, True)
242
bzrworkingtree.WorkingTreeFormatMetaDir.unregister_feature,
235
244
bzrworkingtree.WorkingTreeFormatMetaDir.register_feature(b"name")
236
245
found_format.check_support_status(True)
254
263
('file', b'c-id')],
255
264
[(ie.kind, ie.file_id)
256
265
for path, ie in tree.iter_entries_by_dir()])
257
subtree = self.make_branch_and_tree('tree/a/b')
266
self.make_branch_and_tree('tree/a/b')
258
267
self.assertEqual([('tree-reference', b'b-id')],
259
268
[(ie.kind, ie.file_id)
260
269
for path, ie in tree.iter_entries_by_dir(
263
272
def test_direct_subtree(self):
264
273
tree = self.make_simple_tree()
265
subtree = self.make_branch_and_tree('tree/a/b')
274
self.make_branch_and_tree('tree/a/b')
266
275
self.assertEqual([('directory', b'root-id'),
267
276
('directory', b'a-id'),
268
277
('tree-reference', b'b-id')],
272
281
def test_indirect_subtree(self):
273
282
tree = self.make_simple_tree()
274
subtree = self.make_branch_and_tree('tree/a')
283
self.make_branch_and_tree('tree/a')
275
284
self.assertEqual([('directory', b'root-id'),
276
285
('tree-reference', b'a-id')],
277
286
[(ie.kind, ie.file_id)
306
315
def test_register_extra_lazy(self):
307
316
self.assertEqual([], self.registry._get_all())
308
317
self.registry.register_extra_lazy("breezy.tests.test_workingtree",
309
"SampleExtraTreeFormat")
318
"SampleExtraTreeFormat")
310
319
formats = self.registry._get_all()
311
320
self.assertEqual(1, len(formats))
312
321
self.assertIsInstance(formats[0], SampleExtraTreeFormat)
319
328
control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
320
329
control.create_repository()
321
330
control.create_branch()
322
tree = workingtree_3.WorkingTreeFormat3().initialize(control)
331
workingtree_3.WorkingTreeFormat3().initialize(control)
324
333
# format 'Bazaar-NG Working Tree format 3'
325
334
# inventory = blank inventory
330
339
self.assertEqualDiff(b'Bazaar-NG Working Tree format 3',
331
340
t.get('format').read())
332
341
self.assertEqualDiff(t.get('inventory').read(),
333
b'<inventory format="5">\n'
342
b'<inventory format="5">\n'
336
345
self.assertEqualDiff(b'### bzr hashcache v5\n',
337
346
t.get('stat-cache').read())
350
359
t = self.get_transport()
351
360
url = self.get_url()
352
361
dir = bzrdir.BzrDirMetaFormat1().initialize(url)
353
repo = dir.create_repository()
354
branch = dir.create_branch()
362
dir.create_repository()
356
365
tree = workingtree_3.WorkingTreeFormat3().initialize(dir)
357
366
except errors.NotLocalUrl:
382
391
('this-tree/foo/bar', b'bar')])
383
392
this_tree.add(['foo', 'foo/bar'])
384
393
this_tree.commit('created foo/bar')
385
other_tree = this_tree.controldir.sprout('other-tree').open_workingtree()
394
other_tree = this_tree.controldir.sprout(
395
'other-tree').open_workingtree()
386
396
self.build_tree_contents([('other-tree/foo/bar', b'baz')])
387
397
other_tree.commit('changed bar')
388
398
self.build_tree_contents([('this-tree/foo/bar', b'qux')])