Repository navigation
fix(remove): warn when a submodule holds commits on no remote - #4460
Conversation
worktrunk-bot
left a comment
There was a problem hiding this comment.
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.
worktrunk-bot
left a comment
There was a problem hiding this comment.
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.
worktrunk-bot
left a comment
There was a problem hiding this comment.
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 namedlibs/subatmodules/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-levelsub. One case with a nested name intest_remove_preserves_sole_submodule_historywould cover it. - Defensive error paths: a non-directory entry under
modules/(theUnexpected submodule storagebail), and aread_direrror other thanNotFound.
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.
codecov/patch failed — uncovered lines in module_container_has_local_history
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]>
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:
It still removes, so shallow or SHA-fetched pins (which can look the same) never need
--force.--forceskips 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-
--forceversion of this PR, per the decision to warn instead. The test-only commit routingGIT_EXEC_PATHto Git's real exec path is kept, sincegit submoduleneeds Git's helpers when wt runs asgit wt.