/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2006-2010, 2016 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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1765.1.2 by Robert Collins
Add missing test_ignore.py
16
6622.1.29 by Jelmer Vernooij
Fix some more tests.
17
"""UI tests for brz ignore."""
1765.1.2 by Robert Collins
Add missing test_ignore.py
18
19
20
import os
21
import re
22
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
23
from breezy import (
1996.3.18 by John Arbash Meinel
Now that mkdtemp and rmtree are lazy, they should not be directly improted.
24
    ignores,
25
    osutils,
26
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
27
import breezy
28
from breezy.branch import Branch
7490.61.1 by Jelmer Vernooij
Rename BzrCommandError to CommandError.
29
from breezy.errors import CommandError
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
30
from breezy.osutils import (
1765.1.2 by Robert Collins
Add missing test_ignore.py
31
    pathjoin,
32
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
33
from breezy.tests.test_sftp_transport import TestCaseWithSFTPServer
34
from breezy.tests import TestCaseWithTransport
35
from breezy.workingtree import WorkingTree
1765.1.2 by Robert Collins
Add missing test_ignore.py
36
37
5283.4.5 by Martin Pool
Update remaining subclasses of ExternalBase
38
class TestCommands(TestCaseWithTransport):
1765.1.2 by Robert Collins
Add missing test_ignore.py
39
2104.1.2 by John Arbash Meinel
(Kent Gibson) Fix bug #4559, strip trailing slashes from ignore patterns
40
    def test_ignore_absolutes(self):
41
        """'ignore' with an absolute path returns an error"""
2795.2.1 by Daniel Watkins
Updated tests in tests.blackbox.test_ignore to use bzr internals where appropriate.
42
        self.make_branch_and_tree('.')
6622.1.29 by Jelmer Vernooij
Fix some more tests.
43
        self.run_bzr_error(('brz: ERROR: NAME_PATTERN should not '
2104.1.2 by John Arbash Meinel
(Kent Gibson) Fix bug #4559, strip trailing slashes from ignore patterns
44
                            'be an absolute path\n',),
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
45
                           'ignore /crud')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
46
2104.1.2 by John Arbash Meinel
(Kent Gibson) Fix bug #4559, strip trailing slashes from ignore patterns
47
    def test_ignore_directories(self):
48
        """ignoring a directory should ignore directory tree.
49
50
        Also check that trailing slashes on directories are stripped.
51
        """
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
52
        self.run_bzr('init')
2104.1.2 by John Arbash Meinel
(Kent Gibson) Fix bug #4559, strip trailing slashes from ignore patterns
53
        self.build_tree(['dir1/', 'dir1/foo',
54
                         'dir2/', 'dir2/bar',
55
                         'dir3/', 'dir3/baz'])
2530.3.4 by Martin Pool
Deprecate run_bzr_captured in favour of just run_bzr
56
        self.run_bzr(['ignore', 'dir1', 'dir2/', 'dir4\\'])
6973.10.4 by Jelmer Vernooij
Update python3.passing.
57
        self.check_file_contents('.bzrignore', b'dir1\ndir2\ndir4\n')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
58
        self.assertEqual(self.run_bzr('unknowns')[0], 'dir3\n')
2104.1.2 by John Arbash Meinel
(Kent Gibson) Fix bug #4559, strip trailing slashes from ignore patterns
59
1765.1.2 by Robert Collins
Add missing test_ignore.py
60
    def test_ignore_patterns(self):
2795.2.1 by Daniel Watkins
Updated tests in tests.blackbox.test_ignore to use bzr internals where appropriate.
61
        tree = self.make_branch_and_tree('.')
62
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
63
        self.assertEqual(list(tree.unknowns()), [])
1765.1.2 by Robert Collins
Add missing test_ignore.py
64
1836.1.15 by John Arbash Meinel
Updated WorkingTree to use the new user-level ignores.
65
        # is_ignored() will now create the user global ignore file
66
        # 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
67
        ignores._set_user_ignores(['*.tmp'])
1836.1.15 by John Arbash Meinel
Updated WorkingTree to use the new user-level ignores.
68
1765.1.2 by Robert Collins
Add missing test_ignore.py
69
        self.build_tree_contents(
6855.4.1 by Jelmer Vernooij
Yet more bees.
70
            [('foo.tmp', b'.tmp files are ignored by default')])
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
71
        self.assertEqual(list(tree.unknowns()), [])
2795.2.1 by Daniel Watkins
Updated tests in tests.blackbox.test_ignore to use bzr internals where appropriate.
72
6855.4.1 by Jelmer Vernooij
Yet more bees.
73
        self.build_tree_contents([('foo.c', b'int main() {}')])
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
74
        self.assertEqual(list(tree.unknowns()), ['foo.c'])
2795.2.1 by Daniel Watkins
Updated tests in tests.blackbox.test_ignore to use bzr internals where appropriate.
75
76
        tree.add('foo.c')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
77
        self.assertEqual(list(tree.unknowns()), [])
1765.1.2 by Robert Collins
Add missing test_ignore.py
78
79
        # 'ignore' works when creating the .bzrignore file
6855.4.1 by Jelmer Vernooij
Yet more bees.
80
        self.build_tree_contents([('foo.blah', b'blah')])
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
81
        self.assertEqual(list(tree.unknowns()), ['foo.blah'])
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
82
        self.run_bzr('ignore *.blah')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
83
        self.assertEqual(list(tree.unknowns()), [])
6973.10.4 by Jelmer Vernooij
Update python3.passing.
84
        self.check_file_contents('.bzrignore', b'*.blah\n')
1765.1.2 by Robert Collins
Add missing test_ignore.py
85
86
        # 'ignore' works when then .bzrignore file already exists
6855.4.1 by Jelmer Vernooij
Yet more bees.
87
        self.build_tree_contents([('garh', b'garh')])
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
88
        self.assertEqual(list(tree.unknowns()), ['garh'])
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
89
        self.run_bzr('ignore garh')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
90
        self.assertEqual(list(tree.unknowns()), [])
6973.10.4 by Jelmer Vernooij
Update python3.passing.
91
        self.check_file_contents('.bzrignore', b'*.blah\ngarh\n')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
92
2104.1.2 by John Arbash Meinel
(Kent Gibson) Fix bug #4559, strip trailing slashes from ignore patterns
93
    def test_ignore_multiple_arguments(self):
2063.5.4 by wang
Copy Kent Gibson's changes that incorporates John Arbash Meinel's
94
        """'ignore' works with multiple arguments"""
2795.2.1 by Daniel Watkins
Updated tests in tests.blackbox.test_ignore to use bzr internals where appropriate.
95
        tree = self.make_branch_and_tree('.')
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
96
        self.build_tree(['a', 'b', 'c', 'd'])
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
97
        self.assertEqual(list(tree.unknowns()), ['a', 'b', 'c', 'd'])
2530.3.1 by Martin Pool
Cleanup old variations on run_bzr in the test suite
98
        self.run_bzr('ignore a b c')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
99
        self.assertEqual(list(tree.unknowns()), ['d'])
6973.10.4 by Jelmer Vernooij
Update python3.passing.
100
        self.check_file_contents('.bzrignore', b'a\nb\nc\n')
2077.1.2 by Kent Gibson
Strip trailing slashes from ignore patterns (#4559).
101
102
    def test_ignore_no_arguments(self):
103
        """'ignore' with no arguments returns an error"""
2795.2.1 by Daniel Watkins
Updated tests in tests.blackbox.test_ignore to use bzr internals where appropriate.
104
        self.make_branch_and_tree('.')
6622.1.29 by Jelmer Vernooij
Fix some more tests.
105
        self.run_bzr_error(('brz: ERROR: ignore requires at least one '
5168.3.3 by Parth Malwankar
Removed --old-default-rules flag.
106
                            'NAME_PATTERN or --default-rules.\n',),
2077.1.2 by Kent Gibson
Strip trailing slashes from ignore patterns (#4559).
107
                           'ignore')
108
5168.3.1 by Parth Malwankar
bzr ignore now support --default-rules option
109
    def test_ignore_default_rules(self):
110
        out, err = self.run_bzr(['ignore', '--default-rules'])
111
        reference_set = set(ignores.USER_DEFAULTS)
112
        output_set = set(out.rstrip().split('\n'))
113
        self.assertEqual(reference_set, output_set)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
114
        self.assertEqual('', err)
5168.3.1 by Parth Malwankar
bzr ignore now support --default-rules option
115
2747.5.2 by Daniel Watkins
Added tests for new functionality.
116
    def test_ignore_versioned_file(self):
117
        tree = self.make_branch_and_tree('.')
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
118
        self.build_tree(['a', 'b'])
2747.5.2 by Daniel Watkins
Added tests for new functionality.
119
        tree.add('a')
120
121
        # test a single versioned file
122
        out, err = self.run_bzr('ignore a')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
123
        self.assertEqual(out,
7143.15.2 by Jelmer Vernooij
Run autopep8.
124
                         "Warning: the following files are version controlled"
125
                         " and match your ignore pattern:\na\n"
126
                         "These files will continue to be version controlled"
6622.1.29 by Jelmer Vernooij
Fix some more tests.
127
                         " unless you 'brz remove' them.\n")
2747.5.2 by Daniel Watkins
Added tests for new functionality.
128
129
        # test a single unversioned file
130
        out, err = self.run_bzr('ignore b')
131
        self.assertEqual(out, '')
132
133
        # test wildcards
134
        tree.add('b')
135
        out, err = self.run_bzr('ignore *')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
136
        self.assertEqual(out,
7143.15.2 by Jelmer Vernooij
Run autopep8.
137
                         "Warning: the following files are version controlled"
138
                         " and match your ignore pattern:\n.bzrignore\na\nb\n"
139
                         "These files will continue to be version controlled"
6622.1.29 by Jelmer Vernooij
Fix some more tests.
140
                         " unless you 'brz remove' them.\n")
2747.5.4 by Daniel Watkins
Added test showing that the warning lists only files matching the new glob, as per abentley's request.
141
142
    def test_ignored_versioned_file_matching_new_pattern(self):
143
        tree = self.make_branch_and_tree('.')
144
        self.build_tree(['a', 'b'])
145
        tree.add(['a', 'b'])
146
        self.run_bzr('ignore *')
147
148
        # If only the given pattern is used then only 'b' should match in
149
        # this case.
150
        out, err = self.run_bzr('ignore b')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
151
        self.assertEqual(out,
7143.15.2 by Jelmer Vernooij
Run autopep8.
152
                         "Warning: the following files are version controlled"
153
                         " and match your ignore pattern:\nb\n"
154
                         "These files will continue to be version controlled"
6622.1.29 by Jelmer Vernooij
Fix some more tests.
155
                         " unless you 'brz remove' them.\n")
5171.3.7 by Martin von Gagern
Added blackbox tests for --directory option.
156
157
    def test_ignore_directory(self):
158
        """Test --directory option"""
159
        tree = self.make_branch_and_tree('a')
160
        self.run_bzr(['ignore', '--directory=a', 'README'])
6973.10.4 by Jelmer Vernooij
Update python3.passing.
161
        self.check_file_contents('a/.bzrignore', b'README\n')
5339.3.4 by Parth Malwankar
cleanup of globster code.
162
163
    def test_ignored_invalid_pattern(self):
164
        """Ensure graceful handling for invalid ignore pattern.
165
166
        Test case for #300062.
167
        Invalid pattern should show clear error message.
168
        Invalid pattern should not be added to .bzrignore file.
169
        """
170
        tree = self.make_branch_and_tree('.')
171
        out, err = self.run_bzr(['ignore', 'RE:*.cpp', 'foo', 'RE:['], 3)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
172
        self.assertEqual(out, '')
5339.3.4 by Parth Malwankar
cleanup of globster code.
173
        self.assertContainsRe(err,
7143.15.2 by Jelmer Vernooij
Run autopep8.
174
                              r'Invalid ignore pattern.*RE:\*\.cpp.*RE:\[', re.DOTALL)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
175
        self.assertNotContainsRe(err, 'foo', re.DOTALL)
5339.3.4 by Parth Malwankar
cleanup of globster code.
176
        self.assertFalse(os.path.isfile('.bzrignore'))