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
|
from bzrlib.tests import TestCaseInTempDir
from bzrlib.branch import Branch
from bzrlib.transform import TreeTransform
from bzrlib.errors import DuplicateKey, MalformedTransform
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())
trans_id = transform.create_path('name', root)
transform.create_file('contents', trans_id)
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)
transform.apply()
self.assertEqual('contents', file('name').read())
self.assertEqual(wt.path2id('name'), 'my_pretties')
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')
transform.apply()
self.assertEqual(len(transform.find_conflicts()), 0)
self.assertEqual('contents', file('name').read())
self.assertEqual(wt.path2id('name'), 'my_pretties')
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('name2', root, trans_id2)
transform.apply()
self.assertEqual('contents', file('name').read())
self.assertEqual(wt.path2id('name'), 'my_pretties')
finally:
transform.finalize()
|