38
class BadReferenceTarget(errors.InternalBzrError):
40
_fmt = "Can't add reference to %(other_tree)s into %(tree)s." \
43
def __init__(self, tree, other_tree, reason):
45
self.other_tree = other_tree
38
49
class MutableTree(tree.Tree):
39
50
"""A MutableTree is a specialisation of Tree which is able to be mutated.
127
138
self._add(files, ids, kinds)
129
140
def add_reference(self, sub_tree):
130
"""Add a TreeReference to the tree, pointing at sub_tree"""
141
"""Add a TreeReference to the tree, pointing at sub_tree.
143
:param sub_tree: subtree to add.
131
145
raise errors.UnsupportedOperation(self.add_reference, self)
133
def _add_reference(self, sub_tree):
134
"""Standard add_reference implementation, for use by subclasses"""
136
sub_tree_path = self.relpath(sub_tree.basedir)
137
except errors.PathNotChild:
138
raise errors.BadReferenceTarget(self, sub_tree,
139
'Target not inside tree.')
140
sub_tree_id = sub_tree.get_root_id()
141
if sub_tree_id == self.get_root_id():
142
raise errors.BadReferenceTarget(self, sub_tree,
143
'Trees have the same root id.')
144
if self.has_id(sub_tree_id):
145
raise errors.BadReferenceTarget(self, sub_tree,
146
'Root id already present in tree')
147
self._add([sub_tree_path], [sub_tree_id], ['tree-reference'])
149
147
def _add(self, files, ids, kinds):
150
148
"""Helper function for add - updates the inventory.