Andreas Wendleder reported that with submodule.recurse=true, switching branches in a superproject aborts with "BUG: submodule.c:2414: submodule name 'sub' not a suffix of git dir". This happens when the submodule is a linked worktree of the submodule repository. He said the code is the same on master, next and seen, and gave a reproduction script.
Adrian Ratiu explained the cause. A linked worktree's .git file points at ".git/modules/sub/worktrees/<id>" rather than ".git/modules/sub". The recursive checkout checks that the git dir ends in the submodule's name, so the check fails unless the worktree id happens to match the name. t2405 already creates such a submodule, but it does not test a recursive checkout.
One patch argues that the BUG() is wrong for this case. The path is read from a file on disk, so an unexpected value points to a problem in the user's setup, not a bug in Git. It can also happen when a directory under .git/modules has been renamed. Ratiu's cover letter says the series fixes cases where a recursive checkout either crashes or leaves the submodule broken.
The v2 changes follow Junio Hamano's review. An added code comment was dropped. The hint to enable extensions.submodulePathConfig is now given only when the extension is off, through one helper shared by all three places that refuse a git dir. That fix was prompted by Wendleder's report that the hint appeared even when the extension was already enabled. A new patch moves the git dir setup out of submodule_move_head() to reduce nesting. Another new patch also validates the git dir after absorbing, since absorbing only moves .git directories and a submodule that already used a gitfile keeps its old git dir, valid or not.
The excerpts do not show a verdict on v2 yet.