1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
from bzrlib.tests import TestCaseInTempDir
from bzrlib.branch import Branch
from bzrlib.transform import TreeTransform
from bzrlib.errors import DuplicateKey, MalformedTransform, NoSuchFile
from bzrlib.osutils import file_kind
class TestTreeTransform(TestCaseInTempDir):
def test_build(self):
branch = Branch.initialize('.')
wt = branch.working_tree()
transform = TreeTransform(wt)
try:
root = transform.get_id_tree(wt.get_root_id())
self.assertIs(transform.get_tree_parent(root), None)
imaginary_id = transform.get_tree_path_id('imaginary')
self.assertEqual(transform.get_tree_parent(imaginary_id), root)
self.assertEqual(transform.final_kind(root), 'directory')
self.assertEqual(transform.final_file_id(root), wt.get_root_id())
trans_id = transform.create_path('name', root)
self.assertIs(transform.final_file_id(trans_id), None)
self.assertRaises(NoSuchFile, transform.final_kind, trans_id)
transform.create_file('contents', trans_id)
self.assertEqual(transform.final_kind(trans_id), 'file')
self.assertRaises(DuplicateKey, transform.create_file, 'contents',
trans_id)
transform.version_file('my_pretties', trans_id)
self.assertRaises(DuplicateKey, transform.version_file,
'my_pretties', trans_id)
self.assertEqual(transform.final_file_id(trans_id), 'my_pretties')
self.assertEqual(transform.final_parent(trans_id), root)
self.assertIs(transform.final_parent(root), None)
oz_id = transform.create_path('oz', root)
transform.create_directory(oz_id)
transform.version_file('ozzie', oz_id)
transform.apply()
self.assertEqual('contents', file('name').read())
self.assertEqual(wt.path2id('name'), 'my_pretties')
self.assertEqual('directory', file_kind('oz'))
finally:
transform.finalize()
# is it safe to finalize repeatedly?
transform.finalize()
def test_convenience(self):
branch = Branch.initialize('.')
wt = branch.working_tree()
transform = TreeTransform(wt)
try:
root = transform.get_id_tree(wt.get_root_id())
trans_id = transform.new_file('name', root, 'contents',
'my_pretties')
oz = transform.new_directory('oz', root, 'oz-id')
dorothy = transform.new_directory('dorothy', oz, 'dorothy-id')
toto = transform.new_file('toto', dorothy, 'toto-contents',
'toto-id')
transform.apply()
self.assertEqual(len(transform.find_conflicts()), 0)
self.assertEqual('contents', file('name').read())
self.assertEqual(wt.path2id('name'), 'my_pretties')
self.assertEqual(wt.path2id('oz'), 'oz-id')
self.assertEqual(wt.path2id('oz/dorothy'), 'dorothy-id')
self.assertEqual(wt.path2id('oz/dorothy/toto'), 'toto-id')
self.assertEqual('toto-contents', file('oz/dorothy/toto').read())
finally:
transform.finalize()
def test_conflicts(self):
branch = Branch.initialize('.')
wt = branch.working_tree()
transform = TreeTransform(wt)
try:
root = transform.get_id_tree(wt.get_root_id())
trans_id = transform.new_file('name', root, 'contents',
'my_pretties')
self.assertEqual(len(transform.find_conflicts()), 0)
trans_id2 = transform.new_file('name', root, 'Crontents', 'toto')
self.assertEqual(transform.find_conflicts(),
[('duplicate', trans_id, trans_id2)])
self.assertRaises(MalformedTransform, transform.apply)
transform.adjust_path('name', trans_id, trans_id2)
self.assertEqual(transform.find_conflicts(),
[('non-directory parent', trans_id)])
tinman_id = transform.get_tree_path_id('tinman')
transform.adjust_path('name', tinman_id, trans_id2)
self.assertEqual(transform.find_conflicts(),
[('unversioned parent', tinman_id),
('missing parent', tinman_id)])
lion_id = transform.create_path('lion', root)
self.assertEqual(transform.find_conflicts(),
[('unversioned parent', tinman_id),
('missing parent', tinman_id)])
transform.adjust_path('name', lion_id, trans_id2)
self.assertEqual(transform.find_conflicts(),
[('unversioned parent', lion_id),
('missing parent', lion_id)])
transform.version_file("Courage", lion_id)
self.assertEqual(transform.find_conflicts(),
[('missing parent', lion_id),
('versioning no contents', lion_id)])
transform.adjust_path('name2', root, trans_id2)
self.assertEqual(transform.find_conflicts(),
[('versioning no contents', lion_id)])
transform.create_file('Contents, okay?', lion_id)
transform.adjust_path('name2', trans_id2, trans_id2)
self.assertEqual(transform.find_conflicts(),
[('parent loop', trans_id2),
('non-directory parent', trans_id2)])
transform.adjust_path('name2', root, trans_id2)
transform.apply()
self.assertEqual('contents', file('name').read())
self.assertEqual(wt.path2id('name'), 'my_pretties')
finally:
transform.finalize()
|