26
26
class TestBasisInventory(TestCaseWithWorkingTree):
28
28
def test_create(self):
29
# This test is not applicable to DirState based trees: the basis is
30
# not separate is mandatory.
31
if isinstance(self.workingtree_format,
32
bzrlib.workingtree_4.WorkingTreeFormat4):
29
34
# TODO: jam 20051218 this probably should add more than just
30
35
# a couple files to the inventory
51
56
t._control_files.get_utf8('basis-inventory-cache')
53
58
basis_inv_txt = t.read_basis_inventory()
54
basis_inv = bzrlib.xml6.serializer_v6.read_inventory_from_string(basis_inv_txt)
59
basis_inv = bzrlib.xml7.serializer_v7.read_inventory_from_string(basis_inv_txt)
55
60
self.assertEquals('r2', basis_inv.revision_id)
56
61
store_inv = b.repository.get_inventory('r2')
60
65
def test_wrong_format(self):
61
66
"""WorkingTree.basis safely ignores junk basis inventories"""
67
# This test is not applicable to DirState based trees: the basis is
68
# not separate and ignorable.
69
if isinstance(self.workingtree_format,
70
bzrlib.workingtree_4.WorkingTreeFormat4):
62
72
t = self.make_branch_and_tree('.')
64
74
open('a', 'wb').write('a\n')
73
83
t._control_files.put_utf8('basis-inventory-cache',
74
84
'<inventory format="pi"/>')
77
def test_basis_inv_gets_revision(self):
78
"""When the inventory of the basis tree has no revision id it gets set.
80
It gets set during set_parent_trees() or set_parent_ids().
82
tree = self.make_branch_and_tree('.')
84
# TODO change this to use CommitBuilder
85
inv = inventory.Inventory(revision_id='r1')
86
inv.root.revision = 'r1'
87
inv_lines = tree.branch.repository.serialise_inventory(inv).split('\n')
88
inv_lines = [(l + '\n') for l in inv_lines if l is not None]
89
tree.branch.repository.control_weaves.get_weave('inventory',
90
tree.branch.repository.get_transaction()
91
).add_lines('r1', [], inv_lines)
92
rev = Revision(timestamp=0,
94
committer="Foo Bar <foo@example.com>",
99
tree.branch.repository.add_revision('r1', rev)
101
tree.branch.append_revision('r1')
102
tree.set_parent_trees(
103
[('r1', tree.branch.repository.revision_tree('r1'))])
104
# TODO: we should deserialise the file here, rather than peeking
105
# without parsing, but to do this properly needs a serialiser on the
106
# tree object that abstracts whether it is xml/rio/etc.
107
self.assertContainsRe(
108
tree._control_files.get_utf8('basis-inventory-cache').read(),