230
230
def test_unicode_symlink(self):
231
231
# this tests bug #272444
232
self.requireFeature(features.SymlinkFeature)
233
self.requireFeature(features.UnicodeFilenameFeature)
232
self.requireFeature(tests.SymlinkFeature)
233
self.requireFeature(tests.UnicodeFilenameFeature)
235
235
tree = self.make_branch_and_tree('tree1')
240
240
target = u'\u03a9'
241
241
link_name = u'\N{Euro Sign}link'
242
242
os.symlink(target, 'tree1/' + link_name)
243
tree.add([link_name], ['link-id'])
243
tree.add([link_name],['link-id'])
245
245
revision1 = tree.commit('added a link to a Unicode target')
246
246
revision2 = tree.commit('this revision will be discarded')
388
388
def fake_up_revision(self, tree, revid, shape):
390
class ShapeTree(InventoryRevisionTree):
392
def __init__(self, shape):
393
self._repository = tree.branch.repository
394
self._inventory = shape
396
def get_file_text(self, file_id, path=None):
397
ie = self.root_inventory[file_id]
398
if ie.kind != "file":
400
return 'a' * ie.text_size
402
def get_file(self, file_id, path=None):
403
return StringIO(self.get_file_text(file_id))
405
389
tree.lock_write()
407
if shape.root.revision is None:
408
shape.root.revision = revid
409
builder = tree.branch.get_commit_builder(
413
committer="Foo Bar <foo@example.com>",
415
shape_tree = ShapeTree(shape)
416
base_tree = tree.branch.repository.revision_tree(
417
_mod_revision.NULL_REVISION)
418
changes = shape_tree.iter_changes(
420
list(builder.record_iter_changes(shape_tree,
421
base_tree.get_revision_id(), changes))
422
builder.finish_inventory()
423
builder.commit("Message")
391
tree.branch.repository.start_write_group()
393
if shape.root.revision is None:
394
shape.root.revision = revid
395
# Create the text records for this inventory.
396
for path, ie in shape.iter_entries():
398
lines = ['a' * ie.text_size]
401
tree.branch.repository.texts.add_lines(
402
(ie.file_id, ie.revision), [], lines)
403
sha1 = tree.branch.repository.add_inventory(revid, shape, [])
404
rev = Revision(timestamp=0,
406
committer="Foo Bar <foo@example.com>",
410
tree.branch.repository.add_revision(revid, rev)
411
tree.branch.repository.commit_write_group()
413
tree.branch.repository.abort_write_group()
450
441
self.add_dir(new_shape, new_revid, 'root-id', None, '')
452
443
def assertTransitionFromBasisToShape(self, basis_shape, basis_revid,
453
new_shape, new_revid, extra_parent=None, set_current_inventory=True):
444
new_shape, new_revid, extra_parent=None):
454
445
# set the inventory revision ids.
455
446
basis_shape.revision_id = basis_revid
456
447
new_shape.revision_id = new_revid
465
456
parents.append(extra_parent)
466
457
tree.set_parent_ids(parents)
467
458
self.fake_up_revision(tree, new_revid, new_shape)
468
if set_current_inventory:
469
# give tree an inventory of new_shape
470
tree._write_inventory(new_shape)
459
# give tree an inventory of new_shape
460
tree._write_inventory(new_shape)
471
461
self.assertDeltaApplicationResultsInExpectedBasis(tree, new_revid,
472
462
delta, new_shape)
473
463
# The tree should be internally consistent; while this is a moderately
474
464
# large hammer, this is a particularly sensitive area of code, so the
475
465
# extra assurance is well worth it.
477
# If tree.branch is remote
478
if tree.user_url != tree.branch.user_url:
479
# We have a lightweight checkout, delete both locations
480
tree.branch.bzrdir.root_transport.delete_tree('.')
481
tree.bzrdir.root_transport.delete_tree('.')
467
osutils.rmtree('tree')
483
469
def test_no_parents_just_root(self):
484
470
"""Test doing an empty commit - no parent, set a root only."""
485
basis_shape = Inventory(root_id=None) # empty tree
486
new_shape = Inventory() # tree with a root
471
basis_shape = Inventory(root_id=None) # empty tree
472
new_shape = Inventory() # tree with a root
487
473
self.assertTransitionFromBasisToShape(basis_shape, None, new_shape,
534
520
def do_file(inv, revid):
535
521
self.add_file(inv, revid, 'path-id', 'root-id', 'path', '1' * 32,
538
523
def do_link(inv, revid):
539
524
self.add_link(inv, revid, 'path-id', 'root-id', 'path', 'target')
541
525
def do_dir(inv, revid):
542
526
self.add_dir(inv, revid, 'path-id', 'root-id', 'path')
544
527
for old_factory in (do_file, do_link, do_dir):
545
528
for new_factory in (do_file, do_link, do_dir):
546
529
if old_factory == new_factory:
765
748
self.add_link(new_shape, old_revid, 'link-id-C', 'dir-id-B', 'C', 'D')
766
749
self.assertTransitionFromBasisToShape(basis_shape, old_revid,
767
750
new_shape, new_revid)
769
def test_add_files_to_empty_directory(self):
770
old_revid = 'old-parent'
771
basis_shape = Inventory(root_id=None)
772
self.add_dir(basis_shape, old_revid, 'root-id', None, '')
773
self.add_dir(basis_shape, old_revid, 'dir-id-A', 'root-id', 'A')
774
new_revid = 'new-parent'
775
new_shape = Inventory(root_id=None)
776
self.add_new_root(new_shape, old_revid, new_revid)
777
self.add_dir(new_shape, old_revid, 'dir-id-A', 'root-id', 'A')
778
self.add_file(new_shape, new_revid, 'file-id-B', 'dir-id-A', 'B',
780
self.assertTransitionFromBasisToShape(basis_shape, old_revid,
781
new_shape, new_revid, set_current_inventory=False)