~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_workingtree/test_smart_add.py

  • Committer: Patch Queue Manager
  • Date: 2016-01-31 13:36:59 UTC
  • mfrom: (6613.1.5 1538480-match-hostname)
  • Revision ID: pqm@pqm.ubuntu.com-20160131133659-ouy92ee2wlv9xz8m
(vila) Use ssl.match_hostname instead of our own. (Vincent Ladeuil)

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")
122
135
 
123
136
        self.build_tree(build_paths)
124
137
        wt = self.make_branch_and_tree('.')
 
138
        if wt.user_url != wt.branch.user_url:
 
139
            # Lightweight checkout, make sure we have a repo location.
 
140
            wt.branch.bzrdir.root_transport.mkdir('original')
125
141
        child_tree = self.make_branch_and_tree('original/child')
126
142
        wt.smart_add((".",))
127
143
        for path in paths:
151
167
        self.build_tree(tree_shape)
152
168
        wt.smart_add(add_paths)
153
169
        for path in expected_paths:
154
 
            self.assertNotEqual(wt.path2id(path), None, "No id added for %s" % path)
 
170
            self.assertNotEqual(wt.path2id(path), None,
 
171
                "No id added for %s" % path)
155
172
 
156
173
    def test_add_non_existant(self):
157
174
        """Test smart-adding a file that does not exist."""
202
219
        self.assertEqual(['', 'dir', 'dir/subdir', 'dir/subdir/foo'],
203
220
            [path for path, ie in tree.iter_entries_by_dir()])
204
221
 
 
222
    def test_add_dir_bug_251864(self):
 
223
        """Added file turning into a dir should be detected on add dir
 
224
 
 
225
        Similar to bug 205636 but with automatic adding of directory contents.
 
226
        """
 
227
        tree = self.make_branch_and_tree(".")
 
228
        self.build_tree(["dir"]) # whoops, make a file called dir
 
229
        tree.smart_add(["dir"])
 
230
        os.remove("dir")
 
231
        self.build_tree(["dir/", "dir/file"])
 
232
        tree.smart_add(["dir"])
 
233
        tree.commit("Add dir contents")
 
234
        self.addCleanup(tree.lock_read().unlock)
 
235
        self.assertEqual([(u"dir", "directory"), (u"dir/file", "file")],
 
236
            [(t[0], t[2]) for t in tree.list_files()])
 
237
        self.assertFalse(list(tree.iter_changes(tree.basis_tree())))
 
238
 
 
239
    def test_add_subdir_file_bug_205636(self):
 
240
        """Added file turning into a dir should be detected on add dir/file"""
 
241
        tree = self.make_branch_and_tree(".")
 
242
        self.build_tree(["dir"]) # whoops, make a file called dir
 
243
        tree.smart_add(["dir"])
 
244
        os.remove("dir")
 
245
        self.build_tree(["dir/", "dir/file"])
 
246
        tree.smart_add(["dir/file"])
 
247
        tree.commit("Add file in dir")
 
248
        self.addCleanup(tree.lock_read().unlock)
 
249
        self.assertEqual([(u"dir", "directory"), (u"dir/file", "file")],
 
250
            [(t[0], t[2]) for t in tree.list_files()])
 
251
        self.assertFalse(list(tree.iter_changes(tree.basis_tree())))
 
252
 
205
253
    def test_custom_ids(self):
206
254
        sio = StringIO()
207
255
        action = test_smart_add.AddCustomIDAction(to_file=sio,
221
269
        self.addCleanup(wt.unlock)
222
270
        self.assertEqual([('', wt.path2id('')),
223
271
                          ('dir1', 'directory-dir1'),
 
272
                          ('file1', 'file-file1'),
224
273
                          ('dir1/file2', 'file-dir1%file2'),
225
 
                          ('file1', 'file-file1'),
226
274
                         ], [(path, ie.file_id) for path, ie
227
 
                                in wt.inventory.iter_entries()])
 
275
                                in wt.iter_entries_by_dir()])
228
276
 
229
277
 
230
278
class TestSmartAddConflictRelatedFiles(per_workingtree.TestCaseWithWorkingTree):
259
307
 
260
308
class TestSmartAddTreeUnicode(per_workingtree.TestCaseWithWorkingTree):
261
309
 
262
 
    _test_needs_features = [tests.UnicodeFilenameFeature]
 
310
    _test_needs_features = [features.UnicodeFilenameFeature]
263
311
 
264
312
    def setUp(self):
265
313
        super(TestSmartAddTreeUnicode, self).setUp()
267
315
        self.wt = self.make_branch_and_tree('.')
268
316
        self.overrideAttr(osutils, 'normalized_filename')
269
317
 
 
318
    def test_requires_normalized_unicode_filenames_fails_on_unnormalized(self):
 
319
        """Adding unnormalized unicode filenames fail if and only if the
 
320
        workingtree format has the requires_normalized_unicode_filenames flag
 
321
        set and the underlying filesystem doesn't normalize.
 
322
        """
 
323
        osutils.normalized_filename = osutils._accessible_normalized_filename
 
324
        if (self.workingtree_format.requires_normalized_unicode_filenames
 
325
            and sys.platform != 'darwin'):
 
326
            self.assertRaises(
 
327
                errors.NoSuchFile, self.wt.smart_add, [u'a\u030a'])
 
328
        else:
 
329
            self.wt.smart_add([u'a\u030a'])
 
330
 
270
331
    def test_accessible_explicit(self):
271
332
        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'])
 
333
        if self.workingtree_format.requires_normalized_unicode_filenames:
 
334
            raise tests.TestNotApplicable(
 
335
                'Working tree format smart_add requires normalized unicode '
 
336
                'filenames')
 
337
        self.wt.smart_add([u'a\u030a'])
280
338
        self.wt.lock_read()
281
339
        self.addCleanup(self.wt.unlock)
282
340
        self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
283
341
                         [(path, ie.kind) for path,ie in
284
 
                          self.wt.inventory.iter_entries()])
 
342
                          self.wt.iter_entries_by_dir()])
285
343
 
286
344
    def test_accessible_implicit(self):
287
345
        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([])
 
346
        if self.workingtree_format.requires_normalized_unicode_filenames:
 
347
            raise tests.TestNotApplicable(
 
348
                'Working tree format smart_add requires normalized unicode '
 
349
                'filenames')
 
350
        self.wt.smart_add([])
296
351
        self.wt.lock_read()
297
352
        self.addCleanup(self.wt.unlock)
298
353
        self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
299
354
                         [(path, ie.kind) for path,ie
300
 
                          in self.wt.inventory.iter_entries()])
 
355
                          in self.wt.iter_entries_by_dir()])
301
356
 
302
357
    def test_inaccessible_explicit(self):
303
358
        osutils.normalized_filename = osutils._inaccessible_normalized_filename