226
226
], [(path, ie.file_id) for path, ie
227
227
in wt.inventory.iter_entries()])
229
def make_unicode_containing_tree(self):
231
self.build_tree([u'a\u030a'])
233
raise tests.TestSkipped('Filesystem cannot create unicode filenames')
230
class TestSmartAddConflictRelatedFiles(per_workingtree.TestCaseWithWorkingTree):
232
def make_tree_with_text_conflict(self):
233
tb = self.make_branch_and_tree('base')
234
self.build_tree_contents([('base/file', 'content in base')])
236
tb.commit('Adding file')
238
t1 = tb.bzrdir.sprout('t1').open_workingtree()
240
self.build_tree_contents([('base/file', 'content changed in base')])
241
tb.commit('Changing file in base')
243
self.build_tree_contents([('t1/file', 'content in t1')])
244
t1.commit('Changing file in t1')
245
t1.merge_from_branch(tb.branch)
248
def test_cant_add_generated_files_implicitly(self):
249
t = self.make_tree_with_text_conflict()
250
added, ignored = t.smart_add([t.basedir])
251
self.assertEqual(([], {}), (added, ignored))
253
def test_can_add_generated_files_explicitly(self):
254
fnames = ['file.%s' % s for s in ('BASE', 'THIS', 'OTHER')]
255
t = self.make_tree_with_text_conflict()
256
added, ignored = t.smart_add([t.basedir + '/%s' % f for f in fnames])
257
self.assertEqual((fnames, {}), (added, ignored))
260
class TestSmartAddTreeUnicode(per_workingtree.TestCaseWithWorkingTree):
262
_test_needs_features = [tests.UnicodeFilenameFeature]
265
super(TestSmartAddTreeUnicode, self).setUp()
266
self.build_tree([u'a\u030a'])
234
267
self.wt = self.make_branch_and_tree('.')
268
self.overrideAttr(osutils, 'normalized_filename')
236
270
def test_accessible_explicit(self):
237
self.make_unicode_containing_tree()
238
orig = osutils.normalized_filename
239
271
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'])
241
279
self.wt.smart_add([u'a\u030a'])
243
self.addCleanup(self.wt.unlock)
244
self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
245
[(path, ie.kind) for path,ie in
246
self.wt.inventory.iter_entries()])
248
osutils.normalized_filename = orig
281
self.addCleanup(self.wt.unlock)
282
self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
283
[(path, ie.kind) for path,ie in
284
self.wt.inventory.iter_entries()])
250
286
def test_accessible_implicit(self):
251
self.make_unicode_containing_tree()
252
orig = osutils.normalized_filename
253
287
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, [])
255
295
self.wt.smart_add([])
257
self.addCleanup(self.wt.unlock)
258
self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
259
[(path, ie.kind) for path,ie in
260
self.wt.inventory.iter_entries()])
262
osutils.normalized_filename = orig
297
self.addCleanup(self.wt.unlock)
298
self.assertEqual([('', 'directory'), (u'\xe5', 'file')],
299
[(path, ie.kind) for path,ie
300
in self.wt.inventory.iter_entries()])
264
302
def test_inaccessible_explicit(self):
265
self.make_unicode_containing_tree()
266
orig = osutils.normalized_filename
267
303
osutils.normalized_filename = osutils._inaccessible_normalized_filename
269
self.assertRaises(errors.InvalidNormalization,
270
self.wt.smart_add, [u'a\u030a'])
272
osutils.normalized_filename = orig
304
self.assertRaises(errors.InvalidNormalization,
305
self.wt.smart_add, [u'a\u030a'])
274
307
def test_inaccessible_implicit(self):
275
self.make_unicode_containing_tree()
276
orig = osutils.normalized_filename
277
308
osutils.normalized_filename = osutils._inaccessible_normalized_filename
279
# TODO: jam 20060701 In the future, this should probably
280
# just ignore files that don't fit the normalization
281
# rules, rather than exploding
282
self.assertRaises(errors.InvalidNormalization,
283
self.wt.smart_add, [])
285
osutils.normalized_filename = orig
309
# TODO: jam 20060701 In the future, this should probably
310
# just ignore files that don't fit the normalization
311
# rules, rather than exploding
312
self.assertRaises(errors.InvalidNormalization, self.wt.smart_add, [])