173
174
t = control.get_workingtree_transport(None)
174
175
self.assertEqualDiff('Bazaar-NG Working Tree format 3',
175
176
t.get('format').read())
176
self.assertEqualDiff('<inventory format="5">\n'
178
t.get('inventory').read())
177
# self.assertContainsRe(t.get('inventory').read(),
178
# '<inventory file_id="[^"]*" format="5">\n'
181
# WorkingTreeFormat3 doesn't default to creating a unique root id,
182
# because it is incompatible with older bzr versions
183
self.assertContainsRe(t.get('inventory').read(),
184
'<inventory format="5">\n'
179
187
self.assertEqualDiff('### bzr hashcache v5\n',
180
188
t.get('stat-cache').read())
181
189
self.assertFalse(t.has('inventory.basis'))
251
259
class TestNonFormatSpecificCode(TestCaseWithTransport):
252
260
"""This class contains tests of workingtree that are not format specific."""
255
262
def test_gen_file_id(self):
256
gen_file_id = bzrlib.workingtree.gen_file_id
258
# We try to use the filename if possible
259
self.assertStartsWith(gen_file_id('bar'), 'bar-')
261
# but we squash capitalization, and remove non word characters
262
self.assertStartsWith(gen_file_id('Mwoo oof\t m'), 'mwoooofm-')
264
# We also remove leading '.' characters to prevent hidden file-ids
265
self.assertStartsWith(gen_file_id('..gam.py'), 'gam.py-')
266
self.assertStartsWith(gen_file_id('..Mwoo oof\t m'), 'mwoooofm-')
268
# we remove unicode characters, and still don't end up with a
270
self.assertStartsWith(gen_file_id(u'\xe5\xb5.txt'), 'txt-')
263
file_id = self.applyDeprecated(zero_thirteen, workingtree.gen_file_id,
265
self.assertStartsWith(file_id, 'filename-')
267
def test_gen_root_id(self):
268
file_id = self.applyDeprecated(zero_thirteen, workingtree.gen_root_id)
269
self.assertStartsWith(file_id, 'tree_root-')
272
# Our current method of generating unique ids adds 33 characters
273
# plus an serial number (log10(N) characters)
274
# to the end of the filename. We now restrict the filename portion to
275
# be <= 20 characters, so the maximum length should now be approx < 60
277
# Test both case squashing and length restriction
278
fid = gen_file_id('A'*50 + '.txt')
279
self.assertStartsWith(fid, 'a'*20 + '-')
280
self.failUnless(len(fid) < 60)
282
# restricting length happens after the other actions, so
283
# we preserve as much as possible
284
fid = gen_file_id('\xe5\xb5..aBcd\tefGhijKLMnop\tqrstuvwxyz')
285
self.assertStartsWith(fid, 'abcdefghijklmnopqrst-')
286
self.failUnless(len(fid) < 60)
288
def test_next_id_suffix(self):
289
bzrlib.workingtree._gen_id_suffix = None
290
bzrlib.workingtree._next_id_suffix()
291
self.assertNotEqual(None, bzrlib.workingtree._gen_id_suffix)
292
bzrlib.workingtree._gen_id_suffix = "foo-"
293
bzrlib.workingtree._gen_id_serial = 1
294
self.assertEqual("foo-2", bzrlib.workingtree._next_id_suffix())
295
self.assertEqual("foo-3", bzrlib.workingtree._next_id_suffix())
296
self.assertEqual("foo-4", bzrlib.workingtree._next_id_suffix())
297
self.assertEqual("foo-5", bzrlib.workingtree._next_id_suffix())
298
self.assertEqual("foo-6", bzrlib.workingtree._next_id_suffix())
299
self.assertEqual("foo-7", bzrlib.workingtree._next_id_suffix())
300
self.assertEqual("foo-8", bzrlib.workingtree._next_id_suffix())
301
self.assertEqual("foo-9", bzrlib.workingtree._next_id_suffix())
302
self.assertEqual("foo-10", bzrlib.workingtree._next_id_suffix())
304
271
def test__translate_ignore_rule(self):
305
272
tree = self.make_branch_and_tree('.')
306
273
# translation should return the regex, the number of groups in it,