Submodules

A submodule is a foreign repository that is embedded within a dedicated subdirectory of the repositories tree.

class pygit2.Repository(path=None, flags=0)
Noindex:

add_submodule(url: str, path: str, link: bool = True, callbacks: RemoteCallbacks | None = None) Submodule

Add a submodule to the index. The submodule is automatically cloned.

Returns: the submodule that was added.

Parameters:

url

The URL of the submdoule.

path

The path within the parent repository to add the submodule

link

Should workdir contain a gitlink to the repo in .git/modules vs. repo directly in workdir.

callbacks

Optional RemoteCallbacks to clone the submodule.

init_submodules(submodules: Iterable[str] | None = None, overwrite: bool = False)

Initialize submodules in the repository. Just like “git submodule init”, this copies information about the submodules into “.git/config”.

Parameters:

submodules

Optional list of submodule paths or names to initialize (the submodule is ultimately resolved with Repository.lookup_submodule()). Default argument initializes all submodules.

overwrite

Flag indicating if initialization should overwrite submodule entries.

listall_submodules() list[str]

Return a list with all submodule paths in the repository.

lookup_submodule(path: str) Submodule

Look up submodule information by name or path.

update_submodules(submodules: Iterable[str] | None = None, init: bool = False, callbacks: RemoteCallbacks | None = None)

Update submodules. This will clone a missing submodule and checkout the subrepository to the commit specified in the index of the containing repository. If the submodule repository doesn’t contain the target commit (e.g. because fetchRecurseSubmodules isn’t set), then the submodule is fetched using the fetch options supplied in options.

Parameters:

submodules

Optional list of submodule paths or names (the submodule is ultimately resolved with Repository.lookup_submodule()). If you omit this parameter or pass None, all submodules will be updated.

init

If the submodule is not initialized, setting this flag to True will initialize the submodule before updating. Otherwise, this will raise an error if attempting to update an uninitialized repository.

callbacks

Optional RemoteCallbacks to clone or fetch the submodule.

The Submodule type

class pygit2.Submodule
property branch

Branch that is to be tracked by the submodule.

property head_id

Head of the submodule.

init(overwrite: bool = False)

Just like “git submodule init”, this copies information about the submodule into “.git/config”.

Parameters:

overwrite

By default, existing submodule entries will not be overwritten, but setting this to True forces them to be updated.

property name

Name of the submodule.

open()

Open the repository for a submodule.

property path

Path of the submodule.

reload(force: bool = False)

Reread submodule info from config, index, and HEAD.

Call this to reread cached submodule information for this submodule if you have reason to believe that it has changed.

Parameters:

force

Force reload even if the data doesn’t seem out of date

update(init: bool = False, callbacks: RemoteCallbacks = None)

Update a submodule. This will clone a missing submodule and checkout the subrepository to the commit specified in the index of the containing repository. If the submodule repository doesn’t contain the target commit (e.g. because fetchRecurseSubmodules isn’t set), then the submodule is fetched using the fetch options supplied in options.

Parameters:

init

If the submodule is not initialized, setting this flag to True will initialize the submodule before updating. Otherwise, this will raise an error if attempting to update an uninitialized repository.

callbacks

Optional RemoteCallbacks to clone or fetch the submodule.

property url

URL of the submodule.