~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_ignore.py

  • Committer: John Arbash Meinel
  • Author(s): Mark Hammond
  • Date: 2008-09-09 17:02:21 UTC
  • mto: This revision was merged to the branch mainline in revision 3697.
  • Revision ID: john@arbash-meinel.com-20080909170221-svim3jw2mrz0amp3
An updated transparent icon for bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010, 2016 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""UI tests for bzr ignore."""
18
18
 
32
32
from bzrlib.errors import BzrCommandError
33
33
from bzrlib.osutils import (
34
34
    pathjoin,
 
35
    terminal_width,
35
36
    )
36
37
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
37
 
from bzrlib.tests import TestCaseWithTransport
 
38
from bzrlib.tests.blackbox import ExternalBase
38
39
from bzrlib.workingtree import WorkingTree
39
40
 
40
41
 
41
 
class TestCommands(TestCaseWithTransport):
 
42
class TestCommands(ExternalBase):
42
43
 
43
44
    def test_ignore_absolutes(self):
44
45
        """'ignore' with an absolute path returns an error"""
46
47
        self.run_bzr_error(('bzr: ERROR: NAME_PATTERN should not '
47
48
                            'be an absolute path\n',),
48
49
                           'ignore /crud')
49
 
 
 
50
        
50
51
    def test_ignore_directories(self):
51
52
        """ignoring a directory should ignore directory tree.
52
53
 
58
59
                         'dir3/', 'dir3/baz'])
59
60
        self.run_bzr(['ignore', 'dir1', 'dir2/', 'dir4\\'])
60
61
        self.check_file_contents('.bzrignore', 'dir1\ndir2\ndir4\n')
61
 
        self.assertEqual(self.run_bzr('unknowns')[0], 'dir3\n')
 
62
        self.assertEquals(self.run_bzr('unknowns')[0], 'dir3\n')
62
63
 
63
64
    def test_ignore_patterns(self):
64
65
        tree = self.make_branch_and_tree('.')
65
66
 
66
 
        self.assertEqual(list(tree.unknowns()), [])
 
67
        self.assertEquals(list(tree.unknowns()), [])
67
68
 
68
69
        # is_ignored() will now create the user global ignore file
69
70
        # if it doesn't exist, so make sure we ignore it in our tests
71
72
 
72
73
        self.build_tree_contents(
73
74
            [('foo.tmp', '.tmp files are ignored by default')])
74
 
        self.assertEqual(list(tree.unknowns()), [])
 
75
        self.assertEquals(list(tree.unknowns()), [])
75
76
 
76
77
        self.build_tree_contents([('foo.c', 'int main() {}')])
77
 
        self.assertEqual(list(tree.unknowns()), ['foo.c'])
 
78
        self.assertEquals(list(tree.unknowns()), ['foo.c'])
78
79
 
79
80
        tree.add('foo.c')
80
 
        self.assertEqual(list(tree.unknowns()), [])
 
81
        self.assertEquals(list(tree.unknowns()), [])
81
82
 
82
83
        # 'ignore' works when creating the .bzrignore file
83
84
        self.build_tree_contents([('foo.blah', 'blah')])
84
 
        self.assertEqual(list(tree.unknowns()), ['foo.blah'])
 
85
        self.assertEquals(list(tree.unknowns()), ['foo.blah'])
85
86
        self.run_bzr('ignore *.blah')
86
 
        self.assertEqual(list(tree.unknowns()), [])
 
87
        self.assertEquals(list(tree.unknowns()), [])
87
88
        self.check_file_contents('.bzrignore', '*.blah\n')
88
89
 
89
90
        # 'ignore' works when then .bzrignore file already exists
90
91
        self.build_tree_contents([('garh', 'garh')])
91
 
        self.assertEqual(list(tree.unknowns()), ['garh'])
 
92
        self.assertEquals(list(tree.unknowns()), ['garh'])
92
93
        self.run_bzr('ignore garh')
93
 
        self.assertEqual(list(tree.unknowns()), [])
 
94
        self.assertEquals(list(tree.unknowns()), [])
94
95
        self.check_file_contents('.bzrignore', '*.blah\ngarh\n')
95
 
 
 
96
       
96
97
    def test_ignore_multiple_arguments(self):
97
98
        """'ignore' works with multiple arguments"""
98
99
        tree = self.make_branch_and_tree('.')
99
100
        self.build_tree(['a','b','c','d'])
100
 
        self.assertEqual(list(tree.unknowns()), ['a', 'b', 'c', 'd'])
 
101
        self.assertEquals(list(tree.unknowns()), ['a', 'b', 'c', 'd'])
101
102
        self.run_bzr('ignore a b c')
102
 
        self.assertEqual(list(tree.unknowns()), ['d'])
 
103
        self.assertEquals(list(tree.unknowns()), ['d'])
103
104
        self.check_file_contents('.bzrignore', 'a\nb\nc\n')
104
105
 
105
106
    def test_ignore_no_arguments(self):
106
107
        """'ignore' with no arguments returns an error"""
107
108
        self.make_branch_and_tree('.')
108
109
        self.run_bzr_error(('bzr: ERROR: ignore requires at least one '
109
 
                            'NAME_PATTERN or --default-rules.\n',),
 
110
                            'NAME_PATTERN or --old-default-rules\n',),
110
111
                           'ignore')
111
112
 
112
 
    def test_ignore_default_rules(self):
113
 
        out, err = self.run_bzr(['ignore', '--default-rules'])
114
 
        reference_set = set(ignores.USER_DEFAULTS)
115
 
        output_set = set(out.rstrip().split('\n'))
116
 
        self.assertEqual(reference_set, output_set)
 
113
    def test_ignore_old_defaults(self):
 
114
        out, err = self.run_bzr('ignore --old-default-rules')
 
115
        self.assertContainsRe(out, 'CVS')
117
116
        self.assertEqual('', err)
118
117
 
119
118
    def test_ignore_versioned_file(self):
123
122
 
124
123
        # test a single versioned file
125
124
        out, err = self.run_bzr('ignore a')
126
 
        self.assertEqual(out,
 
125
        self.assertEqual(out, 
127
126
                         "Warning: the following files are version controlled"\
128
 
                         " and match your ignore pattern:\na\n"\
129
 
                         "These files will continue to be version controlled"\
130
 
                         " unless you 'bzr remove' them.\n")
 
127
                         " and match your ignore pattern:\na\n")
131
128
 
132
129
        # test a single unversioned file
133
130
        out, err = self.run_bzr('ignore b')
136
133
        # test wildcards
137
134
        tree.add('b')
138
135
        out, err = self.run_bzr('ignore *')
139
 
        self.assertEqual(out,
 
136
        self.assertEqual(out, 
140
137
                         "Warning: the following files are version controlled"\
141
 
                         " and match your ignore pattern:\n.bzrignore\na\nb\n"\
142
 
                         "These files will continue to be version controlled"\
143
 
                         " unless you 'bzr remove' them.\n")
 
138
                         " and match your ignore pattern:\n.bzrignore\na\nb\n")
144
139
 
145
140
    def test_ignored_versioned_file_matching_new_pattern(self):
146
141
        tree = self.make_branch_and_tree('.')
151
146
        # If only the given pattern is used then only 'b' should match in
152
147
        # this case.
153
148
        out, err = self.run_bzr('ignore b')
154
 
        self.assertEqual(out,
 
149
        self.assertEqual(out, 
155
150
                         "Warning: the following files are version controlled"\
156
 
                         " and match your ignore pattern:\nb\n"\
157
 
                         "These files will continue to be version controlled"\
158
 
                         " unless you 'bzr remove' them.\n")
159
 
 
160
 
    def test_ignore_directory(self):
161
 
        """Test --directory option"""
162
 
        tree = self.make_branch_and_tree('a')
163
 
        self.run_bzr(['ignore', '--directory=a', 'README'])
164
 
        self.check_file_contents('a/.bzrignore', 'README\n')
165
 
 
166
 
    def test_ignored_invalid_pattern(self):
167
 
        """Ensure graceful handling for invalid ignore pattern.
168
 
 
169
 
        Test case for #300062.
170
 
        Invalid pattern should show clear error message.
171
 
        Invalid pattern should not be added to .bzrignore file.
172
 
        """
173
 
        tree = self.make_branch_and_tree('.')
174
 
        out, err = self.run_bzr(['ignore', 'RE:*.cpp', 'foo', 'RE:['], 3)
175
 
        self.assertEqual(out, '')
176
 
        self.assertContainsRe(err,
177
 
            'Invalid ignore pattern.*RE:\*\.cpp.*RE:\[', re.DOTALL)
178
 
        self.assertNotContainsRe(err, 'foo', re.DOTALL)
179
 
        self.assertFalse(os.path.isfile('.bzrignore'))
180
 
 
 
151
                         " and match your ignore pattern:\nb\n")