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
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)
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()])
222
def test_add_dir_bug_251864(self):
223
"""Added file turning into a dir should be detected on add dir
225
Similar to bug 205636 but with automatic adding of directory contents.
227
tree = self.make_branch_and_tree(".")
228
self.build_tree(["dir"]) # whoops, make a file called dir
229
tree.smart_add(["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())))
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"])
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())))
205
253
def test_custom_ids(self):
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()])
230
278
class TestSmartAddConflictRelatedFiles(per_workingtree.TestCaseWithWorkingTree):
267
315
self.wt = self.make_branch_and_tree('.')
268
316
self.overrideAttr(osutils, 'normalized_filename')
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.
323
osutils.normalized_filename = osutils._accessible_normalized_filename
324
if (self.workingtree_format.requires_normalized_unicode_filenames
325
and sys.platform != 'darwin'):
327
errors.NoSuchFile, self.wt.smart_add, [u'a\u030a'])
329
self.wt.smart_add([u'a\u030a'])
270
331
def test_accessible_explicit(self):
271
332
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'])
333
if self.workingtree_format.requires_normalized_unicode_filenames:
334
raise tests.TestNotApplicable(
335
'Working tree format smart_add requires normalized unicode '
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()])
286
344
def test_accessible_implicit(self):
287
345
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([])
346
if self.workingtree_format.requires_normalized_unicode_filenames:
347
raise tests.TestNotApplicable(
348
'Working tree format smart_add requires normalized unicode '
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()])
302
357
def test_inaccessible_explicit(self):
303
358
osutils.normalized_filename = osutils._inaccessible_normalized_filename