4763.2.4
by John Arbash Meinel
merge bzr.2.1 in preparation for NEWS entry. |
1 |
# Copyright (C) 2006-2010 Canonical Ltd
|
1765.1.2
by Robert Collins
Add missing test_ignore.py |
2 |
#
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
1765.1.2
by Robert Collins
Add missing test_ignore.py |
16 |
|
17 |
"""UI tests for bzr ignore."""
|
|
18 |
||
19 |
||
20 |
from cStringIO import StringIO |
|
21 |
import os |
|
22 |
import re |
|
23 |
import sys |
|
24 |
||
1996.3.18
by John Arbash Meinel
Now that mkdtemp and rmtree are lazy, they should not be directly improted. |
25 |
from bzrlib import ( |
26 |
ignores, |
|
27 |
osutils, |
|
28 |
)
|
|
1765.1.2
by Robert Collins
Add missing test_ignore.py |
29 |
import bzrlib |
30 |
from bzrlib.branch import Branch |
|
31 |
import bzrlib.bzrdir as bzrdir |
|
32 |
from bzrlib.errors import BzrCommandError |
|
33 |
from bzrlib.osutils import ( |
|
34 |
pathjoin, |
|
35 |
)
|
|
36 |
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer |
|
5283.4.5
by Martin Pool
Update remaining subclasses of ExternalBase |
37 |
from bzrlib.tests import TestCaseWithTransport |
1765.1.2
by Robert Collins
Add missing test_ignore.py |
38 |
from bzrlib.workingtree import WorkingTree |
39 |
||
40 |
||
5283.4.5
by Martin Pool
Update remaining subclasses of ExternalBase |
41 |
class TestCommands(TestCaseWithTransport): |
1765.1.2
by Robert Collins
Add missing test_ignore.py |
42 |
|
2104.1.2
by John Arbash Meinel
(Kent Gibson) Fix bug #4559, strip trailing slashes from ignore patterns |
43 |
def test_ignore_absolutes(self): |
44 |
"""'ignore' with an absolute path returns an error"""
|
|
2795.2.1
by Daniel Watkins
Updated tests in tests.blackbox.test_ignore to use bzr internals where appropriate. |
45 |
self.make_branch_and_tree('.') |
2104.1.2
by John Arbash Meinel
(Kent Gibson) Fix bug #4559, strip trailing slashes from ignore patterns |
46 |
self.run_bzr_error(('bzr: ERROR: NAME_PATTERN should not ' |
47 |
'be an absolute path\n',), |
|
2552.2.3
by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests. |
48 |
'ignore /crud') |
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
49 |
|
2104.1.2
by John Arbash Meinel
(Kent Gibson) Fix bug #4559, strip trailing slashes from ignore patterns |
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 |
"""
|
|
2530.3.1
by Martin Pool
Cleanup old variations on run_bzr in the test suite |
55 |
self.run_bzr('init') |
2104.1.2
by John Arbash Meinel
(Kent Gibson) Fix bug #4559, strip trailing slashes from ignore patterns |
56 |
self.build_tree(['dir1/', 'dir1/foo', |
57 |
'dir2/', 'dir2/bar', |
|
58 |
'dir3/', 'dir3/baz']) |
|
2530.3.4
by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr |
59 |
self.run_bzr(['ignore', 'dir1', 'dir2/', 'dir4\\']) |
2298.8.3
by Kent Gibson
Extended test cases to test bug 86451. |
60 |
self.check_file_contents('.bzrignore', 'dir1\ndir2\ndir4\n') |
2530.3.1
by Martin Pool
Cleanup old variations on run_bzr in the test suite |
61 |
self.assertEquals(self.run_bzr('unknowns')[0], 'dir3\n') |
2104.1.2
by John Arbash Meinel
(Kent Gibson) Fix bug #4559, strip trailing slashes from ignore patterns |
62 |
|
1765.1.2
by Robert Collins
Add missing test_ignore.py |
63 |
def test_ignore_patterns(self): |
2795.2.1
by Daniel Watkins
Updated tests in tests.blackbox.test_ignore to use bzr internals where appropriate. |
64 |
tree = self.make_branch_and_tree('.') |
65 |
||
66 |
self.assertEquals(list(tree.unknowns()), []) |
|
1765.1.2
by Robert Collins
Add missing test_ignore.py |
67 |
|
1836.1.15
by John Arbash Meinel
Updated WorkingTree to use the new user-level ignores. |
68 |
# is_ignored() will now create the user global ignore file
|
69 |
# if it doesn't exist, so make sure we ignore it in our tests
|
|
1987.1.2
by John Arbash Meinel
Remove the unneeded _set_user_ignores(['./.bazaar']) now that home has moved |
70 |
ignores._set_user_ignores(['*.tmp']) |
1836.1.15
by John Arbash Meinel
Updated WorkingTree to use the new user-level ignores. |
71 |
|
1765.1.2
by Robert Collins
Add missing test_ignore.py |
72 |
self.build_tree_contents( |
2795.2.1
by Daniel Watkins
Updated tests in tests.blackbox.test_ignore to use bzr internals where appropriate. |
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()), []) |
|
1765.1.2
by Robert Collins
Add missing test_ignore.py |
81 |
|
82 |
# 'ignore' works when creating the .bzrignore file
|
|
2795.2.1
by Daniel Watkins
Updated tests in tests.blackbox.test_ignore to use bzr internals where appropriate. |
83 |
self.build_tree_contents([('foo.blah', 'blah')]) |
84 |
self.assertEquals(list(tree.unknowns()), ['foo.blah']) |
|
2530.3.1
by Martin Pool
Cleanup old variations on run_bzr in the test suite |
85 |
self.run_bzr('ignore *.blah') |
2795.2.1
by Daniel Watkins
Updated tests in tests.blackbox.test_ignore to use bzr internals where appropriate. |
86 |
self.assertEquals(list(tree.unknowns()), []) |
2063.5.4
by wang
Copy Kent Gibson's changes that incorporates John Arbash Meinel's |
87 |
self.check_file_contents('.bzrignore', '*.blah\n') |
1765.1.2
by Robert Collins
Add missing test_ignore.py |
88 |
|
89 |
# 'ignore' works when then .bzrignore file already exists
|
|
2795.2.1
by Daniel Watkins
Updated tests in tests.blackbox.test_ignore to use bzr internals where appropriate. |
90 |
self.build_tree_contents([('garh', 'garh')]) |
91 |
self.assertEquals(list(tree.unknowns()), ['garh']) |
|
2530.3.1
by Martin Pool
Cleanup old variations on run_bzr in the test suite |
92 |
self.run_bzr('ignore garh') |
2795.2.1
by Daniel Watkins
Updated tests in tests.blackbox.test_ignore to use bzr internals where appropriate. |
93 |
self.assertEquals(list(tree.unknowns()), []) |
2063.5.4
by wang
Copy Kent Gibson's changes that incorporates John Arbash Meinel's |
94 |
self.check_file_contents('.bzrignore', '*.blah\ngarh\n') |
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
95 |
|
2104.1.2
by John Arbash Meinel
(Kent Gibson) Fix bug #4559, strip trailing slashes from ignore patterns |
96 |
def test_ignore_multiple_arguments(self): |
2063.5.4
by wang
Copy Kent Gibson's changes that incorporates John Arbash Meinel's |
97 |
"""'ignore' works with multiple arguments"""
|
2795.2.1
by Daniel Watkins
Updated tests in tests.blackbox.test_ignore to use bzr internals where appropriate. |
98 |
tree = self.make_branch_and_tree('.') |
2063.5.4
by wang
Copy Kent Gibson's changes that incorporates John Arbash Meinel's |
99 |
self.build_tree(['a','b','c','d']) |
2795.2.1
by Daniel Watkins
Updated tests in tests.blackbox.test_ignore to use bzr internals where appropriate. |
100 |
self.assertEquals(list(tree.unknowns()), ['a', 'b', 'c', 'd']) |
2530.3.1
by Martin Pool
Cleanup old variations on run_bzr in the test suite |
101 |
self.run_bzr('ignore a b c') |
2795.2.1
by Daniel Watkins
Updated tests in tests.blackbox.test_ignore to use bzr internals where appropriate. |
102 |
self.assertEquals(list(tree.unknowns()), ['d']) |
2063.5.4
by wang
Copy Kent Gibson's changes that incorporates John Arbash Meinel's |
103 |
self.check_file_contents('.bzrignore', 'a\nb\nc\n') |
2077.1.2
by Kent Gibson
Strip trailing slashes from ignore patterns (#4559). |
104 |
|
105 |
def test_ignore_no_arguments(self): |
|
106 |
"""'ignore' with no arguments returns an error"""
|
|
2795.2.1
by Daniel Watkins
Updated tests in tests.blackbox.test_ignore to use bzr internals where appropriate. |
107 |
self.make_branch_and_tree('.') |
2077.1.2
by Kent Gibson
Strip trailing slashes from ignore patterns (#4559). |
108 |
self.run_bzr_error(('bzr: ERROR: ignore requires at least one ' |
5168.3.3
by Parth Malwankar
Removed --old-default-rules flag. |
109 |
'NAME_PATTERN or --default-rules.\n',), |
2077.1.2
by Kent Gibson
Strip trailing slashes from ignore patterns (#4559). |
110 |
'ignore') |
111 |
||
5168.3.1
by Parth Malwankar
bzr ignore now support --default-rules option |
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) |
|
117 |
self.assertEqual('', err) |
|
118 |
||
2747.5.2
by Daniel Watkins
Added tests for new functionality. |
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') |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
126 |
self.assertEqual(out, |
2747.5.2
by Daniel Watkins
Added tests for new functionality. |
127 |
"Warning: the following files are version controlled"\
|
4098.6.1
by Neil Martinsen-Burrell
Use a more informative message when an ignore pattern matches existing version controlled files. Fixes #248895 |
128 |
" and match your ignore pattern:\na\n"\ |
129 |
"These files will continue to be version controlled"\
|
|
130 |
" unless you 'bzr remove' them.\n") |
|
2747.5.2
by Daniel Watkins
Added tests for new functionality. |
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 *') |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
139 |
self.assertEqual(out, |
2747.5.2
by Daniel Watkins
Added tests for new functionality. |
140 |
"Warning: the following files are version controlled"\
|
4098.6.1
by Neil Martinsen-Burrell
Use a more informative message when an ignore pattern matches existing version controlled files. Fixes #248895 |
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") |
|
2747.5.4
by Daniel Watkins
Added test showing that the warning lists only files matching the new glob, as per abentley's request. |
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') |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
154 |
self.assertEqual(out, |
2747.5.4
by Daniel Watkins
Added test showing that the warning lists only files matching the new glob, as per abentley's request. |
155 |
"Warning: the following files are version controlled"\
|
4098.6.1
by Neil Martinsen-Burrell
Use a more informative message when an ignore pattern matches existing version controlled files. Fixes #248895 |
156 |
" and match your ignore pattern:\nb\n"\ |
157 |
"These files will continue to be version controlled"\
|
|
158 |
" unless you 'bzr remove' them.\n") |
|
5171.3.7
by Martin von Gagern
Added blackbox tests for --directory option. |
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') |
|
5339.3.4
by Parth Malwankar
cleanup of globster code. |
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 |