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