1
# Copyright (C) 2006, 2007, 2009, 2010 Canonical Ltd
1
# Copyright (C) 2006 Canonical Ltd
2
2
# Authors: Robert Collins <robert.collins@canonical.com>
4
4
# This program is free software; you can redistribute it and/or modify
14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
from bzrlib import config, ignores
19
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
19
from bzrlib import config, ignores, osutils
20
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
22
23
class TestIsIgnored(TestCaseWithWorkingTree):
24
def _set_user_ignore_content(self, ignores):
25
"""Create user ignore file and set its content to ignores."""
26
config.ensure_config_dir_exists()
27
user_ignore_file = config.user_ignore_config_filename()
28
f = open(user_ignore_file, 'wb')
34
25
def test_is_ignored(self):
35
26
tree = self.make_branch_and_tree('.')
36
27
# this will break if a tree changes the ignored format. That is fine
40
31
('.bzrignore', './rootdir\n'
48
'RE:dir2/.*\.wombat\n'
52
39
'unicode\xc2\xb5\n' # u'\xb5'.encode('utf8')
56
43
' xx \n' # whitespace
58
# We set user ignore file to contain '' to avoid patterns from
59
# user ignore being used instead of bzrignore. For .e.g. If we
60
# don't do this 'foo.~1~' will match '*~' default user ignore
61
# pattern instead of '*.~*' from bzr ignore as we expect below.
62
self._set_user_ignore_content('')
63
45
# is_ignored returns the matching ignore regex when a path is ignored.
64
46
# we check some expected matches for each rule, and one or more
65
47
# relevant not-matches that look plausible as cases for bugs.
76
58
self.assertEqual("path/from/ro?t", tree.is_ignored('path/from/root'))
77
59
self.assertEqual("path/from/ro?t", tree.is_ignored('path/from/roat'))
78
60
self.assertEqual(None, tree.is_ignored('roat'))
80
self.assertEqual('**/piffle.py', tree.is_ignored('piffle.py'))
81
self.assertEqual('**/piffle.py', tree.is_ignored('a/piffle.py'))
82
self.assertEqual(None, tree.is_ignored('b/piffle.py')) # exclusion
83
self.assertEqual('**/piffle.py', tree.is_ignored('foo/bar/piffle.py'))
84
self.assertEqual(None, tree.is_ignored('p/iffle.py'))
86
62
self.assertEqual(u'unicode\xb5', tree.is_ignored(u'unicode\xb5'))
87
63
self.assertEqual(u'unicode\xb5', tree.is_ignored(u'subdir/unicode\xb5'))
96
72
self.assertEqual('*bar', tree.is_ignored(r'foo\nbar'))
97
73
self.assertEqual('*bar', tree.is_ignored('bar'))
98
74
self.assertEqual('*bar', tree.is_ignored('.bar'))
100
self.assertEqual(None, tree.is_ignored('bazbar')) # exclusion
102
76
self.assertEqual('?foo', tree.is_ignored('afoo'))
103
77
self.assertEqual('?foo', tree.is_ignored('.foo'))
111
85
self.assertEqual('dir1/?f2', tree.is_ignored('dir1/ff2'))
112
86
self.assertEqual('dir1/?f2', tree.is_ignored('dir1/.f2'))
114
self.assertEqual('RE:dir2/.*\.wombat', tree.is_ignored('dir2/foo.wombat'))
115
self.assertEqual(None, tree.is_ignored('dir2/foo'))
117
88
# Blank lines and comments should be ignored
118
89
self.assertEqual(None, tree.is_ignored(''))
134
105
config.ensure_config_dir_exists()
135
106
user_ignore_file = config.user_ignore_config_filename()
136
self._set_user_ignore_content(
141
'\r\n' #Blank dos line
142
' * \n' #Trailing and suffix spaces
143
'crlf\r\n' # dos style line
144
'*\xc3\xa5*\n' # u'\xe5'.encode('utf8')
107
f = open(user_ignore_file, 'wb')
113
'\r\n' #Blank dos line
114
' * \n' #Trailing and suffix spaces
115
'crlf\r\n' # dos style line
116
'*\xc3\xa5*\n' # u'\xe5'.encode('utf8')
148
122
self.assertEqual('./.shelf', tree.is_ignored('.shelf'))