26
28
# because at the moment tree format is orthogonal to user data, and
27
29
# .bzrignore is user data so must not be changed by a tree format.
28
30
self.build_tree_contents([
29
('.bzrignore', './rootdir\nrandomfile*\npath/from/ro?t\n')])
31
('.bzrignore', './rootdir\n'
34
'unicode\xc2\xb5\n' # u'\xb5'.encode('utf8')
30
40
# is_ignored returns the matching ignore regex when a path is ignored.
31
41
# we check some expected matches for each rule, and one or more
32
42
# relevant not-matches that look plausible as cases for bugs.
33
43
self.assertEqual('./rootdir', tree.is_ignored('rootdir'))
34
44
self.assertEqual(None, tree.is_ignored('foo/rootdir'))
35
45
self.assertEqual(None, tree.is_ignored('rootdirtrailer'))
36
47
self.assertEqual('randomfile*', tree.is_ignored('randomfile'))
37
48
self.assertEqual('randomfile*', tree.is_ignored('randomfiles'))
38
49
self.assertEqual('randomfile*', tree.is_ignored('foo/randomfiles'))
39
50
self.assertEqual(None, tree.is_ignored('randomfil'))
40
51
self.assertEqual(None, tree.is_ignored('foo/randomfil'))
41
53
self.assertEqual("path/from/ro?t", tree.is_ignored('path/from/root'))
42
54
self.assertEqual("path/from/ro?t", tree.is_ignored('path/from/roat'))
43
55
self.assertEqual(None, tree.is_ignored('roat'))
57
self.assertEqual(u'unicode\xb5', tree.is_ignored(u'unicode\xb5'))
58
self.assertEqual(u'unicode\xb5', tree.is_ignored(u'subdir/unicode\xb5'))
59
self.assertEqual(None, tree.is_ignored(u'unicode\xe5'))
60
self.assertEqual(None, tree.is_ignored(u'unicode'))
61
self.assertEqual(None, tree.is_ignored(u'\xb5'))
63
self.assertEqual('dos', tree.is_ignored('dos'))
64
self.assertEqual(None, tree.is_ignored('dosfoo'))
66
# Blank lines and comments should be ignored
67
self.assertEqual(None, tree.is_ignored(''))
68
self.assertEqual(None, tree.is_ignored('test/'))
70
self.assertEqual(None, tree.is_ignored('#comment'))
72
# Whitespace should not be stripped
73
self.assertEqual(' xx ', tree.is_ignored(' xx '))
74
self.assertEqual(' xx ', tree.is_ignored('subdir/ xx '))
75
self.assertEqual(None, tree.is_ignored('xx'))
76
self.assertEqual(None, tree.is_ignored('xx '))
77
self.assertEqual(None, tree.is_ignored(' xx'))
78
self.assertEqual(None, tree.is_ignored('subdir/xx '))
80
def test_global_ignored(self):
81
tree = self.make_branch_and_tree('.')
83
config.ensure_config_dir_exists()
84
user_ignore_file = config.user_ignore_config_filename()
85
f = open(user_ignore_file, 'wb')
91
'\r\n' #Blank dos line
92
' * \n' #Trailing and suffix spaces
93
'crlf\r\n' # dos style line
94
'*\xc3\xa5*\n' # u'\xe5'.encode('utf8')
100
self.assertEqual('./.shelf', tree.is_ignored('.shelf'))
101
self.assertEqual(None, tree.is_ignored('foo/.shelf'))
104
self.assertEqual('*.py[co]', tree.is_ignored('foo.pyc'))
105
self.assertEqual('*.py[co]', tree.is_ignored('foo.pyo'))
106
self.assertEqual(None, tree.is_ignored('foo.py'))
109
self.assertEqual('*.py[co]', tree.is_ignored('bar/foo.pyc'))
110
self.assertEqual('*.py[co]', tree.is_ignored('bar/foo.pyo'))
111
self.assertEqual(None, tree.is_ignored('bar/foo.py'))
114
self.assertEqual(u'*\xe5*', tree.is_ignored(u'b\xe5gfors'))
115
self.assertEqual(u'*\xe5*', tree.is_ignored(u'\xe5gfors'))
116
self.assertEqual(u'*\xe5*', tree.is_ignored(u'\xe5'))
117
self.assertEqual(u'*\xe5*', tree.is_ignored(u'b\xe5'))
118
self.assertEqual(u'*\xe5*', tree.is_ignored(u'b/\xe5'))
121
self.assertEqual(' * ', tree.is_ignored(' bbb '))
122
self.assertEqual(' * ', tree.is_ignored('subdir/ bbb '))
123
self.assertEqual(None, tree.is_ignored('bbb '))
124
self.assertEqual(None, tree.is_ignored(' bbb'))
127
self.assertEqual('crlf', tree.is_ignored('crlf'))
128
self.assertEqual('crlf', tree.is_ignored('subdir/crlf'))
130
# Comment line should be ignored
131
self.assertEqual(None, tree.is_ignored('# comment line'))
133
# Blank line should also be ignored
134
self.assertEqual(None, tree.is_ignored(''))
135
self.assertEqual(None, tree.is_ignored('baz/'))
137
def test_mixed_is_ignored(self):
138
tree = self.make_branch_and_tree('.')
139
ignores.set_user_ignores(['*.py[co]', './.shelf'])
140
self.build_tree_contents([('.bzrignore', './rootdir\n*.swp\n')])
142
self.assertEqual('*.py[co]', tree.is_ignored('foo.pyc'))
143
self.assertEqual('./.shelf', tree.is_ignored('.shelf'))
144
self.assertEqual('./rootdir', tree.is_ignored('rootdir'))
145
self.assertEqual('*.swp', tree.is_ignored('.foo.py.swp'))
146
self.assertEqual(None, tree.is_ignored('.foo.py.swo'))
148
def test_DEFAULT_IGNORE(self):
149
tree = self.make_branch_and_tree('.')
150
# It used to be possible for plugins to modify DEFAULT_IGNORE
151
# directly, and get their working files to be ignored.
152
# It is still possible to do so, but this is deprecated.
154
# No configured ignores
155
self.build_tree_contents([('.bzrignore', '')])
156
ignores.set_user_ignores([])
158
self.assertEqual(None, tree.is_ignored('foo.pyc'))
160
# Must reset the list so that it reads a new one
161
tree._ignorelist = None
163
# use list.append() to get around the deprecation warnings
164
list.append(bzrlib.DEFAULT_IGNORE, '*.py[co]')
166
self.assertEqual('*.py[co]', tree.is_ignored('foo.pyc'))
168
list.remove(bzrlib.DEFAULT_IGNORE, '*.py[co]')