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

Method add

pygit2/submodules.py:219–282  ·  view source on GitHub ↗

Add a submodule to the index. The submodule is automatically cloned. Returns: the submodule that was added. Parameters: url The URL of the submodule. path The path within the parent repository to add the submodule

(
        self,
        url: str,
        path: str,
        link: bool = True,
        callbacks: Optional[RemoteCallbacks] = None,
        depth: int = 0,
    )

Source from the content-addressed store, hash-verified

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
242 Should workdir contain a gitlink to the repo in `.git/modules` vs. repo directly in workdir.
243
244 callbacks
245 Optional RemoteCallbacks to clone the submodule.
246
247 depth
248 Number of commits to fetch.
249 The default is 0 (full commit history).
250 """
251 csub = ffi.new('git_submodule **')
252 curl = ffi.new('char[]', to_bytes(url))
253 cpath = ffi.new('char[]', to_bytes(path))
254 gitlink = 1 if link else 0
255
256 err = C.git_submodule_add_setup(
257 csub, self._repository._repo, curl, cpath, gitlink
258 )
259 check_error(err)
260
261 submodule_instance = Submodule._from_c(self._repository, csub[0])
262
263 # Prepare options
264 opts = ffi.new('git_submodule_update_options *')
265 C.git_submodule_update_options_init(
266 opts, C.GIT_SUBMODULE_UPDATE_OPTIONS_VERSION
267 )
268 opts.fetch_opts.depth = depth
269
270 with git_fetch_options(callbacks, opts=opts.fetch_opts) as payload:
271 crepo = ffi.new('git_repository **')
272 err = C.git_submodule_clone(crepo, submodule_instance._subm, opts)
273 payload.check_error(err)
274
275 # Clean up submodule repository
276 from .repository import Repository

Callers

nothing calls this directly

Calls 5

to_bytesFunction · 0.85
check_errorFunction · 0.85
git_fetch_optionsFunction · 0.85
check_errorMethod · 0.80
_from_cMethod · 0.45

Tested by

no test coverage detected