2052.3.2
by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical |
1 |
# Copyright (C) 2005, 2006 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
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
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 |
terminal_width, |
|
36 |
)
|
|
37 |
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer |
|
38 |
from bzrlib.tests.blackbox import ExternalBase |
|
39 |
from bzrlib.workingtree import WorkingTree |
|
40 |
||
41 |
||
42 |
class TestCommands(ExternalBase): |
|
43 |
||
2104.1.2
by John Arbash Meinel
(Kent Gibson) Fix bug #4559, strip trailing slashes from ignore patterns |
44 |
def test_ignore_absolutes(self): |
45 |
"""'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. |
46 |
self.make_branch_and_tree('.') |
2104.1.2
by John Arbash Meinel
(Kent Gibson) Fix bug #4559, strip trailing slashes from ignore patterns |
47 |
self.run_bzr_error(('bzr: ERROR: NAME_PATTERN should not ' |
48 |
'be an absolute path\n',), |
|
2552.2.3
by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests. |
49 |
'ignore /crud') |
2104.1.2
by John Arbash Meinel
(Kent Gibson) Fix bug #4559, strip trailing slashes from ignore patterns |
50 |
|
51 |
def test_ignore_directories(self): |
|
52 |
"""ignoring a directory should ignore directory tree.
|
|
53 |
||
54 |
Also check that trailing slashes on directories are stripped.
|
|
55 |
"""
|
|
2530.3.1
by Martin Pool
Cleanup old variations on run_bzr in the test suite |
56 |
self.run_bzr('init') |
2104.1.2
by John Arbash Meinel
(Kent Gibson) Fix bug #4559, strip trailing slashes from ignore patterns |
57 |
self.build_tree(['dir1/', 'dir1/foo', |
58 |
'dir2/', 'dir2/bar', |
|
59 |
'dir3/', 'dir3/baz']) |
|
2530.3.4
by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr |
60 |
self.run_bzr(['ignore', 'dir1', 'dir2/', 'dir4\\']) |
2298.8.3
by Kent Gibson
Extended test cases to test bug 86451. |
61 |
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 |
62 |
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 |
63 |
|
1765.1.2
by Robert Collins
Add missing test_ignore.py |
64 |
def test_ignore_patterns(self): |
2795.2.1
by Daniel Watkins
Updated tests in tests.blackbox.test_ignore to use bzr internals where appropriate. |
65 |
tree = self.make_branch_and_tree('.') |
66 |
||
67 |
self.assertEquals(list(tree.unknowns()), []) |
|
1765.1.2
by Robert Collins
Add missing test_ignore.py |
68 |
|
1836.1.15
by John Arbash Meinel
Updated WorkingTree to use the new user-level ignores. |
69 |
# is_ignored() will now create the user global ignore file
|
70 |
# 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 |
71 |
ignores._set_user_ignores(['*.tmp']) |
1836.1.15
by John Arbash Meinel
Updated WorkingTree to use the new user-level ignores. |
72 |
|
1765.1.2
by Robert Collins
Add missing test_ignore.py |
73 |
self.build_tree_contents( |
2795.2.1
by Daniel Watkins
Updated tests in tests.blackbox.test_ignore to use bzr internals where appropriate. |
74 |
[('foo.tmp', '.tmp files are ignored by default')]) |
75 |
self.assertEquals(list(tree.unknowns()), []) |
|
76 |
||
77 |
self.build_tree_contents([('foo.c', 'int main() {}')]) |
|
78 |
self.assertEquals(list(tree.unknowns()), ['foo.c']) |
|
79 |
||
80 |
tree.add('foo.c') |
|
81 |
self.assertEquals(list(tree.unknowns()), []) |
|
1765.1.2
by Robert Collins
Add missing test_ignore.py |
82 |
|
83 |
# '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. |
84 |
self.build_tree_contents([('foo.blah', 'blah')]) |
85 |
self.assertEquals(list(tree.unknowns()), ['foo.blah']) |
|
2530.3.1
by Martin Pool
Cleanup old variations on run_bzr in the test suite |
86 |
self.run_bzr('ignore *.blah') |
2795.2.1
by Daniel Watkins
Updated tests in tests.blackbox.test_ignore to use bzr internals where appropriate. |
87 |
self.assertEquals(list(tree.unknowns()), []) |
2063.5.4
by wang
Copy Kent Gibson's changes that incorporates John Arbash Meinel's |
88 |
self.check_file_contents('.bzrignore', '*.blah\n') |
1765.1.2
by Robert Collins
Add missing test_ignore.py |
89 |
|
90 |
# '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. |
91 |
self.build_tree_contents([('garh', 'garh')]) |
92 |
self.assertEquals(list(tree.unknowns()), ['garh']) |
|
2530.3.1
by Martin Pool
Cleanup old variations on run_bzr in the test suite |
93 |
self.run_bzr('ignore garh') |
2795.2.1
by Daniel Watkins
Updated tests in tests.blackbox.test_ignore to use bzr internals where appropriate. |
94 |
self.assertEquals(list(tree.unknowns()), []) |
2063.5.4
by wang
Copy Kent Gibson's changes that incorporates John Arbash Meinel's |
95 |
self.check_file_contents('.bzrignore', '*.blah\ngarh\n') |
96 |
||
2104.1.2
by John Arbash Meinel
(Kent Gibson) Fix bug #4559, strip trailing slashes from ignore patterns |
97 |
def test_ignore_multiple_arguments(self): |
2063.5.4
by wang
Copy Kent Gibson's changes that incorporates John Arbash Meinel's |
98 |
"""'ignore' works with multiple arguments"""
|
2795.2.1
by Daniel Watkins
Updated tests in tests.blackbox.test_ignore to use bzr internals where appropriate. |
99 |
tree = self.make_branch_and_tree('.') |
2063.5.4
by wang
Copy Kent Gibson's changes that incorporates John Arbash Meinel's |
100 |
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. |
101 |
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 |
102 |
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. |
103 |
self.assertEquals(list(tree.unknowns()), ['d']) |
2063.5.4
by wang
Copy Kent Gibson's changes that incorporates John Arbash Meinel's |
104 |
self.check_file_contents('.bzrignore', 'a\nb\nc\n') |
2077.1.2
by Kent Gibson
Strip trailing slashes from ignore patterns (#4559). |
105 |
|
106 |
def test_ignore_no_arguments(self): |
|
107 |
"""'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. |
108 |
self.make_branch_and_tree('.') |
2077.1.2
by Kent Gibson
Strip trailing slashes from ignore patterns (#4559). |
109 |
self.run_bzr_error(('bzr: ERROR: ignore requires at least one ' |
2104.1.2
by John Arbash Meinel
(Kent Gibson) Fix bug #4559, strip trailing slashes from ignore patterns |
110 |
'NAME_PATTERN or --old-default-rules\n',), |
2077.1.2
by Kent Gibson
Strip trailing slashes from ignore patterns (#4559). |
111 |
'ignore') |
112 |
||
1765.1.2
by Robert Collins
Add missing test_ignore.py |
113 |
def test_ignore_old_defaults(self): |
2552.2.3
by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests. |
114 |
out, err = self.run_bzr('ignore --old-default-rules') |
1765.1.2
by Robert Collins
Add missing test_ignore.py |
115 |
self.assertContainsRe(out, 'CVS') |
116 |
self.assertEqual('', err) |
|
2077.1.2
by Kent Gibson
Strip trailing slashes from ignore patterns (#4559). |
117 |
|
2747.5.2
by Daniel Watkins
Added tests for new functionality. |
118 |
def test_ignore_versioned_file(self): |
119 |
tree = self.make_branch_and_tree('.') |
|
120 |
self.build_tree(['a','b']) |
|
121 |
tree.add('a') |
|
122 |
||
123 |
# test a single versioned file
|
|
124 |
out, err = self.run_bzr('ignore a') |
|
125 |
self.assertEqual(out, |
|
126 |
"Warning: the following files are version controlled"\
|
|
127 |
" and match your ignore pattern:\na\n") |
|
128 |
||
129 |
# test a single unversioned file
|
|
130 |
out, err = self.run_bzr('ignore b') |
|
131 |
self.assertEqual(out, '') |
|
132 |
||
133 |
# test wildcards
|
|
134 |
tree.add('b') |
|
135 |
out, err = self.run_bzr('ignore *') |
|
136 |
self.assertEqual(out, |
|
137 |
"Warning: the following files are version controlled"\
|
|
138 |
" and match your ignore pattern:\n.bzrignore\na\nb\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. |
139 |
|
140 |
def test_ignored_versioned_file_matching_new_pattern(self): |
|
141 |
tree = self.make_branch_and_tree('.') |
|
142 |
self.build_tree(['a', 'b']) |
|
143 |
tree.add(['a', 'b']) |
|
144 |
self.run_bzr('ignore *') |
|
145 |
||
146 |
# If only the given pattern is used then only 'b' should match in
|
|
147 |
# this case.
|
|
148 |
out, err = self.run_bzr('ignore b') |
|
149 |
self.assertEqual(out, |
|
150 |
"Warning: the following files are version controlled"\
|
|
151 |
" and match your ignore pattern:\nb\n") |