submodule¶
For git-submodule(1).
Overview¶
Manage git submodules using GitSubmoduleManager (collection-level)
and GitSubmoduleEntryCmd (per-submodule operations).
Note
GitSubmoduleCmd is the legacy interface. Use git.submodules
(GitSubmoduleManager) for the new
Manager/Cmd pattern.
Examples¶
List submodules — a repository without any simply returns an empty list — and
sync submodule URLs into .git/config:
>>> from libvcs.cmd.git import Git
>>> git = Git(path=example_git_repo.path)
>>> git.submodules.ls()
[]
>>> git.submodules.sync()
''
Register a submodule with add(),
then initialize and fetch it through the entry’s
init() and
update() — each method’s API
reference below carries a runnable example.
API Reference¶
Wrap some of git-submodule(1), manager.
Examples
>>> GitSubmoduleManager(path=tmp_path) <GitSubmoduleManager path=...>
>>> GitSubmoduleManager(path=tmp_path).run('status', trim=True) 'fatal: not a git repository (or any of the parent directories): .git'
>>> GitSubmoduleManager(path=example_git_repo.path).run('status') ''
Run a command against a git repository’s submodules.
Wraps git submodule.
Examples
>>> GitSubmoduleManager(path=example_git_repo.path).run('status') ''
Add a new submodule.
Examples
>>> git_remote_repo = create_git_remote_repo() >>> result = GitSubmoduleManager(path=example_git_repo.path).add( ... f'file://{git_remote_repo}', ... 'vendor/example' ... ) >>> 'error' in result.lower() or 'fatal' in result.lower() or result == '' True
Update submodules.
- Parameters:
path (
list[str] |str|None) – Specific submodule path(s) to update.init (
bool) – Initialize if not already.force (
bool) – Discard local changes.checkout (
bool) – Check out superproject’s recorded commit.rebase (
bool) – Rebase current branch onto commit.merge (
bool) – Merge commit into current branch.recursive (
bool) – Recurse into nested submodules.remote (
bool) – Use remote tracking branch.log_in_real_time (
bool)
- Return type:
Examples
>>> GitSubmoduleManager(path=example_git_repo.path).update() ''
>>> GitSubmoduleManager(path=example_git_repo.path).update(init=True) ''
Run command in each submodule.
Examples
>>> result = GitSubmoduleManager(path=example_git_repo.path).foreach( ... 'git status' ... ) >>> isinstance(result, str) True
Show commit summary for submodules.
- Parameters:
- Return type:
Examples
>>> result = GitSubmoduleManager(path=example_git_repo.path).summary() >>> isinstance(result, str) True
Absorb git directories into superproject.
Examples
>>> result = GitSubmoduleManager(path=example_git_repo.path).absorbgitdirs() >>> isinstance(result, str) True
Parse submodule status output into structured data.
Examples
>>> submodules = GitSubmoduleManager(path=example_git_repo.path)._ls() >>> isinstance(submodules, list) True
List submodules as
GitSubmoduleobjects.- Parameters:
- Returns:
List of submodules with ORM-like filtering.
- Return type:
Examples
>>> submodules = GitSubmoduleManager(path=example_git_repo.path).ls() >>> isinstance(submodules, QueryList) True
Get a specific submodule.
- Parameters:
- Returns:
The matching submodule.
- Return type:
- Raises:
ObjectDoesNotExist– If no matching submodule found.MultipleObjectsReturned– If multiple submodules match.
Examples
>>> from libvcs._internal.query_list import ObjectDoesNotExist >>> submodules = GitSubmoduleManager(path=example_git_repo.path) >>> try: ... submodules.get(path='vendor/lib') ... except ObjectDoesNotExist: ... True True
Filter submodules.
- Parameters:
- Returns:
Filtered list of submodules.
- Return type:
Examples
>>> submodules = GitSubmoduleManager(path=example_git_repo.path).filter() >>> isinstance(submodules, QueryList) True
Bases:
objectRepresent a git submodule.
Current commit SHA of the submodule.
Configured branch for the submodule.
Status prefix: ‘-’ not initialized, ‘+’ differs, ‘U’ conflicts.
Check if submodule is initialized.
Bases:
objectRun git commands targeting a specific submodule.
Wrap some of git-submodule(1) for specific submodule operations.
Examples
>>> GitSubmoduleEntryCmd( ... path=example_git_repo.path, ... submodule_path='vendor/lib', ... ) <GitSubmoduleEntryCmd vendor/lib>
Run a command against a specific submodule.
Wraps git submodule.
Examples
>>> GitSubmoduleEntryCmd( ... path=example_git_repo.path, ... submodule_path='vendor/lib', ... ).run('status') ''
Initialize this submodule.
Examples
>>> result = GitSubmoduleEntryCmd( ... path=example_git_repo.path, ... submodule_path='vendor/lib', ... ).init() >>> 'error' in result.lower() or result == '' True
Update this submodule.
- Parameters:
init (
bool) – Initialize if not already.force (
bool) – Discard local changes.checkout (
bool) – Check out superproject’s recorded commit.rebase (
bool) – Rebase current branch onto commit.merge (
bool) – Merge commit into current branch.recursive (
bool) – Recurse into nested submodules.remote (
bool) – Use remote tracking branch.log_in_real_time (
bool)
- Return type:
Examples
>>> result = GitSubmoduleEntryCmd( ... path=example_git_repo.path, ... submodule_path='vendor/lib', ... ).update() >>> 'error' in result.lower() or result == '' True
Unregister this submodule.
Examples
>>> result = GitSubmoduleEntryCmd( ... path=example_git_repo.path, ... submodule_path='vendor/lib', ... ).deinit() >>> 'error' in result.lower() or result == '' True
Set branch for this submodule.
Examples
>>> result = GitSubmoduleEntryCmd( ... path=example_git_repo.path, ... submodule_path='vendor/lib', ... ).set_branch('main') >>> 'fatal' in result.lower() or 'error' in result.lower() or result == '' True
Set URL for this submodule.
Examples
>>> result = GitSubmoduleEntryCmd( ... path=example_git_repo.path, ... submodule_path='vendor/lib', ... ).set_url('https://example.com/repo.git') >>> 'fatal' in result.lower() or 'error' in result.lower() or result == '' True
Get status of this submodule.
Examples
>>> result = GitSubmoduleEntryCmd( ... path=example_git_repo.path, ... submodule_path='vendor/lib', ... ).status() >>> isinstance(result, str) True
Absorb git directory for this submodule.
Examples
>>> result = GitSubmoduleEntryCmd( ... path=example_git_repo.path, ... submodule_path='vendor/lib', ... ).absorbgitdirs() >>> 'error' in result.lower() or result == '' True
Bases:
objectRun git submodule commands (low-level, use
GitSubmoduleManager).Lite, typed, pythonic wrapper for git-submodule(1).
Examples
>>> GitSubmoduleCmd(path=tmp_path) <GitSubmoduleCmd path=...>
>>> GitSubmoduleCmd(path=tmp_path).run(quiet=True, trim=True) 'fatal: not a git repository (or any of the parent directories): .git'
>>> GitSubmoduleCmd(path=example_git_repo.path).run(quiet=True) ''
Run a command against a git submodule.
Wraps git submodule.
Examples
>>> GitSubmoduleCmd(path=example_git_repo.path).run() ''
Git submodule init.
Examples
>>> GitSubmoduleCmd(path=example_git_repo.path).init() ''
Git submodule update.
Examples
>>> GitSubmoduleCmd(path=example_git_repo.path).update() '' >>> GitSubmoduleCmd(path=example_git_repo.path).update(init=True) '' >>> GitSubmoduleCmd( ... path=example_git_repo.path ... ).update(init=True, recursive=True) '' >>> GitSubmoduleCmd(path=example_git_repo.path).update(force=True) '' >>> GitSubmoduleCmd(path=example_git_repo.path).update(checkout=True) '' >>> GitSubmoduleCmd(path=example_git_repo.path).update(rebase=True) '' >>> GitSubmoduleCmd(path=example_git_repo.path).update(merge=True) ''