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

Class SubmoduleCollection

pygit2/submodules.py:184–394  ·  view source on GitHub ↗

Collection of submodules in a repository.

Source from the content-addressed store, hash-verified

182
183
184class SubmoduleCollection:
185 """Collection of submodules in a repository."""
186
187 def __init__(self, repository: BaseRepository):
188 self._repository = repository
189
190 def __getitem__(self, name: str | Path) -> Submodule:
191 """
192 Look up submodule information by name or path.
193 Raises KeyError if there is no such submodule.
194 """
195 csub = ffi.new('git_submodule **')
196 cpath = ffi.new('char[]', to_bytes(name))
197
198 err = C.git_submodule_lookup(csub, self._repository._repo, cpath)
199 check_error(err)
200 return Submodule._from_c(self._repository, csub[0])
201
202 def __contains__(self, name: str) -> bool:
203 return self.get(name) is not None
204
205 def __iter__(self) -> Iterator[Submodule]:
206 for s in self._repository.listall_submodules():
207 yield self[s]
208
209 def get(self, name: str) -> Submodule | None:
210 """
211 Look up submodule information by name or path.
212 Unlike __getitem__, this returns None if the submodule is not found.
213 """
214 try:
215 return self[name]
216 except KeyError:
217 return None
218
219 def add(
220 self,
221 url: str,
222 path: str,
223 link: bool = True,
224 callbacks: Optional[RemoteCallbacks] = None,
225 depth: int = 0,
226 ) -> Submodule:
227 """
228 Add a submodule to the index.
229 The submodule is automatically cloned.
230
231 Returns: the submodule that was added.
232
233 Parameters:
234
235 url
236 The URL of the submodule.
237
238 path
239 The path within the parent repository to add the submodule
240
241 link

Callers 1

_common_initMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…