Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions git/objects/submodule/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
Callable,
Dict,
Iterator,
List,
Mapping,
Sequence,
TYPE_CHECKING,
Expand Down Expand Up @@ -1267,6 +1268,36 @@ def remove(

return self

@unbare_repo
def deinit(self, force: bool = False) -> "Submodule":
"""Run ``git submodule deinit`` on this submodule.

This is a thin wrapper around ``git submodule deinit <path>``, paralleling
:meth:`add`, :meth:`update`, and :meth:`remove`. It unregisters the
submodule (removes its entry from ``.git/config`` and empties the
working-tree directory) without deleting the submodule from
``.gitmodules`` or its checked-out repository under ``.git/modules/``.
A subsequent :meth:`update` will re-initialize the submodule from the
retained contents.

:param force:
If ``True``, pass ``--force`` to ``git submodule deinit``. This
allows deinitialization even when the submodule's working tree has
local modifications that would otherwise block the command.

:return:
self

:note:
Doesn't work in bare repositories.
"""
args: List[str] = []
if force:
args.append("--force")
args.extend(["--", self.path])
self.repo.git.submodule("deinit", *args)
return self
Comment on lines +1271 to +1299
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new public API Submodule.deinit() isn't covered by tests. Please add a targeted unit test that asserts the underlying git invocation (e.g., by mocking submodule.repo.git.submodule) for both force=False and force=True, including verifying the -- separator and the provided path argument.

Copilot uses AI. Check for mistakes.

def set_parent_commit(self, commit: Union[Commit_ish, str, None], check: bool = True) -> "Submodule":
"""Set this instance to use the given commit whose tree is supposed to
contain the ``.gitmodules`` blob.
Expand Down
Loading