19
19
from bzrlib.bzrdir import BzrDir
20
from bzrlib.conflicts import (DuplicateEntry, DuplicateID, MissingParent,
21
UnversionedParent, ParentLoop)
20
22
from bzrlib.errors import (DuplicateKey, MalformedTransform, NoSuchFile,
21
23
ReusingTransform, CantMoveRoot, NotVersionedError,
22
24
ExistingLimbo, ImmortalLimbo, LockError)
23
25
from bzrlib.osutils import file_kind, has_symlinks, pathjoin
24
26
from bzrlib.merge import Merge3Merger
25
from bzrlib.tests import TestCaseInTempDir, TestSkipped
27
from bzrlib.tests import TestCaseInTempDir, TestSkipped, TestCase
26
28
from bzrlib.transform import (TreeTransform, ROOT_PARENT, FinalPaths,
27
29
resolve_conflicts, cook_conflicts,
28
conflicts_strings, find_interesting, build_tree)
30
find_interesting, build_tree, get_backup_name)
30
32
class TestTreeTransform(TestCaseInTempDir):
188
190
transform3.adjust_path('tip', root_id, tip_id)
189
191
transform3.apply()
193
def test_add_del(self):
194
start, root = self.get_transform()
195
start.new_directory('a', root, 'a')
197
transform, root = self.get_transform()
198
transform.delete_versioned(transform.trans_id_tree_file_id('a'))
199
transform.new_directory('a', root, 'a')
191
202
def test_unversioning(self):
192
203
create_tree, root = self.get_transform()
193
204
parent_id = create_tree.new_directory('parent', root, 'parent-id')
392
403
tt, emerald, oz, old_dorothy, new_dorothy = self.get_conflicted()
393
404
raw_conflicts = resolve_conflicts(tt)
394
405
cooked_conflicts = cook_conflicts(raw_conflicts, tt)
395
duplicate = ('duplicate', 'Moved existing file to', 'dorothy.moved',
396
None, 'dorothy', 'dorothy-id')
406
duplicate = DuplicateEntry('Moved existing file to', 'dorothy.moved',
407
'dorothy', None, 'dorothy-id')
397
408
self.assertEqual(cooked_conflicts[0], duplicate)
398
duplicate_id = ('duplicate id', 'Unversioned existing file',
399
'dorothy.moved', None, 'dorothy', 'dorothy-id')
409
duplicate_id = DuplicateID('Unversioned existing file',
410
'dorothy.moved', 'dorothy', None,
400
412
self.assertEqual(cooked_conflicts[1], duplicate_id)
401
missing_parent = ('missing parent', 'Not deleting', 'oz', 'oz-id')
413
missing_parent = MissingParent('Not deleting', 'oz', 'oz-id')
402
414
self.assertEqual(cooked_conflicts[2], missing_parent)
403
unversioned_parent = ('unversioned parent',
404
'Versioned directory', 'oz', 'oz-id')
415
unversioned_parent = UnversionedParent('Versioned directory', 'oz',
405
417
self.assertEqual(cooked_conflicts[3], unversioned_parent)
406
parent_loop = ('parent loop', 'Cancelled move', 'oz/emeraldcity',
407
'emerald-id', 'oz/emeraldcity', 'emerald-id')
418
parent_loop = ParentLoop('Cancelled move', 'oz/emeraldcity',
419
'oz/emeraldcity', 'emerald-id', 'emerald-id')
408
420
self.assertEqual(cooked_conflicts[4], parent_loop)
409
421
self.assertEqual(len(cooked_conflicts), 5)
414
426
raw_conflicts = resolve_conflicts(tt)
415
427
cooked_conflicts = cook_conflicts(raw_conflicts, tt)
417
conflicts_s = list(conflicts_strings(cooked_conflicts))
429
conflicts_s = [str(c) for c in cooked_conflicts]
418
430
self.assertEqual(len(cooked_conflicts), len(conflicts_s))
419
431
self.assertEqual(conflicts_s[0], 'Conflict adding file dorothy. '
420
432
'Moved existing file to '
688
702
self.assertIs(os.path.isdir('b/foo'), True)
689
703
self.assertEqual(file('b/foo/bar', 'rb').read(), "contents")
690
704
self.assertEqual(os.readlink('b/foo/baz'), 'a/foo/bar')
706
class MockTransform(object):
708
def has_named_child(self, by_parent, parent_id, name):
709
for child_id in by_parent[parent_id]:
713
elif name == "name.~%s~" % child_id:
717
class MockEntry(object):
719
object.__init__(self)
722
class TestGetBackupName(TestCase):
723
def test_get_backup_name(self):
725
name = get_backup_name(MockEntry(), {'a':[]}, 'a', tt)
726
self.assertEqual(name, 'name.~1~')
727
name = get_backup_name(MockEntry(), {'a':['1']}, 'a', tt)
728
self.assertEqual(name, 'name.~2~')
729
name = get_backup_name(MockEntry(), {'a':['2']}, 'a', tt)
730
self.assertEqual(name, 'name.~1~')
731
name = get_backup_name(MockEntry(), {'a':['2'], 'b':[]}, 'b', tt)
732
self.assertEqual(name, 'name.~1~')
733
name = get_backup_name(MockEntry(), {'a':['1', '2', '3']}, 'a', tt)
734
self.assertEqual(name, 'name.~4~')