MCPcopy Create free account
hub / github.com/libgit2/pygit2 / read_tree

Method read_tree

pygit2/index.py:132–156  ·  view source on GitHub ↗

Replace the contents of the Index with those of the given tree, expressed either as a object or as an oid (string or ). The tree will be read recursively and all its children will also be inserted into the Index.

(self, tree: Oid | Tree | str)

Source from the content-addressed store, hash-verified

130 check_error(err)
131
132 def read_tree(self, tree: Oid | Tree | str) -> None:
133 """Replace the contents of the Index with those of the given tree,
134 expressed either as a <Tree> object or as an oid (string or <Oid>).
135
136 The tree will be read recursively and all its children will also be
137 inserted into the Index.
138 """
139 repo = self._repo
140 if isinstance(tree, str):
141 if repo is None:
142 raise TypeError('id given but no associated repository')
143 tree = repo[tree]
144
145 if isinstance(tree, Oid):
146 if repo is None:
147 raise TypeError('id given but no associated repository')
148
149 tree = repo[tree]
150 elif not isinstance(tree, Tree):
151 raise TypeError('argument must be Oid, Tree or str')
152
153 tree_cptr = ffi.new('git_tree **')
154 ffi.buffer(tree_cptr)[:] = tree._pointer[:]
155 err = C.git_index_read_tree(self._index, tree_cptr[0])
156 check_error(err)
157
158 def write_tree(self, repo: 'Repository | None' = None) -> Oid:
159 """Create a tree out of the Index. Return the <Oid> object of the

Callers 4

check_writingFunction · 0.95
write_archiveMethod · 0.95
test_read_treeFunction · 0.80

Calls 1

check_errorFunction · 0.85

Tested by 3

check_writingFunction · 0.76
test_read_treeFunction · 0.64