42
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.run_bzr(['ignore', 'dir1', 'dir2/', 'dir4\\'])
63
self.check_file_contents('.bzrignore', 'dir1\ndir2\ndir4\n')
64
self.assertEquals(self.run_bzr('unknowns')[0], 'dir3\n')
44
66
def test_ignore_patterns(self):
46
self.assertEquals(self.capture('unknowns'), '')
68
self.assertEquals(self.run_bzr(['unknowns'])[0], '')
48
70
# is_ignored() will now create the user global ignore file
49
71
# if it doesn't exist, so make sure we ignore it in our tests
52
74
self.build_tree_contents(
53
75
[('foo.tmp', '.tmp files are ignored by default'),
55
self.assertEquals(self.capture('unknowns'), '')
77
self.assertEquals(self.run_bzr(['unknowns'])[0], '')
57
79
file('foo.c', 'wt').write('int main() {}')
58
self.assertEquals(self.capture('unknowns'), 'foo.c\n')
80
self.assertEquals(self.run_bzr(['unknowns'])[0], 'foo.c\n')
60
self.runbzr(['add', 'foo.c'])
61
self.assertEquals(self.capture('unknowns'), '')
82
self.run_bzr('add foo.c')
83
self.assertEquals(self.run_bzr(['unknowns'])[0], '')
63
85
# 'ignore' works when creating the .bzrignore file
64
86
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())
87
self.assertEquals(self.run_bzr(['unknowns'])[0], 'foo.blah\n')
88
self.run_bzr('ignore *.blah')
89
self.assertEquals(self.run_bzr(['unknowns'])[0], '')
90
self.check_file_contents('.bzrignore', '*.blah\n')
70
92
# 'ignore' works when then .bzrignore file already exists
71
93
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')
94
self.assertEquals(self.run_bzr(['unknowns'])[0], 'garh\n')
95
self.run_bzr('ignore garh')
96
self.assertEquals(self.run_bzr(['unknowns'])[0], '')
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.run_bzr(['unknowns'])[0], 'a\nb\nc\nd\n')
104
self.run_bzr('ignore a b c')
105
self.assertEquals(self.run_bzr(['unknowns'])[0], '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',),
77
115
def test_ignore_old_defaults(self):
78
116
out, err = self.run_bzr('ignore', '--old-default-rules')
79
117
self.assertContainsRe(out, 'CVS')
80
118
self.assertEqual('', err)