18
18
from cStringIO import StringIO
21
from bzrlib import ignores
22
23
from bzrlib.branch import Branch
23
24
from bzrlib import bzrdir, conflicts, errors, workingtree
249
250
def test_gen_file_id(self):
250
self.assertStartsWith(bzrlib.workingtree.gen_file_id('bar'), 'bar-')
251
self.assertStartsWith(bzrlib.workingtree.gen_file_id('Mwoo oof\t m'), 'Mwoooofm-')
252
self.assertStartsWith(bzrlib.workingtree.gen_file_id('..gam.py'), 'gam.py-')
253
self.assertStartsWith(bzrlib.workingtree.gen_file_id('..Mwoo oof\t m'), 'Mwoooofm-')
251
gen_file_id = bzrlib.workingtree.gen_file_id
253
# We try to use the filename if possible
254
self.assertStartsWith(gen_file_id('bar'), 'bar-')
256
# but we squash capitalization, and remove non word characters
257
self.assertStartsWith(gen_file_id('Mwoo oof\t m'), 'mwoooofm-')
259
# We also remove leading '.' characters to prevent hidden file-ids
260
self.assertStartsWith(gen_file_id('..gam.py'), 'gam.py-')
261
self.assertStartsWith(gen_file_id('..Mwoo oof\t m'), 'mwoooofm-')
263
# we remove unicode characters, and still don't end up with a
265
self.assertStartsWith(gen_file_id(u'\xe5\xb5.txt'), 'txt-')
267
# Our current method of generating unique ids adds 33 characters
268
# plus an serial number (log10(N) characters)
269
# to the end of the filename. We now restrict the filename portion to
270
# be <= 20 characters, so the maximum length should now be approx < 60
272
# Test both case squashing and length restriction
273
fid = gen_file_id('A'*50 + '.txt')
274
self.assertStartsWith(fid, 'a'*20 + '-')
275
self.failUnless(len(fid) < 60)
277
# restricting length happens after the other actions, so
278
# we preserve as much as possible
279
fid = gen_file_id('\xe5\xb5..aBcd\tefGhijKLMnop\tqrstuvwxyz')
280
self.assertStartsWith(fid, 'abcdefghijklmnopqrst-')
281
self.failUnless(len(fid) < 60)
255
283
def test_next_id_suffix(self):
256
284
bzrlib.workingtree._gen_id_suffix = None
316
344
def test__get_ignore_rules_as_regex(self):
317
345
tree = self.make_branch_and_tree('.')
318
self.build_tree_contents([('.bzrignore', 'CVS\n.hg\n')])
319
reference_output = tree._combine_ignore_rules(['CVS', '.hg'])[0]
320
regex_rules = tree._get_ignore_rules_as_regex()[0]
321
self.assertEqual(len(reference_output[1]), regex_rules[0].groups)
322
self.assertEqual(reference_output[1], regex_rules[1])
346
# Setup the default ignore list to be empty
347
ignores._set_user_ignores([])
349
# some plugins (shelf) modifies the DEFAULT_IGNORE list in memory
350
# which causes this test to fail so force the DEFAULT_IGNORE
352
orig_default = bzrlib.DEFAULT_IGNORE
353
# Also make sure the runtime ignore list is empty
354
orig_runtime = ignores._runtime_ignores
356
bzrlib.DEFAULT_IGNORE = []
357
ignores._runtime_ignores = set()
359
self.build_tree_contents([('.bzrignore', 'CVS\n.hg\n')])
360
reference_output = tree._combine_ignore_rules(
361
set(['CVS', '.hg']))[0]
362
regex_rules = tree._get_ignore_rules_as_regex()[0]
363
self.assertEqual(len(reference_output[1]), regex_rules[0].groups)
364
self.assertEqual(reference_output[1], regex_rules[1])
366
bzrlib.DEFAULT_IGNORE = orig_default
367
ignores._runtime_ignores = orig_runtime