268
268
file_id = self.applyDeprecated(zero_thirteen, workingtree.gen_root_id)
269
269
self.assertStartsWith(file_id, 'tree_root-')
271
def test__translate_ignore_rule(self):
272
tree = self.make_branch_and_tree('.')
273
# translation should return the regex, the number of groups in it,
274
# and the original rule in a tuple.
275
# there are three sorts of ignore rules:
276
# root only - regex is the rule itself without the leading ./
279
tree._translate_ignore_rule("./rootdirrule"))
280
# full path - regex is the rule itself
282
"(path\\/to\\/file$)",
283
tree._translate_ignore_rule("path/to/file"))
284
# basename only rule - regex is a rule that ignores everything up
285
# to the last / in the filename
287
"((?:.*/)?(?!.*/)basenamerule$)",
288
tree._translate_ignore_rule("basenamerule"))
290
def test__combine_ignore_rules(self):
291
tree = self.make_branch_and_tree('.')
292
# the combined ignore regexs need the outer group indices
293
# placed in a dictionary with the rules that were combined.
294
# an empty set of rules
295
# this is returned as a list of combined regex,rule sets, because
296
# python has a limit of 100 combined regexes.
297
compiled_rules = tree._combine_ignore_rules([])
298
self.assertEqual([], compiled_rules)
299
# one of each type of rule.
300
compiled_rules = tree._combine_ignore_rules(
301
["rule1", "rule/two", "./three"])[0]
302
# what type *is* the compiled regex to do an isinstance of ?
303
self.assertEqual(3, compiled_rules[0].groups)
305
{0:"rule1",1:"rule/two",2:"./three"},
308
def test__combine_ignore_rules_grouping(self):
309
tree = self.make_branch_and_tree('.')
310
# when there are too many rules, the output is split into groups of 100
312
for index in range(198):
314
self.assertEqual(2, len(tree._combine_ignore_rules(rules)))
316
def test__get_ignore_rules_as_regex(self):
317
tree = self.make_branch_and_tree('.')
318
# Setup the default ignore list to be empty
319
ignores._set_user_ignores([])
321
# some plugins (shelf) modifies the DEFAULT_IGNORE list in memory
322
# which causes this test to fail so force the DEFAULT_IGNORE
324
orig_default = bzrlib.DEFAULT_IGNORE
325
# Also make sure the runtime ignore list is empty
326
orig_runtime = ignores._runtime_ignores
328
bzrlib.DEFAULT_IGNORE = []
329
ignores._runtime_ignores = set()
331
self.build_tree_contents([('.bzrignore', 'CVS\n.hg\n')])
332
reference_output = tree._combine_ignore_rules(
333
set(['CVS', '.hg']))[0]
334
regex_rules = tree._get_ignore_rules_as_regex()[0]
335
self.assertEqual(len(reference_output[1]), regex_rules[0].groups)
336
self.assertEqual(reference_output[1], regex_rules[1])
338
bzrlib.DEFAULT_IGNORE = orig_default
339
ignores._runtime_ignores = orig_runtime
342
272
class InstrumentedTree(object):
343
273
"""A instrumented tree to check the needs_tree_write_lock decorator."""