1
# Copyright (C) 2005, 2006 Canonical Ltd
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.
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.
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
17
"""UI tests for bzr ignore."""
20
from cStringIO import StringIO
30
from bzrlib.branch import Branch
31
import bzrlib.bzrdir as bzrdir
32
from bzrlib.errors import BzrCommandError
33
from bzrlib.osutils import (
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
44
class TestCommands(ExternalBase):
46
def test_ignore_absolutes(self):
47
"""'ignore' with an absolute path returns an error"""
49
self.run_bzr_error(('bzr: ERROR: NAME_PATTERN should not '
50
'be an absolute path\n',),
53
def test_ignore_directories(self):
54
"""ignoring a directory should ignore directory tree.
56
Also check that trailing slashes on directories are stripped.
59
self.build_tree(['dir1/', 'dir1/foo',
62
self.runbzr('ignore dir1 dir2/ dir4\\')
63
self.check_file_contents('.bzrignore', 'dir1\ndir2\ndir4\n')
64
self.assertEquals(self.capture('unknowns'), 'dir3\n')
66
def test_ignore_patterns(self):
68
self.assertEquals(self.capture('unknowns'), '')
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
72
ignores._set_user_ignores(['*.tmp'])
74
self.build_tree_contents(
75
[('foo.tmp', '.tmp files are ignored by default'),
77
self.assertEquals(self.capture('unknowns'), '')
79
file('foo.c', 'wt').write('int main() {}')
80
self.assertEquals(self.capture('unknowns'), 'foo.c\n')
82
self.runbzr(['add', 'foo.c'])
83
self.assertEquals(self.capture('unknowns'), '')
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'), '')
90
self.check_file_contents('.bzrignore', '*.blah\n')
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'), '')
97
self.check_file_contents('.bzrignore', '*.blah\ngarh\n')
99
def test_ignore_multiple_arguments(self):
100
"""'ignore' works with multiple arguments"""
102
self.build_tree(['a','b','c','d'])
103
self.assertEquals(self.capture('unknowns'), 'a\nb\nc\nd\n')
104
self.runbzr('ignore a b c')
105
self.assertEquals(self.capture('unknowns'), 'd\n')
106
self.check_file_contents('.bzrignore', 'a\nb\nc\n')
108
def test_ignore_no_arguments(self):
109
"""'ignore' with no arguments returns an error"""
111
self.run_bzr_error(('bzr: ERROR: ignore requires at least one '
112
'NAME_PATTERN or --old-default-rules\n',),
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)