/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_ignore.py

  • Committer: Robert Collins
  • Date: 2007-03-08 04:06:06 UTC
  • mfrom: (2323.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 2442.
  • Revision ID: robertc@robertcollins.net-20070308040606-84gsniv56huiyjt4
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
 
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
 
 
25
from bzrlib import (
 
26
    ignores,
 
27
    osutils,
 
28
    )
 
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
 
 
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/ dir4\\')
 
63
        self.check_file_contents('.bzrignore', 'dir1\ndir2\ndir4\n')
 
64
        self.assertEquals(self.capture('unknowns'), 'dir3\n')
 
65
 
 
66
    def test_ignore_patterns(self):
 
67
        self.runbzr('init')
 
68
        self.assertEquals(self.capture('unknowns'), '')
 
69
 
 
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'])
 
73
 
 
74
        self.build_tree_contents(
 
75
            [('foo.tmp', '.tmp files are ignored by default'),
 
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'), '')
 
90
        self.check_file_contents('.bzrignore', '*.blah\n')
 
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'), '')
 
97
        self.check_file_contents('.bzrignore', '*.blah\ngarh\n')
 
98
       
 
99
    def test_ignore_multiple_arguments(self):
 
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')
 
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')
 
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 '
 
112
                            'NAME_PATTERN or --old-default-rules\n',),
 
113
                           'ignore')
 
114
 
 
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)
 
119