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 |
has_symlinks, |
|
35 |
pathjoin, |
|
36 |
terminal_width, |
|
37 |
)
|
|
38 |
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver |
|
39 |
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer |
|
40 |
from bzrlib.tests.blackbox import ExternalBase |
|
41 |
from bzrlib.workingtree import WorkingTree |
|
42 |
||
43 |
||
44 |
class TestCommands(ExternalBase): |
|
45 |
||
2104.1.2
by John Arbash Meinel
(Kent Gibson) Fix bug #4559, strip trailing slashes from ignore patterns |
46 |
def test_ignore_absolutes(self): |
47 |
"""'ignore' with an absolute path returns an error"""
|
|
48 |
self.runbzr('init') |
|
49 |
self.run_bzr_error(('bzr: ERROR: NAME_PATTERN should not ' |
|
50 |
'be an absolute path\n',), |
|
51 |
'ignore','/crud') |
|
52 |
||
53 |
def test_ignore_directories(self): |
|
54 |
"""ignoring a directory should ignore directory tree.
|
|
55 |
||
56 |
Also check that trailing slashes on directories are stripped.
|
|
57 |
"""
|
|
58 |
self.runbzr('init') |
|
59 |
self.build_tree(['dir1/', 'dir1/foo', |
|
60 |
'dir2/', 'dir2/bar', |
|
61 |
'dir3/', 'dir3/baz']) |
|
62 |
self.runbzr('ignore dir1 dir2/') |
|
63 |
self.check_file_contents('.bzrignore', 'dir1\ndir2\n') |
|
64 |
self.assertEquals(self.capture('unknowns'), 'dir3\n') |
|
65 |
||
1765.1.2
by Robert Collins
Add missing test_ignore.py |
66 |
def test_ignore_patterns(self): |
67 |
self.runbzr('init') |
|
68 |
self.assertEquals(self.capture('unknowns'), '') |
|
69 |
||
1836.1.15
by John Arbash Meinel
Updated WorkingTree to use the new user-level ignores. |
70 |
# is_ignored() will now create the user global ignore file
|
71 |
# 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 |
72 |
ignores._set_user_ignores(['*.tmp']) |
1836.1.15
by John Arbash Meinel
Updated WorkingTree to use the new user-level ignores. |
73 |
|
1765.1.2
by Robert Collins
Add missing test_ignore.py |
74 |
self.build_tree_contents( |
1836.1.15
by John Arbash Meinel
Updated WorkingTree to use the new user-level ignores. |
75 |
[('foo.tmp', '.tmp files are ignored by default'), |
1765.1.2
by Robert Collins
Add missing test_ignore.py |
76 |
])
|
77 |
self.assertEquals(self.capture('unknowns'), '') |
|
78 |
||
79 |
file('foo.c', 'wt').write('int main() {}') |
|
80 |
self.assertEquals(self.capture('unknowns'), 'foo.c\n') |
|
81 |
||
82 |
self.runbzr(['add', 'foo.c']) |
|
83 |
self.assertEquals(self.capture('unknowns'), '') |
|
84 |
||
85 |
# 'ignore' works when creating the .bzrignore file
|
|
86 |
file('foo.blah', 'wt').write('blah') |
|
87 |
self.assertEquals(self.capture('unknowns'), 'foo.blah\n') |
|
88 |
self.runbzr('ignore *.blah') |
|
89 |
self.assertEquals(self.capture('unknowns'), '') |
|
2063.5.4
by wang
Copy Kent Gibson's changes that incorporates John Arbash Meinel's |
90 |
self.check_file_contents('.bzrignore', '*.blah\n') |
1765.1.2
by Robert Collins
Add missing test_ignore.py |
91 |
|
92 |
# 'ignore' works when then .bzrignore file already exists
|
|
93 |
file('garh', 'wt').write('garh') |
|
94 |
self.assertEquals(self.capture('unknowns'), 'garh\n') |
|
95 |
self.runbzr('ignore garh') |
|
96 |
self.assertEquals(self.capture('unknowns'), '') |
|
2063.5.4
by wang
Copy Kent Gibson's changes that incorporates John Arbash Meinel's |
97 |
self.check_file_contents('.bzrignore', '*.blah\ngarh\n') |
98 |
||
2104.1.2
by John Arbash Meinel
(Kent Gibson) Fix bug #4559, strip trailing slashes from ignore patterns |
99 |
def test_ignore_multiple_arguments(self): |
2063.5.4
by wang
Copy Kent Gibson's changes that incorporates John Arbash Meinel's |
100 |
"""'ignore' works with multiple arguments"""
|
101 |
self.runbzr('init') |
|
102 |
self.build_tree(['a','b','c','d']) |
|
103 |
self.assertEquals(self.capture('unknowns'), 'a\nb\nc\nd\n') |
|
2063.5.1
by wang
"bzr ignore" takes multiple arguments. Fixes bug 29488. |
104 |
self.runbzr('ignore a b c') |
2063.5.4
by wang
Copy Kent Gibson's changes that incorporates John Arbash Meinel's |
105 |
self.assertEquals(self.capture('unknowns'), 'd\n') |
106 |
self.check_file_contents('.bzrignore', 'a\nb\nc\n') |
|
2077.1.2
by Kent Gibson
Strip trailing slashes from ignore patterns (#4559). |
107 |
|
108 |
def test_ignore_no_arguments(self): |
|
109 |
"""'ignore' with no arguments returns an error"""
|
|
110 |
self.runbzr('init') |
|
111 |
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 |
112 |
'NAME_PATTERN or --old-default-rules\n',), |
2077.1.2
by Kent Gibson
Strip trailing slashes from ignore patterns (#4559). |
113 |
'ignore') |
114 |
||
1765.1.2
by Robert Collins
Add missing test_ignore.py |
115 |
def test_ignore_old_defaults(self): |
116 |
out, err = self.run_bzr('ignore', '--old-default-rules') |
|
117 |
self.assertContainsRe(out, 'CVS') |
|
118 |
self.assertEqual('', err) |
|
2077.1.2
by Kent Gibson
Strip trailing slashes from ignore patterns (#4559). |
119 |