/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) 2007, 2009-2012, 2016 Canonical Ltd
2255.2.62 by John Arbash Meinel
add a workingtree_implementations test that makes sure smart_add_tree orks properly
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
2255.2.62 by John Arbash Meinel
add a workingtree_implementations test that makes sure smart_add_tree orks properly
16
17
"""Test that we can use smart_add on all Tree implementations."""
18
5378.1.1 by Martin
Add per_workingtree tests in add and smart_add for bug 205636
19
import os
4789.11.1 by John Arbash Meinel
Skip the assertFilenameSkipped tests on Windows.
20
import sys
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
21
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
22
from ... import (
7141.3.2 by Jelmer Vernooij
add some tests.
23
    add as _mod_add,
2255.2.62 by John Arbash Meinel
add a workingtree_implementations test that makes sure smart_add_tree orks properly
24
    errors,
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
25
    ignores,
26
    osutils,
2568.2.10 by Robert Collins
And a missing import.
27
    tests,
6123.10.1 by Jelmer Vernooij
"bzr add" warns about nested trees that are skipped.
28
    trace,
6851.1.1 by Jelmer Vernooij
More foreign branch fixes.
29
    workingtree,
2255.2.62 by John Arbash Meinel
add a workingtree_implementations test that makes sure smart_add_tree orks properly
30
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
31
from ...sixish import (
7045.4.3 by Jelmer Vernooij
Fix test_custom_ids tests.
32
    StringIO,
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
33
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
34
from .. import (
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
35
    features,
36
    per_workingtree,
5013.2.2 by Vincent Ladeuil
Fix imports in per_workingtree/test_smart_add.py.
37
    test_smart_add,
2255.7.92 by Martin Pool
Test for smart_add(save=false) should be run against all WorkingTrees; adjust the test to more precisely cover the contract.
38
    )
5013.2.2 by Vincent Ladeuil
Fix imports in per_workingtree/test_smart_add.py.
39
40
7141.3.2 by Jelmer Vernooij
add some tests.
41
class RecordingAddAction(_mod_add.AddAction):
42
43
    def __init__(self):
44
        self.adds = []
45
46
    def __call__(self, wt, parent_ie, path, kind):
47
        self.adds.append((wt, path, kind))
48
49
5013.2.2 by Vincent Ladeuil
Fix imports in per_workingtree/test_smart_add.py.
50
class TestSmartAddTree(per_workingtree.TestCaseWithWorkingTree):
2255.2.62 by John Arbash Meinel
add a workingtree_implementations test that makes sure smart_add_tree orks properly
51
52
    def test_single_file(self):
53
        tree = self.make_branch_and_tree('tree')
54
        self.build_tree(['tree/a'])
7141.3.2 by Jelmer Vernooij
add some tests.
55
        action = RecordingAddAction()
56
        tree.smart_add(['tree'], action=action)
2255.2.62 by John Arbash Meinel
add a workingtree_implementations test that makes sure smart_add_tree orks properly
57
7141.3.2 by Jelmer Vernooij
add some tests.
58
        with tree.lock_read():
2255.2.62 by John Arbash Meinel
add a workingtree_implementations test that makes sure smart_add_tree orks properly
59
            files = [(path, status, kind)
60
                     for path, status, kind, file_id, parent_id
7143.16.9 by Jelmer Vernooij
Fix E127
61
                     in tree.list_files(include_root=True)]
2255.2.62 by John Arbash Meinel
add a workingtree_implementations test that makes sure smart_add_tree orks properly
62
        self.assertEqual([('', 'V', 'directory'), ('a', 'V', 'file')],
63
                         files)
7141.3.2 by Jelmer Vernooij
add some tests.
64
        self.assertEqual([(tree, 'a', 'file')], action.adds)
2255.7.92 by Martin Pool
Test for smart_add(save=false) should be run against all WorkingTrees; adjust the test to more precisely cover the contract.
65
4634.55.1 by Robert Collins
Do not add files whose name contains new lines or carriage returns
66
    def assertFilenameSkipped(self, filename):
67
        tree = self.make_branch_and_tree('tree')
4789.11.1 by John Arbash Meinel
Skip the assertFilenameSkipped tests on Windows.
68
        try:
7143.15.2 by Jelmer Vernooij
Run autopep8.
69
            self.build_tree(['tree/' + filename])
4789.11.1 by John Arbash Meinel
Skip the assertFilenameSkipped tests on Windows.
70
        except errors.NoSuchFile:
71
            if sys.platform == 'win32':
72
                raise tests.TestNotApplicable('Cannot create files named %r on'
7143.15.2 by Jelmer Vernooij
Run autopep8.
73
                                              ' win32' % (filename,))
4634.55.1 by Robert Collins
Do not add files whose name contains new lines or carriage returns
74
        tree.smart_add(['tree'])
75
        self.assertEqual(None, tree.path2id(filename))
76
77
    def test_path_containing_newline_skips(self):
78
        self.assertFilenameSkipped('a\nb')
79
80
    def test_path_containing_carriagereturn_skips(self):
81
        self.assertFilenameSkipped('a\rb')
82
2255.7.92 by Martin Pool
Test for smart_add(save=false) should be run against all WorkingTrees; adjust the test to more precisely cover the contract.
83
    def test_save_false(self):
84
        """Dry-run add doesn't permanently affect the tree."""
85
        wt = self.make_branch_and_tree('.')
7141.3.2 by Jelmer Vernooij
add some tests.
86
        with wt.lock_write():
2585.1.1 by Aaron Bentley
Unify MutableTree.smart_add behavior by disabling quirky memory-only Inventory
87
            self.build_tree(['file'])
88
            wt.smart_add(['file'], save=False)
89
            # the file should not be added - no id.
90
            self.assertEqual(wt.path2id('file'), None)
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
91
        # and the disk state should be the same - reopen to check.
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
92
        wt = wt.controldir.open_workingtree()
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
93
        self.assertFalse(wt.is_versioned('file'))
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
94
95
    def test_add_dot_from_root(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
96
        """Test adding . from the root of the tree."""
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
97
        paths = ("original/", "original/file1", "original/file2")
98
        self.build_tree(paths)
99
        wt = self.make_branch_and_tree('.')
7141.3.2 by Jelmer Vernooij
add some tests.
100
        action = RecordingAddAction()
101
        wt.smart_add((u".",), action=action)
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
102
        for path in paths:
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
103
            self.assertTrue(wt.is_versioned(path))
7141.3.2 by Jelmer Vernooij
add some tests.
104
        if wt.has_versioned_directories():
105
            self.assertEqual(
106
                {(wt, 'original', 'directory'),
107
                 (wt, 'original/file1', 'file'),
108
                 (wt, 'original/file2', 'file')},
109
                set(action.adds))
110
        else:
111
            self.assertEqual(
112
                {(wt, 'original/file1', 'file'),
113
                 (wt, 'original/file2', 'file')},
114
                set(action.adds))
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
115
6123.10.1 by Jelmer Vernooij
"bzr add" warns about nested trees that are skipped.
116
    def test_skip_nested_trees(self):
117
        """Test smart-adding a nested tree ignors it and warns."""
118
        wt = self.make_branch_and_tree('.')
119
        nested_wt = self.make_branch_and_tree('nested')
120
        warnings = []
7143.15.2 by Jelmer Vernooij
Run autopep8.
121
6123.10.1 by Jelmer Vernooij
"bzr add" warns about nested trees that are skipped.
122
        def warning(*args):
123
            warnings.append(args[0] % args[1:])
124
        self.overrideAttr(trace, 'warning', warning)
125
        wt.smart_add((u".",))
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
126
        self.assertFalse(wt.is_versioned("nested"))
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
127
        self.assertEqual(
6123.10.1 by Jelmer Vernooij
"bzr add" warns about nested trees that are skipped.
128
            ['skipping nested tree %r' % nested_wt.basedir], warnings)
129
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
130
    def test_add_dot_from_subdir(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
131
        """Test adding . from a subdir of the tree."""
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
132
        paths = ("original/", "original/file1", "original/file2")
133
        self.build_tree(paths)
134
        wt = self.make_branch_and_tree('.')
135
        wt.smart_add((u".",))
136
        for path in paths:
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
137
            self.assertTrue(wt.is_versioned(path))
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
138
139
    def test_add_tree_from_above_tree(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
140
        """Test adding a tree from above the tree."""
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
141
        paths = ("original/", "original/file1", "original/file2")
142
        branch_paths = ("branch/", "branch/original/", "branch/original/file1",
143
                        "branch/original/file2")
144
        self.build_tree(branch_paths)
145
        wt = self.make_branch_and_tree('branch')
146
        wt.smart_add(("branch",))
147
        for path in paths:
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
148
            self.assertTrue(wt.is_versioned(path))
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
149
150
    def test_add_above_tree_preserves_tree(self):
151
        """Test nested trees are not affect by an add above them."""
152
        paths = ("original/", "original/file1", "original/file2")
153
        child_paths = ("path",)
154
        full_child_paths = ("original/child", "original/child/path")
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
155
        build_paths = ("original/", "original/file1", "original/file2",
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
156
                       "original/child/", "original/child/path")
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
157
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
158
        self.build_tree(build_paths)
159
        wt = self.make_branch_and_tree('.')
6874.1.2 by Jelmer Vernooij
Consistently use Branch.user_url.
160
        if wt.controldir.user_url != wt.branch.controldir.user_url:
6437.70.6 by John Arbash Meinel
Fix a couple tests that wanted to directly create a wt where the branch was.
161
            # Lightweight checkout, make sure we have a repo location.
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
162
            wt.branch.controldir.root_transport.mkdir('original')
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
163
        child_tree = self.make_branch_and_tree('original/child')
164
        wt.smart_add((".",))
165
        for path in paths:
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
166
            self.assertNotEqual((path, wt.is_versioned(path)),
167
                                (path, False))
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
168
        for path in full_child_paths:
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
169
            self.assertEqual((path, wt.is_versioned(path)),
170
                             (path, False))
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
171
        for path in child_paths:
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
172
            self.assertFalse(child_tree.is_versioned(path))
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
173
174
    def test_add_paths(self):
175
        """Test smart-adding a list of paths."""
176
        paths = ("file1", "file2")
177
        self.build_tree(paths)
178
        wt = self.make_branch_and_tree('.')
179
        wt.smart_add(paths)
180
        for path in paths:
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
181
            self.assertTrue(wt.is_versioned(path))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
182
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
183
    def test_add_ignored_nested_paths(self):
184
        """Test smart-adding a list of paths which includes ignored ones."""
185
        wt = self.make_branch_and_tree('.')
7143.15.2 by Jelmer Vernooij
Run autopep8.
186
        tree_shape = ("adir/", "adir/CVS/",
187
                      "adir/CVS/afile", "adir/CVS/afile2")
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
188
        add_paths = ("adir/CVS", "adir/CVS/afile", "adir")
7143.15.2 by Jelmer Vernooij
Run autopep8.
189
        expected_paths = ("adir", "adir/CVS",
190
                          "adir/CVS/afile", "adir/CVS/afile2")
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
191
        self.build_tree(tree_shape)
192
        wt.smart_add(add_paths)
193
        for path in expected_paths:
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
194
            self.assertTrue(wt.is_versioned(path), "No id added for %s" % path)
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
195
196
    def test_add_non_existant(self):
197
        """Test smart-adding a file that does not exist."""
198
        wt = self.make_branch_and_tree('.')
7143.15.2 by Jelmer Vernooij
Run autopep8.
199
        self.assertRaises(errors.NoSuchFile, wt.smart_add,
200
                          ['non-existant-file'])
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
201
202
    def test_returns_and_ignores(self):
203
        """Correctly returns added/ignored files"""
204
        wt = self.make_branch_and_tree('.')
205
        # The default ignore list includes '*.py[co]', but not CVS
206
        ignores._set_user_ignores(['*.py[co]'])
207
        self.build_tree(['inertiatic/', 'inertiatic/esp', 'inertiatic/CVS',
7143.15.2 by Jelmer Vernooij
Run autopep8.
208
                         'inertiatic/foo.pyc'])
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
209
        added, ignored = wt.smart_add(u'.')
6861.1.1 by Jelmer Vernooij
More foreign branch test fixes.
210
        if wt.has_versioned_directories():
211
            self.assertSubset(('inertiatic', 'inertiatic/esp', 'inertiatic/CVS'),
212
                              added)
213
        else:
214
            self.assertSubset(('inertiatic/esp', 'inertiatic/CVS'),
215
                              added)
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
216
        self.assertSubset(('*.py[co]',), ignored)
217
        self.assertSubset(('inertiatic/foo.pyc',), ignored['*.py[co]'])
218
219
    def test_add_multiple_dirs(self):
220
        """Test smart adding multiple directories at once."""
221
        added_paths = ['file1', 'file2',
222
                       'dir1/', 'dir1/file3',
223
                       'dir1/subdir2/', 'dir1/subdir2/file4',
224
                       'dir2/', 'dir2/file5',
7143.15.2 by Jelmer Vernooij
Run autopep8.
225
                       ]
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
226
        not_added = ['file6', 'dir3/', 'dir3/file7', 'dir3/file8']
227
        self.build_tree(added_paths)
228
        self.build_tree(not_added)
229
230
        wt = self.make_branch_and_tree('.')
231
        wt.smart_add(['file1', 'file2', 'dir1', 'dir2'])
232
233
        for path in added_paths:
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
234
            self.assertTrue(wt.is_versioned(path.rstrip('/')),
7143.15.2 by Jelmer Vernooij
Run autopep8.
235
                            'Failed to add path: %s' % (path,))
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
236
        for path in not_added:
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
237
            self.assertFalse(wt.is_versioned(path.rstrip('/')),
7143.15.2 by Jelmer Vernooij
Run autopep8.
238
                             'Accidentally added path: %s' % (path,))
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
239
4163.2.1 by Ian Clatworthy
Fix add in trees supports views
240
    def test_add_file_in_unknown_dir(self):
241
        # Test that parent directory addition is implicit
242
        tree = self.make_branch_and_tree('.')
243
        self.build_tree(['dir/', 'dir/subdir/', 'dir/subdir/foo'])
244
        tree.smart_add(['dir/subdir/foo'])
245
        tree.lock_read()
246
        self.addCleanup(tree.unlock)
247
        self.assertEqual(['', 'dir', 'dir/subdir', 'dir/subdir/foo'],
7143.15.2 by Jelmer Vernooij
Run autopep8.
248
                         [path for path, ie in tree.iter_entries_by_dir()])
4163.2.1 by Ian Clatworthy
Fix add in trees supports views
249
5504.6.2 by Martin
If a dir being added used to be something else detect and correct
250
    def test_add_dir_bug_251864(self):
5504.6.3 by Martin
Address poolie's review, mention both bugs in test and add news
251
        """Added file turning into a dir should be detected on add dir
252
253
        Similar to bug 205636 but with automatic adding of directory contents.
254
        """
5378.1.1 by Martin
Add per_workingtree tests in add and smart_add for bug 205636
255
        tree = self.make_branch_and_tree(".")
7143.15.2 by Jelmer Vernooij
Run autopep8.
256
        self.build_tree(["dir"])  # whoops, make a file called dir
5378.1.1 by Martin
Add per_workingtree tests in add and smart_add for bug 205636
257
        tree.smart_add(["dir"])
258
        os.remove("dir")
259
        self.build_tree(["dir/", "dir/file"])
5504.6.2 by Martin
If a dir being added used to be something else detect and correct
260
        tree.smart_add(["dir"])
5378.1.1 by Martin
Add per_workingtree tests in add and smart_add for bug 205636
261
        tree.commit("Add dir contents")
5378.1.4 by Martin
Assert state of the tree after add and commit in new tests
262
        self.addCleanup(tree.lock_read().unlock)
263
        self.assertEqual([(u"dir", "directory"), (u"dir/file", "file")],
7143.15.2 by Jelmer Vernooij
Run autopep8.
264
                         [(t[0], t[2]) for t in tree.list_files()])
5378.1.4 by Martin
Assert state of the tree after add and commit in new tests
265
        self.assertFalse(list(tree.iter_changes(tree.basis_tree())))
5378.1.1 by Martin
Add per_workingtree tests in add and smart_add for bug 205636
266
267
    def test_add_subdir_file_bug_205636(self):
268
        """Added file turning into a dir should be detected on add dir/file"""
269
        tree = self.make_branch_and_tree(".")
7143.15.2 by Jelmer Vernooij
Run autopep8.
270
        self.build_tree(["dir"])  # whoops, make a file called dir
5378.1.1 by Martin
Add per_workingtree tests in add and smart_add for bug 205636
271
        tree.smart_add(["dir"])
272
        os.remove("dir")
273
        self.build_tree(["dir/", "dir/file"])
5378.1.3 by Martin
Note that TestSmartAddTree.test_add_subdir_file_bug_205636 now passes
274
        tree.smart_add(["dir/file"])
5378.1.1 by Martin
Add per_workingtree tests in add and smart_add for bug 205636
275
        tree.commit("Add file in dir")
5378.1.4 by Martin
Assert state of the tree after add and commit in new tests
276
        self.addCleanup(tree.lock_read().unlock)
277
        self.assertEqual([(u"dir", "directory"), (u"dir/file", "file")],
7143.15.2 by Jelmer Vernooij
Run autopep8.
278
                         [(t[0], t[2]) for t in tree.list_files()])
5378.1.4 by Martin
Assert state of the tree after add and commit in new tests
279
        self.assertFalse(list(tree.iter_changes(tree.basis_tree())))
5378.1.1 by Martin
Add per_workingtree tests in add and smart_add for bug 205636
280
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
281
    def test_custom_ids(self):
7045.4.3 by Jelmer Vernooij
Fix test_custom_ids tests.
282
        sio = StringIO()
5013.2.2 by Vincent Ladeuil
Fix imports in per_workingtree/test_smart_add.py.
283
        action = test_smart_add.AddCustomIDAction(to_file=sio,
284
                                                  should_print=True)
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
285
        self.build_tree(['file1', 'dir1/', 'dir1/file2'])
286
287
        wt = self.make_branch_and_tree('.')
6851.1.1 by Jelmer Vernooij
More foreign branch fixes.
288
        if not wt._format.supports_setting_file_ids:
289
            self.assertRaises(
290
                workingtree.SettingFileIdUnsupported,
291
                wt.smart_add, ['.'], action=action)
292
            return
293
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
294
        wt.smart_add(['.'], action=action)
295
        # The order of adds is not strictly fixed:
296
        sio.seek(0)
297
        lines = sorted(sio.readlines())
6851.1.1 by Jelmer Vernooij
More foreign branch fixes.
298
        self.assertEqual(['added dir1 with id directory-dir1\n',
299
                          'added dir1/file2 with id file-dir1%file2\n',
7143.15.2 by Jelmer Vernooij
Run autopep8.
300
                          'added file1 with id file-file1\n', ], lines)
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
301
        wt.lock_read()
302
        self.addCleanup(wt.unlock)
303
        self.assertEqual([('', wt.path2id('')),
7045.4.3 by Jelmer Vernooij
Fix test_custom_ids tests.
304
                          ('dir1', b'directory-dir1'),
305
                          ('file1', b'file-file1'),
306
                          ('dir1/file2', b'file-dir1%file2'),
7143.15.2 by Jelmer Vernooij
Run autopep8.
307
                          ], [(path, ie.file_id) for path, ie
308
                              in wt.iter_entries_by_dir()])
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
309
5013.2.3 by Vincent Ladeuil
Simplify some tests in per_workingtree/test_smart_add.py.
310
5013.2.4 by Vincent Ladeuil
``bzr add`` won't blindly add conflict related files.
311
class TestSmartAddConflictRelatedFiles(per_workingtree.TestCaseWithWorkingTree):
312
313
    def make_tree_with_text_conflict(self):
314
        tb = self.make_branch_and_tree('base')
6855.4.1 by Jelmer Vernooij
Yet more bees.
315
        self.build_tree_contents([('base/file', b'content in base')])
5013.2.4 by Vincent Ladeuil
``bzr add`` won't blindly add conflict related files.
316
        tb.add('file')
317
        tb.commit('Adding file')
318
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
319
        t1 = tb.controldir.sprout('t1').open_workingtree()
5013.2.4 by Vincent Ladeuil
``bzr add`` won't blindly add conflict related files.
320
6855.4.1 by Jelmer Vernooij
Yet more bees.
321
        self.build_tree_contents([('base/file', b'content changed in base')])
5013.2.4 by Vincent Ladeuil
``bzr add`` won't blindly add conflict related files.
322
        tb.commit('Changing file in base')
323
6855.4.1 by Jelmer Vernooij
Yet more bees.
324
        self.build_tree_contents([('t1/file', b'content in t1')])
5013.2.4 by Vincent Ladeuil
``bzr add`` won't blindly add conflict related files.
325
        t1.commit('Changing file in t1')
326
        t1.merge_from_branch(tb.branch)
327
        return t1
328
329
    def test_cant_add_generated_files_implicitly(self):
330
        t = self.make_tree_with_text_conflict()
331
        added, ignored = t.smart_add([t.basedir])
332
        self.assertEqual(([], {}), (added, ignored))
333
334
    def test_can_add_generated_files_explicitly(self):
7143.15.2 by Jelmer Vernooij
Run autopep8.
335
        fnames = ['file.%s' % s for s in ('BASE', 'THIS', 'OTHER')]
5013.2.4 by Vincent Ladeuil
``bzr add`` won't blindly add conflict related files.
336
        t = self.make_tree_with_text_conflict()
337
        added, ignored = t.smart_add([t.basedir + '/%s' % f for f in fnames])
338
        self.assertEqual((fnames, {}), (added, ignored))
339
340
5013.2.3 by Vincent Ladeuil
Simplify some tests in per_workingtree/test_smart_add.py.
341
class TestSmartAddTreeUnicode(per_workingtree.TestCaseWithWorkingTree):
342
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
343
    _test_needs_features = [features.UnicodeFilenameFeature]
5013.2.3 by Vincent Ladeuil
Simplify some tests in per_workingtree/test_smart_add.py.
344
345
    def setUp(self):
346
        super(TestSmartAddTreeUnicode, self).setUp()
347
        self.build_tree([u'a\u030a'])
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
348
        self.wt = self.make_branch_and_tree('.')
5013.2.3 by Vincent Ladeuil
Simplify some tests in per_workingtree/test_smart_add.py.
349
        self.overrideAttr(osutils, 'normalized_filename')
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
350
5868.1.4 by Andrew Bennetts
Tweak mgz's patch to preserve the test coverage of raising NoSuchFile if unnormalized unicode is passed to a wt format that requires normalized unicode.
351
    def test_requires_normalized_unicode_filenames_fails_on_unnormalized(self):
352
        """Adding unnormalized unicode filenames fail if and only if the
353
        workingtree format has the requires_normalized_unicode_filenames flag
5929.1.1 by Vincent Ladeuil
Fix spurious test failure on OSX for WorkingTreeFormat2
354
        set and the underlying filesystem doesn't normalize.
5868.1.4 by Andrew Bennetts
Tweak mgz's patch to preserve the test coverage of raising NoSuchFile if unnormalized unicode is passed to a wt format that requires normalized unicode.
355
        """
356
        osutils.normalized_filename = osutils._accessible_normalized_filename
5929.1.1 by Vincent Ladeuil
Fix spurious test failure on OSX for WorkingTreeFormat2
357
        if (self.workingtree_format.requires_normalized_unicode_filenames
7143.15.2 by Jelmer Vernooij
Run autopep8.
358
                and sys.platform != 'darwin'):
5868.1.4 by Andrew Bennetts
Tweak mgz's patch to preserve the test coverage of raising NoSuchFile if unnormalized unicode is passed to a wt format that requires normalized unicode.
359
            self.assertRaises(
360
                errors.NoSuchFile, self.wt.smart_add, [u'a\u030a'])
361
        else:
362
            self.wt.smart_add([u'a\u030a'])
363
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
364
    def test_accessible_explicit(self):
365
        osutils.normalized_filename = osutils._accessible_normalized_filename
5582.10.29 by Jelmer Vernooij
Add requires_normalized_unicode_filenames
366
        if self.workingtree_format.requires_normalized_unicode_filenames:
5868.1.4 by Andrew Bennetts
Tweak mgz's patch to preserve the test coverage of raising NoSuchFile if unnormalized unicode is passed to a wt format that requires normalized unicode.
367
            raise tests.TestNotApplicable(
368
                'Working tree format smart_add requires normalized unicode '
369
                'filenames')
5868.1.1 by Martin
Turn two long-standing unexpected successes into skips
370
        self.wt.smart_add([u'a\u030a'])
5013.2.3 by Vincent Ladeuil
Simplify some tests in per_workingtree/test_smart_add.py.
371
        self.wt.lock_read()
372
        self.addCleanup(self.wt.unlock)
373
        self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
374
                         [(path, ie.kind) for path, ie in
5807.1.8 by Jelmer Vernooij
Fix some tests.
375
                          self.wt.iter_entries_by_dir()])
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
376
377
    def test_accessible_implicit(self):
378
        osutils.normalized_filename = osutils._accessible_normalized_filename
5582.10.29 by Jelmer Vernooij
Add requires_normalized_unicode_filenames
379
        if self.workingtree_format.requires_normalized_unicode_filenames:
5868.1.4 by Andrew Bennetts
Tweak mgz's patch to preserve the test coverage of raising NoSuchFile if unnormalized unicode is passed to a wt format that requires normalized unicode.
380
            raise tests.TestNotApplicable(
381
                'Working tree format smart_add requires normalized unicode '
382
                'filenames')
5868.1.1 by Martin
Turn two long-standing unexpected successes into skips
383
        self.wt.smart_add([])
5013.2.3 by Vincent Ladeuil
Simplify some tests in per_workingtree/test_smart_add.py.
384
        self.wt.lock_read()
385
        self.addCleanup(self.wt.unlock)
386
        self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
387
                         [(path, ie.kind) for path, ie
5807.1.8 by Jelmer Vernooij
Fix some tests.
388
                          in self.wt.iter_entries_by_dir()])
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
389
390
    def test_inaccessible_explicit(self):
391
        osutils.normalized_filename = osutils._inaccessible_normalized_filename
5013.2.3 by Vincent Ladeuil
Simplify some tests in per_workingtree/test_smart_add.py.
392
        self.assertRaises(errors.InvalidNormalization,
393
                          self.wt.smart_add, [u'a\u030a'])
2568.2.4 by Robert Collins
* ``bzrlib.add.smart_add`` and ``bzrlib.add.smart_add_tree`` are now
394
395
    def test_inaccessible_implicit(self):
396
        osutils.normalized_filename = osutils._inaccessible_normalized_filename
5013.2.3 by Vincent Ladeuil
Simplify some tests in per_workingtree/test_smart_add.py.
397
        # TODO: jam 20060701 In the future, this should probably
398
        #       just ignore files that don't fit the normalization
399
        #       rules, rather than exploding
400
        self.assertRaises(errors.InvalidNormalization, self.wt.smart_add, [])