1
# Copyright (C) 2005, 2006 by 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
25
from bzrlib import ignores
27
from bzrlib.branch import Branch
28
import bzrlib.bzrdir as bzrdir
29
from bzrlib.errors import BzrCommandError
30
from bzrlib.osutils import (
36
from bzrlib.tests.HTTPTestUtil import TestCaseWithWebserver
37
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
38
from bzrlib.tests.blackbox import ExternalBase
39
from bzrlib.workingtree import WorkingTree
42
class TestCommands(ExternalBase):
44
def test_ignore_patterns(self):
46
self.assertEquals(self.capture('unknowns'), '')
48
# is_ignored() will now create the user global ignore file
49
# if it doesn't exist, so make sure we ignore it in our tests
50
ignores._set_user_ignores(['*.tmp', './.bazaar'])
52
self.build_tree_contents(
53
[('foo.tmp', '.tmp files are ignored by default'),
55
self.assertEquals(self.capture('unknowns'), '')
57
file('foo.c', 'wt').write('int main() {}')
58
self.assertEquals(self.capture('unknowns'), 'foo.c\n')
60
self.runbzr(['add', 'foo.c'])
61
self.assertEquals(self.capture('unknowns'), '')
63
# 'ignore' works when creating the .bzrignore file
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())
70
# 'ignore' works when then .bzrignore file already exists
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')
77
def test_ignore_old_defaults(self):
78
out, err = self.run_bzr('ignore', '--old-default-rules')
79
self.assertContainsRe(out, 'CVS')
80
self.assertEqual('', err)