93
93
self.assertNotEqual(wt.path2id(path), None)
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')
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)
106
['skipping nested tree %r' % nested_wt.basedir], warnings)
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)
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()])
219
def test_add_dir_bug_251864(self):
220
"""Added file turning into a dir should be detected on add dir
222
Similar to bug 205636 but with automatic adding of directory contents.
224
tree = self.make_branch_and_tree(".")
225
self.build_tree(["dir"]) # whoops, make a file called dir
226
tree.smart_add(["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())))
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"])
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())))
205
250
def test_custom_ids(self):
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()])
230
275
class TestSmartAddConflictRelatedFiles(per_workingtree.TestCaseWithWorkingTree):
267
312
self.wt = self.make_branch_and_tree('.')
268
313
self.overrideAttr(osutils, 'normalized_filename')
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.
320
osutils.normalized_filename = osutils._accessible_normalized_filename
321
if (self.workingtree_format.requires_normalized_unicode_filenames
322
and sys.platform != 'darwin'):
324
errors.NoSuchFile, self.wt.smart_add, [u'a\u030a'])
326
self.wt.smart_add([u'a\u030a'])
270
328
def test_accessible_explicit(self):
271
329
osutils.normalized_filename = osutils._accessible_normalized_filename
272
if isinstance(self.workingtree_format, workingtree.WorkingTreeFormat2):
274
'With WorkingTreeFormat2, smart_add requires'
275
' normalized unicode filenames',
276
self.assertRaises, errors.NoSuchFile,
277
self.wt.smart_add, [u'a\u030a'])
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 '
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()])
286
341
def test_accessible_implicit(self):
287
342
osutils.normalized_filename = osutils._accessible_normalized_filename
288
if isinstance(self.workingtree_format, workingtree.WorkingTreeFormat2):
290
'With WorkingTreeFormat2, smart_add requires'
291
' normalized unicode filenames',
292
self.assertRaises, errors.NoSuchFile,
293
self.wt.smart_add, [])
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 '
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()])
302
354
def test_inaccessible_explicit(self):
303
355
osutils.normalized_filename = osutils._inaccessible_normalized_filename