Skip to content

fix: make submodule.update() after submodule.deinit() work#2175

Merged
Byron merged 1 commit into
mainfrom
submodule-deinit-fix
Jul 16, 2026
Merged

fix: make submodule.update() after submodule.deinit() work#2175
Byron merged 1 commit into
mainfrom
submodule-deinit-fix

Conversation

@Byron

@Byron Byron commented Jul 16, 2026

Copy link
Copy Markdown
Member

Git's submodule deinit command removes the submodule checkout but retains its repository under the parent repository's .git/modules directory.

Submodule.update() previously treated the missing checkout as a completely uninitialized submodule and attempted to clone it again. The clone could not reuse the existing module repository, preventing a deinitialized submodule from being initialized again through GitPython.

Detect a valid retained repository before entering the clone path. Restore the checkout's .git file and the module repository's worktree configuration, reset the retained repository to recreate its index and working tree, and restore the submodule URL in the parent configuration. Continue using the existing clone behavior when no valid retained repository is available.

Tasks

  • refackiew

Copilot AI review requested due to automatic review settings July 16, 2026 05:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes Submodule.update() so that a submodule can be re-initialized via GitPython after it was deinitialized with git submodule deinit, by reusing the retained repository under the parent repo’s .git/modules/ rather than attempting a fresh clone.

Changes:

  • Detect and reuse an existing retained submodule repository under .git/modules/ when the worktree checkout is missing.
  • Recreate the submodule checkout by restoring the .git file + module core.worktree config and resetting to repopulate index/worktree.
  • Add test coverage to validate update-after-deinit behavior (including init=False, dry_run=True, and nested submodule names).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
git/objects/submodule/base.py Adds a “reconnect retained repo” path in Submodule.update() to restore a deinitialized checkout without recloning.
test/test_submodule.py Adds tests covering submodule.update() behavior after submodule.deinit() across several modes and a nested submodule case.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread git/objects/submodule/base.py
Copilot AI review requested due to automatic review settings July 16, 2026 05:35
@Byron Byron force-pushed the submodule-deinit-fix branch from 72895f4 to eb7bf7b Compare July 16, 2026 05:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread git/objects/submodule/base.py
Git's `submodule deinit` command removes the submodule checkout but retains
its repository under the parent repository's `.git/modules` directory.

Submodule.update() previously treated the missing checkout as a completely
uninitialized submodule and attempted to clone it again. The clone could not
reuse the existing module repository, preventing a deinitialized submodule
from being initialized again through GitPython.

Detect a valid retained repository before entering the clone path. Restore
the checkout's `.git` file and the module repository's worktree
configuration, reset the retained repository to recreate its index and
working tree, and restore the submodule URL in the parent configuration.
Continue using the existing clone behavior when no valid retained repository
is available.

Co-authored-by: Sebastian Thiel <[email protected]>
Copilot AI review requested due to automatic review settings July 16, 2026 05:46
@Byron Byron force-pushed the submodule-deinit-fix branch from eb7bf7b to b9d82c0 Compare July 16, 2026 05:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@Byron Byron merged commit 15527ef into main Jul 16, 2026
53 of 54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants