~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Alexander Belchenko
  • Date: 2006-07-30 16:43:12 UTC
  • mto: (1711.2.111 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1906.
  • Revision ID: bialix@ukr.net-20060730164312-b025fd3ff0cee59e
rename  gpl.txt => COPYING.txt

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 by 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
 
22
22
import re
23
23
import sys
24
24
 
25
 
from bzrlib import (
26
 
    ignores,
27
 
    osutils,
28
 
    )
 
25
from bzrlib import ignores
29
26
import bzrlib
30
27
from bzrlib.branch import Branch
31
28
import bzrlib.bzrdir as bzrdir
32
29
from bzrlib.errors import BzrCommandError
33
30
from bzrlib.osutils import (
 
31
    has_symlinks,
34
32
    pathjoin,
 
33
    rmtree,
 
34
    terminal_width,
35
35
    )
 
36
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
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
 
 
43
 
    def test_ignore_absolutes(self):
44
 
        """'ignore' with an absolute path returns an error"""
45
 
        self.make_branch_and_tree('.')
46
 
        self.run_bzr_error(('bzr: ERROR: NAME_PATTERN should not '
47
 
                            'be an absolute path\n',),
48
 
                           'ignore /crud')
49
 
 
50
 
    def test_ignore_directories(self):
51
 
        """ignoring a directory should ignore directory tree.
52
 
 
53
 
        Also check that trailing slashes on directories are stripped.
54
 
        """
55
 
        self.run_bzr('init')
56
 
        self.build_tree(['dir1/', 'dir1/foo',
57
 
                         'dir2/', 'dir2/bar',
58
 
                         'dir3/', 'dir3/baz'])
59
 
        self.run_bzr(['ignore', 'dir1', 'dir2/', 'dir4\\'])
60
 
        self.check_file_contents('.bzrignore', 'dir1\ndir2\ndir4\n')
61
 
        self.assertEquals(self.run_bzr('unknowns')[0], 'dir3\n')
 
42
class TestCommands(ExternalBase):
62
43
 
63
44
    def test_ignore_patterns(self):
64
 
        tree = self.make_branch_and_tree('.')
65
 
 
66
 
        self.assertEquals(list(tree.unknowns()), [])
 
45
        self.runbzr('init')
 
46
        self.assertEquals(self.capture('unknowns'), '')
67
47
 
68
48
        # is_ignored() will now create the user global ignore file
69
49
        # if it doesn't exist, so make sure we ignore it in our tests
70
 
        ignores._set_user_ignores(['*.tmp'])
 
50
        ignores._set_user_ignores(['*.tmp', './.bazaar'])
71
51
 
72
52
        self.build_tree_contents(
73
 
            [('foo.tmp', '.tmp files are ignored by default')])
74
 
        self.assertEquals(list(tree.unknowns()), [])
75
 
 
76
 
        self.build_tree_contents([('foo.c', 'int main() {}')])
77
 
        self.assertEquals(list(tree.unknowns()), ['foo.c'])
78
 
 
79
 
        tree.add('foo.c')
80
 
        self.assertEquals(list(tree.unknowns()), [])
 
53
            [('foo.tmp', '.tmp files are ignored by default'),
 
54
             ])
 
55
        self.assertEquals(self.capture('unknowns'), '')
 
56
 
 
57
        file('foo.c', 'wt').write('int main() {}')
 
58
        self.assertEquals(self.capture('unknowns'), 'foo.c\n')
 
59
 
 
60
        self.runbzr(['add', 'foo.c'])
 
61
        self.assertEquals(self.capture('unknowns'), '')
81
62
 
82
63
        # 'ignore' works when creating the .bzrignore file
83
 
        self.build_tree_contents([('foo.blah', 'blah')])
84
 
        self.assertEquals(list(tree.unknowns()), ['foo.blah'])
85
 
        self.run_bzr('ignore *.blah')
86
 
        self.assertEquals(list(tree.unknowns()), [])
87
 
        self.check_file_contents('.bzrignore', '*.blah\n')
 
64
        file('foo.blah', 'wt').write('blah')
 
65
        self.assertEquals(self.capture('unknowns'), 'foo.blah\n')
 
66
        self.runbzr('ignore *.blah')
 
67
        self.assertEquals(self.capture('unknowns'), '')
 
68
        self.assertEquals('*.blah\n', open('.bzrignore', 'rU').read())
88
69
 
89
70
        # 'ignore' works when then .bzrignore file already exists
90
 
        self.build_tree_contents([('garh', 'garh')])
91
 
        self.assertEquals(list(tree.unknowns()), ['garh'])
92
 
        self.run_bzr('ignore garh')
93
 
        self.assertEquals(list(tree.unknowns()), [])
94
 
        self.check_file_contents('.bzrignore', '*.blah\ngarh\n')
95
 
 
96
 
    def test_ignore_multiple_arguments(self):
97
 
        """'ignore' works with multiple arguments"""
98
 
        tree = self.make_branch_and_tree('.')
99
 
        self.build_tree(['a','b','c','d'])
100
 
        self.assertEquals(list(tree.unknowns()), ['a', 'b', 'c', 'd'])
101
 
        self.run_bzr('ignore a b c')
102
 
        self.assertEquals(list(tree.unknowns()), ['d'])
103
 
        self.check_file_contents('.bzrignore', 'a\nb\nc\n')
104
 
 
105
 
    def test_ignore_no_arguments(self):
106
 
        """'ignore' with no arguments returns an error"""
107
 
        self.make_branch_and_tree('.')
108
 
        self.run_bzr_error(('bzr: ERROR: ignore requires at least one '
109
 
                            'NAME_PATTERN or --default-rules.\n',),
110
 
                           'ignore')
111
 
 
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)
 
71
        file('garh', 'wt').write('garh')
 
72
        self.assertEquals(self.capture('unknowns'), 'garh\n')
 
73
        self.runbzr('ignore garh')
 
74
        self.assertEquals(self.capture('unknowns'), '')
 
75
        self.assertEquals(file('.bzrignore', 'rU').read(), '*.blah\ngarh\n')
 
76
        
 
77
    def test_ignore_old_defaults(self):
 
78
        out, err = self.run_bzr('ignore', '--old-default-rules')
 
79
        self.assertContainsRe(out, 'CVS')
117
80
        self.assertEqual('', err)
118
 
 
119
 
    def test_ignore_versioned_file(self):
120
 
        tree = self.make_branch_and_tree('.')
121
 
        self.build_tree(['a','b'])
122
 
        tree.add('a')
123
 
 
124
 
        # test a single versioned file
125
 
        out, err = self.run_bzr('ignore a')
126
 
        self.assertEqual(out,
127
 
                         "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")
131
 
 
132
 
        # test a single unversioned file
133
 
        out, err = self.run_bzr('ignore b')
134
 
        self.assertEqual(out, '')
135
 
 
136
 
        # test wildcards
137
 
        tree.add('b')
138
 
        out, err = self.run_bzr('ignore *')
139
 
        self.assertEqual(out,
140
 
                         "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")
144
 
 
145
 
    def test_ignored_versioned_file_matching_new_pattern(self):
146
 
        tree = self.make_branch_and_tree('.')
147
 
        self.build_tree(['a', 'b'])
148
 
        tree.add(['a', 'b'])
149
 
        self.run_bzr('ignore *')
150
 
 
151
 
        # If only the given pattern is used then only 'b' should match in
152
 
        # this case.
153
 
        out, err = self.run_bzr('ignore b')
154
 
        self.assertEqual(out,
155
 
                         "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