~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/workingtree_implementations/test_is_ignored.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-07-19 21:44:16 UTC
  • mfrom: (1836.1.26 ignores)
  • Revision ID: pqm@pqm.ubuntu.com-20060719214416-9fab2f627df9f1aa
(jam) allow global user ignores, and include a small set by default

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
 
18
import bzrlib
 
19
from bzrlib import config, ignores, osutils
18
20
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
19
21
 
20
22
 
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'
 
32
                           'randomfile*\n'
 
33
                           'path/from/ro?t\n'
 
34
                           'unicode\xc2\xb5\n' # u'\xb5'.encode('utf8')
 
35
                           'dos\r\n'
 
36
                           '\n' # empty line
 
37
                           '#comment\n'
 
38
                           ' xx \n' # whitespace
 
39
            )])
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'))
 
46
 
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'))
 
52
 
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'))
 
56
 
 
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'))
 
62
 
 
63
        self.assertEqual('dos', tree.is_ignored('dos'))
 
64
        self.assertEqual(None, tree.is_ignored('dosfoo'))
 
65
 
 
66
        # Blank lines and comments should be ignored
 
67
        self.assertEqual(None, tree.is_ignored(''))
 
68
        self.assertEqual(None, tree.is_ignored('test/'))
 
69
 
 
70
        self.assertEqual(None, tree.is_ignored('#comment'))
 
71
 
 
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 '))
 
79
 
 
80
    def test_global_ignored(self):
 
81
        tree = self.make_branch_and_tree('.')
 
82
 
 
83
        config.ensure_config_dir_exists()
 
84
        user_ignore_file = config.user_ignore_config_filename()
 
85
        f = open(user_ignore_file, 'wb')
 
86
        try:
 
87
            f.write('*.py[co]\n'
 
88
                    './.shelf\n'
 
89
                    '# comment line\n'
 
90
                    '\n' #Blank line
 
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')
 
95
                    )
 
96
        finally:
 
97
            f.close()
 
98
 
 
99
        # Rooted
 
100
        self.assertEqual('./.shelf', tree.is_ignored('.shelf'))
 
101
        self.assertEqual(None, tree.is_ignored('foo/.shelf'))
 
102
 
 
103
        # Glob style
 
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'))
 
107
 
 
108
        # Glob in subdir
 
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'))
 
112
 
 
113
        # Unicode
 
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'))
 
119
 
 
120
        # Whitespace
 
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'))
 
125
 
 
126
        # Dos lines
 
127
        self.assertEqual('crlf', tree.is_ignored('crlf'))
 
128
        self.assertEqual('crlf', tree.is_ignored('subdir/crlf'))
 
129
 
 
130
        # Comment line should be ignored
 
131
        self.assertEqual(None, tree.is_ignored('# comment line'))
 
132
 
 
133
        # Blank line should also be ignored
 
134
        self.assertEqual(None, tree.is_ignored(''))
 
135
        self.assertEqual(None, tree.is_ignored('baz/'))
 
136
 
 
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')])
 
141
 
 
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'))
 
147
 
 
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.
 
153
 
 
154
        # No configured ignores
 
155
        self.build_tree_contents([('.bzrignore', '')])
 
156
        ignores.set_user_ignores([])
 
157
 
 
158
        self.assertEqual(None, tree.is_ignored('foo.pyc'))
 
159
 
 
160
        # Must reset the list so that it reads a new one
 
161
        tree._ignorelist = None
 
162
 
 
163
        # use list.append() to get around the deprecation warnings
 
164
        list.append(bzrlib.DEFAULT_IGNORE, '*.py[co]')
 
165
        try:
 
166
            self.assertEqual('*.py[co]', tree.is_ignored('foo.pyc'))
 
167
        finally:
 
168
            list.remove(bzrlib.DEFAULT_IGNORE, '*.py[co]')