Skip to content

fix(remove): warn when a submodule holds commits on no remote - #4460

Merged
max-sixty merged 11 commits into
mainfrom
codex/submodule-storage-protection
Oct 20, 2026
Merged

max-sixty merged 11 commits into
mainfrom
codex/submodule-storage-protection

Conversation

@max-sixty

@max-sixty max-sixty commented Oct 12, 2026 •

Copy link
Copy Markdown
Owner

Removing a worktree deletes its submodules' module stores, and with them any commit no remote-tracking ref reaches, including reflog-only ones. Removal now warns before proceeding:

▲ Submodule submod has commits on no remote; removing the worktree deletes them

It still removes, so shallow or SHA-fetched pins (which can look the same) never need --force. --force skips the check, having already consented to losing what the worktree holds. The picker removes silently, as it does for everything else.

This replaces the earlier refuse-unless---force version of this PR, per the decision to warn instead. The test-only commit routing GIT_EXEC_PATH to Git's real exec path is kept, since git submodule needs Git's helpers when wt runs as git wt.

This was written by Claude Code on behalf of max-sixty

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A shallow or SHA-fetched submodule reads as holding local history, so ordinary shallow-submodule worktrees can no longer be cleaned up without --force. Details inline.

Comment thread src/git/repository/worktrees.rs Resolved

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The FETCH_HEAD exclusion only covers a shallow pin until the submodule fetches or updates again. After that, the worktree reads as holding local history and needs --force again. Details inline.

Comment thread src/git/repository/worktrees.rs Resolved
@max-sixty max-sixty changed the title Preserve local submodule history during worktree cleanup Preserve uncovered submodule history during worktree cleanup Oct 12, 2026
worktrunk-bot
worktrunk-bot previously approved these changes Oct 12, 2026

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

codecov/patch fails on this head: 92.41% of the diff is covered, against a 98.49% target. The same gap failed on the earlier heads too, and AGENTS.md (Coverage) makes it a merge gate, so I've withdrawn my approval until the gap is closed or explicitly waived.

Most of the uncovered lines are in module_container_has_local_history in src/git/repository/worktrees.rs:

  • The namespace-prefix recursion (the if !is_repository { … continue; } branch). Git stores a submodule named libs/sub at modules/libs/sub, so this branch runs whenever a submodule has a nested name. That's a common layout, and this check depends on the recursion finding those stores. The existing tests all use a top-level sub. One case with a nested name in test_remove_preserves_sole_submodule_history would cover it.
  • Defensive error paths: a non-directory entry under modules/ (the Unexpected submodule storage bail), and a read_dir error other than NotFound.

Two smaller misses are also in worktrees.rs: the return Ok(false) in has_local_submodule_history when the checkout's .git is absent, and the refusal ? in prune_worktree_entry. That refusal is the removal-time recheck, which planning normally catches first.

I can push a test for the nested-name case if you want it.

@worktrunk-bot
worktrunk-bot dismissed their stale review October 12, 2026 22:28

codecov/patch failed — uncovered lines in module_container_has_local_history

max-sixty and others added 3 commits October 20, 2026 15:08
Max chose a warning over a refusal: removal names the submodules holding
commits no remote-tracking ref reaches and still proceeds, so shallow and
SHA-pinned submodules need no --force. This merge takes main's tree; the next
commit adds the warning.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Removing a worktree deletes its submodules' module stores, and with them any
commit no remote-tracking ref reaches, including reflog-only ones. Removal now
names each such submodule and proceeds; --force skips the check, having
already consented to the loss.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty max-sixty changed the title Preserve uncovered submodule history during worktree cleanup fix(remove): warn when a submodule holds commits on no remote Oct 20, 2026
@max-sixty
max-sixty merged commit ab2a1e3 into main Oct 20, 2026
38 checks passed
@max-sixty
max-sixty deleted the codex/submodule-storage-protection branch October 20, 2026 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants