259
264
in wt.inventory.iter_entries()])
267
class TestAddFrom(TestCaseWithTransport):
268
"""Tests for AddFromBaseAction"""
270
def make_base_tree(self):
271
self.base_tree = self.make_branch_and_tree('base')
272
self.build_tree(['base/a', 'base/b',
273
'base/dir/', 'base/dir/a',
277
self.base_tree.add(['a', 'b', 'dir', 'dir/a',
278
'dir/subdir', 'dir/subdir/b'])
279
self.base_tree.commit('creating initial tree.')
281
def add_helper(self, base_tree, base_path, new_tree, file_list,
284
base_tree.lock_read()
286
new_tree.lock_write()
288
action = AddFromBaseAction(base_tree, base_path,
290
should_print=should_print)
291
smart_add_tree(new_tree, file_list, action=action)
296
return to_file.getvalue()
298
def test_copy_all(self):
299
self.make_base_tree()
300
new_tree = self.make_branch_and_tree('new')
306
self.build_tree(['new/' + fn for fn in files])
307
self.add_helper(self.base_tree, '', new_tree, ['new'])
310
base_file_id = self.base_tree.path2id(fn)
311
new_file_id = new_tree.path2id(fn)
312
self.assertEqual(base_file_id, new_file_id)
314
def test_copy_from_dir(self):
315
self.make_base_tree()
316
new_tree = self.make_branch_and_tree('new')
318
self.build_tree(['new/a', 'new/b', 'new/c',
319
'new/subdir/', 'new/subdir/b', 'new/subdir/d'])
320
self.add_helper(self.base_tree, 'dir', new_tree, ['new'])
322
# We 'a' and 'b' exist in the root, and they are being added
323
# in a new 'root'. Since ROOT ids are not unique, we will
325
# TODO: This will probably change once trees have a unique root id
326
# It is definitely arguable that 'a' should get the id of
327
# 'dir/a' not of 'a'.
328
self.assertEqual(self.base_tree.path2id('a'),
329
new_tree.path2id('a'))
330
self.assertEqual(self.base_tree.path2id('b'),
331
new_tree.path2id('b'))
333
# Because we specified 'dir/' as the base path, and we have
334
# nothing named 'subdir' in the base tree, we should grab the
336
self.assertEqual(self.base_tree.path2id('dir/subdir'),
337
new_tree.path2id('subdir'))
338
self.assertEqual(self.base_tree.path2id('dir/subdir/b'),
339
new_tree.path2id('subdir/b'))
341
# These should get newly generated ids
342
c_id = new_tree.path2id('c')
343
self.assertNotEqual(None, c_id)
344
self.failIf(c_id in self.base_tree)
346
d_id = new_tree.path2id('subdir/d')
347
self.assertNotEqual(None, d_id)
348
self.failIf(d_id in self.base_tree)
350
def test_copy_existing_dir(self):
351
self.make_base_tree()
352
new_tree = self.make_branch_and_tree('new')
353
self.build_tree(['new/subby/', 'new/subby/a', 'new/subby/b'])
355
subdir_file_id = self.base_tree.path2id('dir/subdir')
356
new_tree.add(['subby'], [subdir_file_id])
357
self.add_helper(self.base_tree, '', new_tree, ['new'])
358
# Because 'subby' already points to subdir, we should add
359
# 'b' with the same id
360
self.assertEqual(self.base_tree.path2id('dir/subdir/b'),
361
new_tree.path2id('subby/b'))
363
# 'subby/a' should be added with a new id because there is no
364
# matching path or child of 'subby'.
365
a_id = new_tree.path2id('subby/a')
366
self.assertNotEqual(None, a_id)
367
self.failIf(a_id in self.base_tree)
262
370
class TestAddNonNormalized(TestCaseWithTransport):