/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/per_workingtree/test_smart_add.py

Merge bzr.dev, update to use new hooks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Test that we can use smart_add on all Tree implementations."""
18
18
 
19
19
from cStringIO import StringIO
 
20
import os
20
21
import sys
21
22
 
22
23
from bzrlib import (
23
 
    add,
24
24
    errors,
25
25
    ignores,
26
26
    osutils,
27
27
    tests,
28
 
    workingtree,
 
28
    trace,
29
29
    )
30
30
from bzrlib.tests import (
31
31
    features,
 
32
    per_workingtree,
32
33
    test_smart_add,
33
 
    per_workingtree,
34
34
    )
35
35
 
36
36
 
92
92
        for path in paths:
93
93
            self.assertNotEqual(wt.path2id(path), None)
94
94
 
 
95
    def test_skip_nested_trees(self):
 
96
        """Test smart-adding a nested tree ignors it and warns."""
 
97
        wt = self.make_branch_and_tree('.')
 
98
        nested_wt = self.make_branch_and_tree('nested')
 
99
        warnings = []
 
100
        def warning(*args):
 
101
            warnings.append(args[0] % args[1:])
 
102
        self.overrideAttr(trace, 'warning', warning)
 
103
        wt.smart_add((u".",))
 
104
        self.assertIs(wt.path2id("nested"), None)
 
105
        self.assertEquals(
 
106
            ['skipping nested tree %r' % nested_wt.basedir], warnings)
 
107
 
95
108
    def test_add_dot_from_subdir(self):
96
109
        """Test adding . from a subdir of the tree."""
97
110
        paths = ("original/", "original/file1", "original/file2")
151
164
        self.build_tree(tree_shape)
152
165
        wt.smart_add(add_paths)
153
166
        for path in expected_paths:
154
 
            self.assertNotEqual(wt.path2id(path), None, "No id added for %s" % path)
 
167
            self.assertNotEqual(wt.path2id(path), None,
 
168
                "No id added for %s" % path)
155
169
 
156
170
    def test_add_non_existant(self):
157
171
        """Test smart-adding a file that does not exist."""
202
216
        self.assertEqual(['', 'dir', 'dir/subdir', 'dir/subdir/foo'],
203
217
            [path for path, ie in tree.iter_entries_by_dir()])
204
218
 
 
219
    def test_add_dir_bug_251864(self):
 
220
        """Added file turning into a dir should be detected on add dir
 
221
 
 
222
        Similar to bug 205636 but with automatic adding of directory contents.
 
223
        """
 
224
        tree = self.make_branch_and_tree(".")
 
225
        self.build_tree(["dir"]) # whoops, make a file called dir
 
226
        tree.smart_add(["dir"])
 
227
        os.remove("dir")
 
228
        self.build_tree(["dir/", "dir/file"])
 
229
        tree.smart_add(["dir"])
 
230
        tree.commit("Add dir contents")
 
231
        self.addCleanup(tree.lock_read().unlock)
 
232
        self.assertEqual([(u"dir", "directory"), (u"dir/file", "file")],
 
233
            [(t[0], t[2]) for t in tree.list_files()])
 
234
        self.assertFalse(list(tree.iter_changes(tree.basis_tree())))
 
235
 
 
236
    def test_add_subdir_file_bug_205636(self):
 
237
        """Added file turning into a dir should be detected on add dir/file"""
 
238
        tree = self.make_branch_and_tree(".")
 
239
        self.build_tree(["dir"]) # whoops, make a file called dir
 
240
        tree.smart_add(["dir"])
 
241
        os.remove("dir")
 
242
        self.build_tree(["dir/", "dir/file"])
 
243
        tree.smart_add(["dir/file"])
 
244
        tree.commit("Add file in dir")
 
245
        self.addCleanup(tree.lock_read().unlock)
 
246
        self.assertEqual([(u"dir", "directory"), (u"dir/file", "file")],
 
247
            [(t[0], t[2]) for t in tree.list_files()])
 
248
        self.assertFalse(list(tree.iter_changes(tree.basis_tree())))
 
249
 
205
250
    def test_custom_ids(self):
206
251
        sio = StringIO()
207
252
        action = test_smart_add.AddCustomIDAction(to_file=sio,
221
266
        self.addCleanup(wt.unlock)
222
267
        self.assertEqual([('', wt.path2id('')),
223
268
                          ('dir1', 'directory-dir1'),
 
269
                          ('file1', 'file-file1'),
224
270
                          ('dir1/file2', 'file-dir1%file2'),
225
 
                          ('file1', 'file-file1'),
226
271
                         ], [(path, ie.file_id) for path, ie
227
 
                                in wt.inventory.iter_entries()])
 
272
                                in wt.iter_entries_by_dir()])
228
273
 
229
274
 
230
275
class TestSmartAddConflictRelatedFiles(per_workingtree.TestCaseWithWorkingTree):
259
304
 
260
305
class TestSmartAddTreeUnicode(per_workingtree.TestCaseWithWorkingTree):
261
306
 
262
 
    _test_needs_features = [tests.UnicodeFilenameFeature]
 
307
    _test_needs_features = [features.UnicodeFilenameFeature]
263
308
 
264
309
    def setUp(self):
265
310
        super(TestSmartAddTreeUnicode, self).setUp()
267
312
        self.wt = self.make_branch_and_tree('.')
268
313
        self.overrideAttr(osutils, 'normalized_filename')
269
314
 
 
315
    def test_requires_normalized_unicode_filenames_fails_on_unnormalized(self):
 
316
        """Adding unnormalized unicode filenames fail if and only if the
 
317
        workingtree format has the requires_normalized_unicode_filenames flag
 
318
        set and the underlying filesystem doesn't normalize.
 
319
        """
 
320
        osutils.normalized_filename = osutils._accessible_normalized_filename
 
321
        if (self.workingtree_format.requires_normalized_unicode_filenames
 
322
            and sys.platform != 'darwin'):
 
323
            self.assertRaises(
 
324
                errors.NoSuchFile, self.wt.smart_add, [u'a\u030a'])
 
325
        else:
 
326
            self.wt.smart_add([u'a\u030a'])
 
327
 
270
328
    def test_accessible_explicit(self):
271
329
        osutils.normalized_filename = osutils._accessible_normalized_filename
272
 
        if isinstance(self.workingtree_format, workingtree.WorkingTreeFormat2):
273
 
            self.expectFailure(
274
 
                'With WorkingTreeFormat2, smart_add requires'
275
 
                ' normalized unicode filenames',
276
 
                self.assertRaises, errors.NoSuchFile,
277
 
                self.wt.smart_add, [u'a\u030a'])
278
 
        else:
279
 
            self.wt.smart_add([u'a\u030a'])
 
330
        if self.workingtree_format.requires_normalized_unicode_filenames:
 
331
            raise tests.TestNotApplicable(
 
332
                'Working tree format smart_add requires normalized unicode '
 
333
                'filenames')
 
334
        self.wt.smart_add([u'a\u030a'])
280
335
        self.wt.lock_read()
281
336
        self.addCleanup(self.wt.unlock)
282
337
        self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
283
338
                         [(path, ie.kind) for path,ie in
284
 
                          self.wt.inventory.iter_entries()])
 
339
                          self.wt.iter_entries_by_dir()])
285
340
 
286
341
    def test_accessible_implicit(self):
287
342
        osutils.normalized_filename = osutils._accessible_normalized_filename
288
 
        if isinstance(self.workingtree_format, workingtree.WorkingTreeFormat2):
289
 
            self.expectFailure(
290
 
                'With WorkingTreeFormat2, smart_add requires'
291
 
                ' normalized unicode filenames',
292
 
                self.assertRaises, errors.NoSuchFile,
293
 
                self.wt.smart_add, [])
294
 
        else:
295
 
            self.wt.smart_add([])
 
343
        if self.workingtree_format.requires_normalized_unicode_filenames:
 
344
            raise tests.TestNotApplicable(
 
345
                'Working tree format smart_add requires normalized unicode '
 
346
                'filenames')
 
347
        self.wt.smart_add([])
296
348
        self.wt.lock_read()
297
349
        self.addCleanup(self.wt.unlock)
298
350
        self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
299
351
                         [(path, ie.kind) for path,ie
300
 
                          in self.wt.inventory.iter_entries()])
 
352
                          in self.wt.iter_entries_by_dir()])
301
353
 
302
354
    def test_inaccessible_explicit(self):
303
355
        osutils.normalized_filename = osutils._inaccessible_normalized_filename