{"thread":{"id":"66859","subject":"submodule: linked-worktree submodule hits BUG() in validate_submodule_legacy_git_dir()","startedAt":"2026-11-16T22:51:48Z","lastAt":"2026-11-19T22:14:03Z","messageCount":13,"participants":["Andreas Wendleder","Adrian Ratiu","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"558578","messageId":"avuJBGlB3pRU3JU0@pampelmuse","threadId":"66859","inReplyTo":null,"subject":"submodule: linked-worktree submodule hits BUG() in validate_submodule_legacy_git_dir()","fromName":"Andreas Wendleder","fromEmail":"gonsolo@gmail.com","sentAt":"2026-11-16T22:51:48Z","receivedAt":"2026-11-16T22:51:48Z","isPatch":false,"sender":{"key":"gonsolo@gmail.com","avatar":null},"body":"With submodule.recurse=true, switching branches in a superproject worktree\nwhose submodule is itself a linked worktree of the submodule repository\naborts:\n\n  BUG: submodule.c:2414: submodule name 'sub' not a suffix of git dir\n  '.../.git/modules/sub/worktrees/sub1'\n\nReproduction (git 2.56.0; the code is the same on master, next and seen):\n\n  #!/bin/sh\n  set -e\n  export GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_NOSYSTEM=1\n  g() { git -c user.name=t -c user.email=t@t -c protocol.file.allow=always \"$@\"; }\n  rm -rf w && mkdir w && cd w\n  g init -q -b main sub && g -C sub commit -q --allow-empty -m s1\n  g init -q -b main super && cd super\n  g submodule add -q ../sub sub && g commit -q -m add\n  g -C sub commit -q --allow-empty -m s2 && g add sub && g commit -q -m bump\n  g branch other HEAD~1\n  g worktree add -q --detach ../wt main\n  g -C sub worktree add -q --detach ../../other/sub HEAD  # takes the name 'sub'\n  g -C sub worktree add -q --detach ../../wt/sub HEAD     # so this one is 'sub1'\n  cd ../wt\n  g -c submodule.recurse=true switch other\n\nsubmodule_move_head() expects validate_submodule_git_dir() to return < 0\nand then dies with \"refusing to create/use ... Enabling\nextensions.submodulePathConfig should fix this\", but without the extension\nvalidate_submodule_legacy_git_dir() calls BUG() instead. A linked\nworktree's git dir (modules/<name>/worktrees/<id>) never ends in the\nsubmodule name, so this setup always hits it.\n\nWith extensions.submodulePathConfig enabled (repositoryformatversion 1),\nthe same commands no longer crash but die with the \"refusing to create/use\n...\" message, which recommends enabling the extension that is already\nenabled.\n\nI would expect a linked worktree of a submodule's repository to be\naccepted as the submodule's git dir. If it is meant to be rejected, the\nlegacy path should return an error instead of calling BUG(), and the hint\nshould not suggest the extension when it is already on.\n\n"},{"id":"558637","messageId":"877bibjqrv.fsf@collabora.com","threadId":"66859","inReplyTo":"avuJBGlB3pRU3JU0@pampelmuse","subject":"Re: submodule: linked-worktree submodule hits BUG() in validate_submodule_legacy_git_dir()","fromName":"Adrian Ratiu","fromEmail":"adrian.ratiu@collabora.com","sentAt":"2026-11-17T17:45:24Z","receivedAt":"2026-11-17T17:45:24Z","isPatch":false,"sender":{"key":"adrian.ratiu@collabora.com","avatar":"https://avatars.githubusercontent.com/u/12472556?v=4"},"body":"Hi Andreas,\n\nOn Mon, 16 Nov 2026, Andreas Wendleder <gonsolo@gmail.com> wrote:\n> With submodule.recurse=true, switching branches in a superproject worktree\n> whose submodule is itself a linked worktree of the submodule repository\n> aborts:\n>\n>   BUG: submodule.c:2414: submodule name 'sub' not a suffix of git dir\n>   '.../.git/modules/sub/worktrees/sub1'\n\nThanks for reporting this and for the reproducer.\n\nThe BUG() is older than submodulePathConfig. Users could not reach it\nbefore 9cf8547320 (clone: prevent clashing git dirs when cloning\nsubmodule in parallel, 2024-01-28), which made submodule_move_head()\nvalidate whatever path the submodule's gitfile points to. A path read\nfrom disk can be anything, so it should never hit a BUG().\n\nYour reproducer needs the second worktree because the gitdir \".../sub\"\nhappens to end in the submodule name, so the check passes by accident.\n\nt2405 sets up exactly this layout but never runs a recursvie checkout.\n\nI'll send a fix.\n\n> With extensions.submodulePathConfig enabled (repositoryformatversion 1),\n> the same commands no longer crash but die with the \"refusing to create/use\n> ...\" message, which recommends enabling the extension that is already\n> enabled.\n>\n> I would expect a linked worktree of a submodule's repository to be\n> accepted as the submodule's git dir. If it is meant to be rejected, the\n> legacy path should return an error instead of calling BUG(), and the hint\n> should not suggest the extension when it is already on.\n\nYes, the hint is actually my mistake.\n\nI have a local fix which I need to test a bit more, but makes your\nscript switch cleanly in both modes and the main submodule checkout\nisn't touched.\n\nWill send it in the next few days with you in Reported-by.\n\nThanks again,\nAdrian\n\n"},{"id":"558720","messageId":"20261118163249.1693361-1-adrian.ratiu@collabora.com","threadId":"66859","inReplyTo":"avuJBGlB3pRU3JU0@pampelmuse","subject":"[PATCH 0/3] submodule: support linked worktrees in recursive checkout","fromName":"Adrian Ratiu","fromEmail":"adrian.ratiu@collabora.com","sentAt":"2026-11-18T16:32:46Z","receivedAt":"2026-11-18T16:32:46Z","isPatch":true,"sender":{"key":"adrian.ratiu@collabora.com","avatar":"https://avatars.githubusercontent.com/u/12472556?v=4"},"body":"Hello all,\n\nThis fixes a few submodule bugs reported by Andreas at:\nhttps://lore.kernel.org/git/avuJBGlB3pRU3JU0@pampelmuse/\n\nIn short: when a submodule is a linked worktree of its repository\n(\"git worktree add\" inside the submodule), a recursive checkout in the\nsuperproject either crashes with a BUG() or leaves the submodule broken.\n\nThe patches should be self-explanatory, many thanks to Andreas for\nreporting and sharing a reproducer.\n\nRegards,\nAdrian\n\nAdrian Ratiu (3):\n  submodule: return an error instead of BUG() for an unexpected git dir\n  submodule: only suggest submodulePathConfig when it is disabled\n  submodule: accept a linked worktree as the submodule's git dir\n\n submodule.c                                | 72 +++++++++++++++++++---\n t/t2405-worktree-submodule.sh              | 40 ++++++++++++\n t/t7425-submodule-gitdir-path-extension.sh | 14 +++++\n t/t7450-bad-git-dotfiles.sh                | 31 ++++++++++\n 4 files changed, 148 insertions(+), 9 deletions(-)\n\n\nbase-commit: e1ec09b23c8e0deb21a0b95ac5996422277395d4\n-- \n2.56.1\n\n\n"},{"id":"558721","messageId":"20261118163249.1693361-2-adrian.ratiu@collabora.com","threadId":"66859","inReplyTo":"20261118163249.1693361-1-adrian.ratiu@collabora.com","subject":"[PATCH 1/3] submodule: return an error instead of BUG() for an unexpected git dir","fromName":"Adrian Ratiu","fromEmail":"adrian.ratiu@collabora.com","sentAt":"2026-11-18T16:32:47Z","receivedAt":"2026-11-18T16:32:47Z","isPatch":true,"sender":{"key":"adrian.ratiu@collabora.com","avatar":"https://avatars.githubusercontent.com/u/12472556?v=4"},"body":"During a recursive checkout, Git reads a submodule's .git file to find\nits git dir and checks that the path ends in the submodule's name, e.g.\n\".git/modules/sub\" for a submodule called \"sub\".\n\nWithout extensions.submodulePathConfig, a path that does not end that\nway triggers a BUG() and aborts the command:\n\n  BUG: submodule.c:2414: submodule name 'sub' not a suffix of git dir '...'\n\nThis path comes from a file on disk, not from Git's own code, so an\nunexpected value is a problem with the user's setup, not a bug in Git.\nIt can happen when the git dir under .git/modules has been renamed or\nthe submodule is a linked worktree (handled in a later commit).\n\nWhen the check was added in a8dee3ca61 (Disallow dubiously-nested\nsubmodule git directories, 2019-10-01), its callers only passed git\ndirs computed by Git from the submodule name, so BUG() was correct.\n\n9cf8547320 (clone: prevent clashing git dirs when cloning submodule in\nparallel, 2024-01-28) added a caller that passes a path read from the\ngitfile, which made the BUG() reachable.\n\nReturn an error instead of BUG(), so the command dies with the same\n\"refusing to create/use ...\" message as when the submodulePathConfig\nextension is enabled.\n\nReported-by: Andreas Wendleder <gonsolo@gmail.com>\nSigned-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>\n---\n submodule.c                 |  8 ++++++--\n t/t7450-bad-git-dotfiles.sh | 14 ++++++++++++++\n 2 files changed, 20 insertions(+), 2 deletions(-)\n\ndiff --git a/submodule.c b/submodule.c\nindex 1302c11ddf..d00d820d42 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -2410,10 +2410,14 @@ static int validate_submodule_legacy_git_dir(char *git_dir, const char *submodul\n \t\tBUG(\"validate_submodule_git_dir() must be called with \"\n \t\t    \"extensions.submodulePathConfig disabled.\");\n \n+\t/*\n+\t * The git dir may come from a gitfile on disk, so a mismatch is\n+\t * not necessarily a bug in the caller.\n+\t */\n \tif (len <= suffix_len || (p = git_dir + len - suffix_len)[-1] != '/' ||\n \t    strcmp(p, submodule_name))\n-\t\tBUG(\"submodule name '%s' not a suffix of git dir '%s'\",\n-\t\t    submodule_name, git_dir);\n+\t\treturn error(_(\"submodule name '%s' not a suffix of git dir '%s'\"),\n+\t\t\t     submodule_name, git_dir);\n \n \t/*\n \t * We prevent the contents of sibling submodules' git directories to\ndiff --git a/t/t7450-bad-git-dotfiles.sh b/t/t7450-bad-git-dotfiles.sh\nindex 72c7f6f73b..e17642fc16 100755\n--- a/t/t7450-bad-git-dotfiles.sh\n+++ b/t/t7450-bad-git-dotfiles.sh\n@@ -380,6 +380,20 @@ test_expect_success 'checkout -f --recurse-submodules must not use a nested gitd\n \ttest_path_is_missing nested_checkout/thing2/.git\n '\n \n+test_expect_success 'checkout --recurse-submodules rejects gitfile not matching submodule name' '\n+\tgit clone nested mismatched_gitdir &&\n+\t(\n+\t\tcd mismatched_gitdir &&\n+\t\tgit submodule init thing1 &&\n+\t\tgit submodule update thing1 &&\n+\t\tmv .git/modules/hippo .git/modules/elephant &&\n+\t\techo \"gitdir: ../.git/modules/elephant\" >thing1/.git\n+\t) &&\n+\ttest_must_fail git -C mismatched_gitdir checkout -f --recurse-submodules HEAD 2>err &&\n+\ttest_grep \"not a suffix of git dir\" err &&\n+\ttest_grep ! \"BUG\" err\n+'\n+\n test_expect_success SYMLINKS,!WINDOWS,!MINGW 'submodule must not checkout into different directory' '\n \ttest_when_finished \"rm -rf sub repo bad-clone\" &&\n \n-- \n2.56.1\n\n\n"},{"id":"558722","messageId":"20261118163249.1693361-3-adrian.ratiu@collabora.com","threadId":"66859","inReplyTo":"20261118163249.1693361-1-adrian.ratiu@collabora.com","subject":"[PATCH 2/3] submodule: only suggest submodulePathConfig when it is disabled","fromName":"Adrian Ratiu","fromEmail":"adrian.ratiu@collabora.com","sentAt":"2026-11-18T16:32:48Z","receivedAt":"2026-11-18T16:32:48Z","isPatch":true,"sender":{"key":"adrian.ratiu@collabora.com","avatar":"https://avatars.githubusercontent.com/u/12472556?v=4"},"body":"When a recursive checkout refuses to use a submodule's git dir, the\nerror message ends with:\n\n  Enabling extensions.submodulePathConfig should fix this.\n\nThis is printed even when the extension is already enabled, which is\nconfusing: the user is told to turn on something that is already on.\n\nMove the suggestion into a separate hint, as submodule_name_to_gitdir()\nalready does, and only show it when the extension is disabled.\n\nReported-by: Andreas Wendleder <gonsolo@gmail.com>\nSigned-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>\n---\n submodule.c                                | 10 ++++++----\n t/t7425-submodule-gitdir-path-extension.sh | 14 ++++++++++++++\n t/t7450-bad-git-dotfiles.sh                |  1 +\n 3 files changed, 21 insertions(+), 4 deletions(-)\n\ndiff --git a/submodule.c b/submodule.c\nindex d00d820d42..64cd8005f7 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -2171,11 +2171,13 @@ int submodule_move_head(const char *path, const char *super_prefix,\n \n \t\t\t\tfree(dotgit);\n \t\t\t\tif (validate_submodule_git_dir(git_dir,\n-\t\t\t\t\t\t\t       sub->name) < 0)\n+\t\t\t\t\t\t\t       sub->name) < 0) {\n+\t\t\t\t\tif (!the_repository->repository_format_submodule_path_cfg)\n+\t\t\t\t\t\tadvise(_(\"enabling extensions.submodulePathConfig \"\n+\t\t\t\t\t\t\t \"might fix the following error.\"));\n \t\t\t\t\tdie(_(\"refusing to create/use '%s' in \"\n-\t\t\t\t\t      \"another submodule's git dir. \"\n-\t\t\t\t\t      \"Enabling extensions.submodulePathConfig \"\n-\t\t\t\t\t      \"should fix this.\"), git_dir);\n+\t\t\t\t\t      \"another submodule's git dir.\"), git_dir);\n+\t\t\t\t}\n \t\t\t\tfree(git_dir);\n \t\t\t}\n \t\t} else {\ndiff --git a/t/t7425-submodule-gitdir-path-extension.sh b/t/t7425-submodule-gitdir-path-extension.sh\nindex ea86ecf7ee..80438a7231 100755\n--- a/t/t7425-submodule-gitdir-path-extension.sh\n+++ b/t/t7425-submodule-gitdir-path-extension.sh\n@@ -525,4 +525,18 @@ test_expect_success 'submodule gitdir conflicts with previously encoded name (lo\n \t)\n '\n \n+test_expect_success 'rejected submodule gitfile does not suggest enabling the extension' '\n+\tgit clone -c extensions.submodulePathConfig=true --recurse-submodules nested clone_moved_gitdir &&\n+\t(\n+\t\tcd clone_moved_gitdir &&\n+\t\tmkdir .git/modules/zoo &&\n+\t\tmv .git/modules/hippo .git/modules/zoo/hippo &&\n+\t\tgit config set -f .git/modules/zoo/hippo/config core.worktree ../../../../thing1 &&\n+\t\techo \"gitdir: ../.git/modules/zoo/hippo\" >thing1/.git\n+\t) &&\n+\ttest_must_fail git -C clone_moved_gitdir checkout -f --recurse-submodules HEAD 2>err &&\n+\ttest_grep \"refusing to create/use\" err &&\n+\ttest_grep ! \"extensions.submodulePathConfig\" err\n+'\n+\n test_done\ndiff --git a/t/t7450-bad-git-dotfiles.sh b/t/t7450-bad-git-dotfiles.sh\nindex e17642fc16..a710c05a5d 100755\n--- a/t/t7450-bad-git-dotfiles.sh\n+++ b/t/t7450-bad-git-dotfiles.sh\n@@ -391,6 +391,7 @@ test_expect_success 'checkout --recurse-submodules rejects gitfile not matching\n \t) &&\n \ttest_must_fail git -C mismatched_gitdir checkout -f --recurse-submodules HEAD 2>err &&\n \ttest_grep \"not a suffix of git dir\" err &&\n+\ttest_grep \"enabling extensions.submodulePathConfig\" err &&\n \ttest_grep ! \"BUG\" err\n '\n \n-- \n2.56.1\n\n\n"},{"id":"558723","messageId":"20261118163249.1693361-4-adrian.ratiu@collabora.com","threadId":"66859","inReplyTo":"20261118163249.1693361-1-adrian.ratiu@collabora.com","subject":"[PATCH 3/3] submodule: accept a linked worktree as the submodule's git dir","fromName":"Adrian Ratiu","fromEmail":"adrian.ratiu@collabora.com","sentAt":"2026-11-18T16:32:49Z","receivedAt":"2026-11-18T16:32:49Z","isPatch":true,"sender":{"key":"adrian.ratiu@collabora.com","avatar":"https://avatars.githubusercontent.com/u/12472556?v=4"},"body":"A submodule's working tree can be a linked worktree of the submodule's\nrepository, created e.g. with:\n\n  git -C super/sub worktree add ../../wt/sub\n\nIts .git file then points to \"super/.git/modules/sub/worktrees/<id>\"\ninstead of \"super/.git/modules/sub\". t2405 already creates such a\nsubmodule, but it doesn't test a recursive checkout, and its worktree\nid happens to match the submodule name.\n\nA recursive checkout (--recurse-submodules or submodule.recurse=true)\nhas two problems with this setup:\n\n 1. It checks that the git dir ends in the submodule's name. A\n    worktree's git dir ends in the worktree id instead, so the check\n    fails and the command dies. It only passes by chance, when the id\n    is the same as the name.\n\n 2. Even when the check passes, Git then rewrites the .git file to\n    point to the git dir it would normally use for the submodule,\n    \"$GIT_DIR/modules/<name>\" of the superproject. That is not the\n    repository the worktree belongs to and it usually does not exist,\n    so the submodule is left broken. Likewise, when the submodule is\n    removed, Git tries to unset core.worktree in that git dir and\n    prints an error and a warning.\n\n    This happens on every recursive checkout, not only with --force,\n    because unpack_trees() always passes SUBMODULE_MOVE_HEAD_FORCE to\n    submodule_move_head().\n\nFix both: when the git dir is a linked worktree of a valid submodule\ngit dir, i.e. it is located at \"<common-dir>/worktrees/<id>\", check\nthe common dir against the submodule's name and leave the .git file\nand core.worktree alone. Reject a git dir that has a commondir file but\nis located anywhere else.\n\nReported-by: Andreas Wendleder <gonsolo@gmail.com>\nSigned-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>\n---\n submodule.c                   | 56 ++++++++++++++++++++++++++++++++---\n t/t2405-worktree-submodule.sh | 40 +++++++++++++++++++++++++\n t/t7450-bad-git-dotfiles.sh   | 16 ++++++++++\n 3 files changed, 108 insertions(+), 4 deletions(-)\n\ndiff --git a/submodule.c b/submodule.c\nindex 64cd8005f7..1bd7fb7e04 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -2119,6 +2119,45 @@ static void submodule_reset_index(const char *path, const char *super_prefix)\n \t\tdie(_(\"could not reset submodule index\"));\n }\n \n+/*\n+ * A submodule gitfile may point to a linked worktree of the submodule\n+ * repository, i.e. \"<common-dir>/worktrees/<id>\", whose path does not end\n+ * in the submodule name. Validate the common dir in that case, after making\n+ * sure that the git dir is where \"git worktree add\" would have put it, and\n+ * die if it is not.\n+ *\n+ * Returns:\n+ *   1 if git_dir is a valid linked worktree.\n+ *   0 if it is a valid submodule git dir.\n+ *   a negative value otherwise.\n+ */\n+static int validate_submodule_gitfile_dir(const char *git_dir,\n+\t\t\t\t\t  const char *submodule_name)\n+{\n+\tstruct strbuf common_dir = STRBUF_INIT;\n+\tstruct strbuf worktree_dir = STRBUF_INIT;\n+\tint is_worktree, ret;\n+\n+\tis_worktree = get_common_dir_noenv(&common_dir, git_dir);\n+\tif (is_worktree) {\n+\t\tconst char *id;\n+\n+\t\tstrbuf_realpath(&worktree_dir, git_dir, 1);\n+\t\tif (!skip_prefix(worktree_dir.buf, common_dir.buf, &id) ||\n+\t\t    !skip_prefix(id, \"/worktrees/\", &id) ||\n+\t\t    !*id || strchr(id, '/'))\n+\t\t\tdie(_(\"submodule git dir '%s' is not a worktree of '%s'\"),\n+\t\t\t    git_dir, common_dir.buf);\n+\t}\n+\n+\tret = validate_submodule_git_dir(common_dir.buf, submodule_name);\n+\tif (!ret)\n+\t\tret = is_worktree;\n+\tstrbuf_release(&common_dir);\n+\tstrbuf_release(&worktree_dir);\n+\treturn ret;\n+}\n+\n /**\n  * Moves a submodule at a given path from a given head to another new head.\n  * For edge cases (a submodule coming into existence or removing a submodule)\n@@ -2132,6 +2171,7 @@ int submodule_move_head(const char *path, const char *super_prefix,\n \tstruct child_process cp = CHILD_PROCESS_INIT;\n \tconst struct submodule *sub;\n \tint *error_code_ptr, error_code;\n+\tint is_worktree = 0;\n \n \tif (!is_submodule_active(the_repository, path))\n \t\treturn 0;\n@@ -2170,8 +2210,9 @@ int submodule_move_head(const char *path, const char *super_prefix,\n \t\t\t\tchar *git_dir = xstrdup(read_gitfile(dotgit));\n \n \t\t\t\tfree(dotgit);\n-\t\t\t\tif (validate_submodule_git_dir(git_dir,\n-\t\t\t\t\t\t\t       sub->name) < 0) {\n+\t\t\t\tis_worktree = validate_submodule_gitfile_dir(git_dir,\n+\t\t\t\t\t\t\t\t\t     sub->name);\n+\t\t\t\tif (is_worktree < 0) {\n \t\t\t\t\tif (!the_repository->repository_format_submodule_path_cfg)\n \t\t\t\t\t\tadvise(_(\"enabling extensions.submodulePathConfig \"\n \t\t\t\t\t\t\t \"might fix the following error.\"));\n@@ -2191,7 +2232,13 @@ int submodule_move_head(const char *path, const char *super_prefix,\n \t\t\tsubmodule_reset_index(path, super_prefix);\n \t\t}\n \n-\t\tif (old_head && (flags & SUBMODULE_MOVE_HEAD_FORCE)) {\n+\t\t/*\n+\t\t * Do not reconnect a linked worktree to the submodule's\n+\t\t * main git dir: that would take over the git dir of another\n+\t\t * working tree.\n+\t\t */\n+\t\tif (old_head && (flags & SUBMODULE_MOVE_HEAD_FORCE) &&\n+\t\t    !is_worktree) {\n \t\t\tstruct strbuf gitdir = STRBUF_INIT;\n \t\t\tsubmodule_name_to_gitdir(&gitdir, the_repository,\n \t\t\t\t\t\t sub->name);\n@@ -2256,7 +2303,8 @@ int submodule_move_head(const char *path, const char *super_prefix,\n \t\t\tif (is_empty_dir(path))\n \t\t\t\trmdir_or_warn(path);\n \n-\t\t\tsubmodule_unset_core_worktree(sub);\n+\t\t\tif (!is_worktree)\n+\t\t\t\tsubmodule_unset_core_worktree(sub);\n \t\t}\n \t}\n out:\ndiff --git a/t/t2405-worktree-submodule.sh b/t/t2405-worktree-submodule.sh\nindex f5c94d490b..fc5cb849de 100755\n--- a/t/t2405-worktree-submodule.sh\n+++ b/t/t2405-worktree-submodule.sh\n@@ -59,6 +59,46 @@ test_expect_success 'submodule is checked out after manually adding submodule wo\n \ttest_grep \"file1 updated\" out\n '\n \n+test_expect_success 'checkout --recurse-submodules accepts a submodule worktree' '\n+\tgit -C main worktree add \"$base_path/submodule-worktree\" \"$rev1_hash_main\" &&\n+\tgit -C main/sub worktree add \"$base_path/submodule-worktree/sub\" \"$rev1_hash_sub\" &&\n+\tcat submodule-worktree/sub/.git >expect-gitfile &&\n+\t# the worktree id must not end in the submodule name\n+\ttest_grep \"/worktrees/sub1$\" expect-gitfile &&\n+\tgit -C main/sub rev-parse HEAD >expect-head-main &&\n+\tgit -C submodule-worktree checkout --recurse-submodules \"$(git -C main rev-parse HEAD)\" &&\n+\tgit -C submodule-worktree rev-parse HEAD:sub >expect-head &&\n+\tgit -C submodule-worktree/sub rev-parse HEAD >actual-head &&\n+\ttest_cmp expect-head actual-head &&\n+\tcat submodule-worktree/sub/.git >actual-gitfile &&\n+\ttest_cmp expect-gitfile actual-gitfile &&\n+\tgit -C main/sub rev-parse HEAD >actual-head-main &&\n+\ttest_cmp expect-head-main actual-head-main\n+'\n+\n+test_expect_success 'checkout --recurse-submodules accepts a submodule worktree with submodulePathConfig' '\n+\ttest_config -C main core.repositoryformatversion 1 &&\n+\ttest_config -C main extensions.submodulePathConfig true &&\n+\ttest_config -C main submodule.sub.gitdir .git/modules/sub &&\n+\tgit -C submodule-worktree checkout --recurse-submodules \"$rev1_hash_main\" &&\n+\tgit -C submodule-worktree/sub rev-parse --short HEAD >actual-head &&\n+\techo \"$rev1_hash_sub\" >expect-head &&\n+\ttest_cmp expect-head actual-head &&\n+\tcat submodule-worktree/sub/.git >actual-gitfile &&\n+\ttest_cmp expect-gitfile actual-gitfile &&\n+\tgit -C main/sub rev-parse HEAD >actual-head-main &&\n+\ttest_cmp expect-head-main actual-head-main\n+'\n+\n+test_expect_success 'checkout --recurse-submodules removes a submodule worktree' '\n+\tgit -C main/sub config get core.worktree >expect-main &&\n+\tgit -C submodule-worktree checkout --recurse-submodules first 2>err &&\n+\ttest_grep ! \"core.worktree\" err &&\n+\ttest_path_is_missing submodule-worktree/sub/.git &&\n+\tgit -C main/sub config get core.worktree >actual-main &&\n+\ttest_cmp expect-main actual-main\n+'\n+\n test_expect_success 'checkout --recurse-submodules uses $GIT_DIR for submodules in a linked worktree' '\n \tgit -C main worktree add \"$base_path/checkout-recurse\" --detach  &&\n \tgit -C checkout-recurse submodule update --init &&\ndiff --git a/t/t7450-bad-git-dotfiles.sh b/t/t7450-bad-git-dotfiles.sh\nindex a710c05a5d..26d442c0ad 100755\n--- a/t/t7450-bad-git-dotfiles.sh\n+++ b/t/t7450-bad-git-dotfiles.sh\n@@ -395,6 +395,22 @@ test_expect_success 'checkout --recurse-submodules rejects gitfile not matching\n \ttest_grep ! \"BUG\" err\n '\n \n+test_expect_success 'checkout --recurse-submodules rejects gitfile pointing to a forged worktree' '\n+\tgit clone nested forged_worktree &&\n+\t(\n+\t\tcd forged_worktree &&\n+\t\tgit submodule init thing1 &&\n+\t\tgit submodule update thing1 &&\n+\t\tmkdir .git/modules/forged &&\n+\t\tcp .git/modules/hippo/HEAD .git/modules/forged/HEAD &&\n+\t\techo \"../hippo\" >.git/modules/forged/commondir &&\n+\t\techo \"gitdir: ../.git/modules/forged\" >thing1/.git\n+\t) &&\n+\ttest_must_fail git -C forged_worktree checkout -f --recurse-submodules HEAD 2>err &&\n+\ttest_grep \"is not a worktree of\" err &&\n+\ttest_grep ! \"extensions.submodulePathConfig\" err\n+'\n+\n test_expect_success SYMLINKS,!WINDOWS,!MINGW 'submodule must not checkout into different directory' '\n \ttest_when_finished \"rm -rf sub repo bad-clone\" &&\n \n-- \n2.56.1\n\n\n"},{"id":"558742","messageId":"xmqqecci54tw.fsf@gitster.g","threadId":"66859","inReplyTo":"20261118163249.1693361-2-adrian.ratiu@collabora.com","subject":"Re: [PATCH 1/3] submodule: return an error instead of BUG() for an unexpected git dir","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-18T19:15:23Z","receivedAt":"2026-11-18T19:15:23Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Adrian Ratiu <adrian.ratiu@collabora.com> writes:\n\n> 9cf8547320 (clone: prevent clashing git dirs when cloning submodule in\n> parallel, 2024-01-28) added a caller that passes a path read from the\n> gitfile, which made the BUG() reachable.\n>\n> Return an error instead of BUG(), so the command dies with the same\n> \"refusing to create/use ...\" message as when the submodulePathConfig\n> extension is enabled.\n\nMakes sense.\n\nThe above archaeology was quite illuminating.  It seems that the\noffending commit came without the usual on-list reviews as part of\nthe Git 2.39.4/2.45.1 updates.\n\n> Reported-by: Andreas Wendleder <gonsolo@gmail.com>\n> Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>\n> ---\n>  submodule.c                 |  8 ++++++--\n>  t/t7450-bad-git-dotfiles.sh | 14 ++++++++++++++\n>  2 files changed, 20 insertions(+), 2 deletions(-)\n>\n> diff --git a/submodule.c b/submodule.c\n> index 1302c11ddf..d00d820d42 100644\n> --- a/submodule.c\n> +++ b/submodule.c\n> @@ -2410,10 +2410,14 @@ static int validate_submodule_legacy_git_dir(char *git_dir, const char *submodul\n>  \t\tBUG(\"validate_submodule_git_dir() must be called with \"\n>  \t\t    \"extensions.submodulePathConfig disabled.\");\n>  \n> +\t/*\n> +\t * The git dir may come from a gitfile on disk, so a mismatch is\n> +\t * not necessarily a bug in the caller.\n> +\t */\n\n\"is not necessarily a bug\" is not incorrect per se, but it is only\nrelevant in the context of turning what was originally a BUG() into\na \"return error()\".  If this had been written to return an error\ninstead of calling BUG() from the beginning, you would not have\nphrased the comment that way.\n\nIf this if() statement needs a comment, we should state why these\ntwo are expected to match, or why it is an error if they do not\nmatch.\n\n>  \tif (len <= suffix_len || (p = git_dir + len - suffix_len)[-1] != '/' ||\n>  \t    strcmp(p, submodule_name))\n> -\t\tBUG(\"submodule name '%s' not a suffix of git dir '%s'\",\n> -\t\t    submodule_name, git_dir);\n> +\t\treturn error(_(\"submodule name '%s' not a suffix of git dir '%s'\"),\n> +\t\t\t     submodule_name, git_dir);\n\n"},{"id":"558743","messageId":"xmqqzev63pnh.fsf@gitster.g","threadId":"66859","inReplyTo":"20261118163249.1693361-3-adrian.ratiu@collabora.com","subject":"Re: [PATCH 2/3] submodule: only suggest submodulePathConfig when it is disabled","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-18T19:28:34Z","receivedAt":"2026-11-18T19:28:34Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Adrian Ratiu <adrian.ratiu@collabora.com> writes:\n\n> When a recursive checkout refuses to use a submodule's git dir, the\n> error message ends with:\n>\n>   Enabling extensions.submodulePathConfig should fix this.\n>\n> This is printed even when the extension is already enabled, which is\n> confusing: the user is told to turn on something that is already on.\n\nThe motivation sounds sensible.\n\n> Move the suggestion into a separate hint, as submodule_name_to_gitdir()\n> already does, and only show it when the extension is disabled.\n\nHmph, but submodule_name_to_gitdir() does\n\n\t/* validate because users might have modified the config */\n\tif (validate_submodule_git_dir(buf->buf, submodule_name)) {\n\t\tadvise(_(\"enabling extensions.submodulePathConfig might fix the \"\n\t\t\t \"following error, if it's not already enabled.\"));\n\t\tdie(_(\"refusing to create/use '%s' in another submodule's \"\n\t\t      \" git dir.\"), buf->buf);\n\t}\n\nwhich does not really check if it is enabled; it just hedges the\nmessage by using \"might fix ... if it's not\" and lets the users do\nthe work themselves, which is not necessarily a bad approach to take\nto simplify our job.\n\nSimilarly, builtin/submodule--helper.c:clone_submodule(), which is\nanother caller of validate_submodule_git_dir(), has an unconditional\n\"Enabling ... should fix this\" message, which we may want to give a\nsimilar treatment.\n\n> Reported-by: Andreas Wendleder <gonsolo@gmail.com>\n> Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>\n> ---\n>  submodule.c                                | 10 ++++++----\n>  t/t7425-submodule-gitdir-path-extension.sh | 14 ++++++++++++++\n>  t/t7450-bad-git-dotfiles.sh                |  1 +\n>  3 files changed, 21 insertions(+), 4 deletions(-)\n>\n> diff --git a/submodule.c b/submodule.c\n> index d00d820d42..64cd8005f7 100644\n> --- a/submodule.c\n> +++ b/submodule.c\n> @@ -2171,11 +2171,13 @@ int submodule_move_head(const char *path, const char *super_prefix,\n>  \n>  \t\t\t\tfree(dotgit);\n>  \t\t\t\tif (validate_submodule_git_dir(git_dir,\n> -\t\t\t\t\t\t\t       sub->name) < 0)\n> +\t\t\t\t\t\t\t       sub->name) < 0) {\n> +\t\t\t\t\tif (!the_repository->repository_format_submodule_path_cfg)\n> +\t\t\t\t\t\tadvise(_(\"enabling extensions.submodulePathConfig \"\n> +\t\t\t\t\t\t\t \"might fix the following error.\"));\n>  \t\t\t\t\tdie(_(\"refusing to create/use '%s' in \"\n> -\t\t\t\t\t      \"another submodule's git dir. \"\n> -\t\t\t\t\t      \"Enabling extensions.submodulePathConfig \"\n> -\t\t\t\t\t      \"should fix this.\"), git_dir);\n> +\t\t\t\t\t      \"another submodule's git dir.\"), git_dir);\n> +\t\t\t\t}\n\nIt is not exactly a new issue, but this makes an already too deeply\nnested block even worse.  I wonder if the entire \"if not dry-run, do\nthese\" block should be moved to a private helper function to make it\na bit easier to read.\n\n\n"},{"id":"558746","messageId":"874idej5o8.fsf@collabora.com","threadId":"66859","inReplyTo":"xmqqecci54tw.fsf@gitster.g","subject":"Re: [PATCH 1/3] submodule: return an error instead of BUG() for an unexpected git dir","fromName":"Adrian Ratiu","fromEmail":"adrian.ratiu@collabora.com","sentAt":"2026-11-18T19:33:27Z","receivedAt":"2026-11-18T19:33:27Z","isPatch":true,"sender":{"key":"adrian.ratiu@collabora.com","avatar":"https://avatars.githubusercontent.com/u/12472556?v=4"},"body":"On Wed, 18 Nov 2026, Junio C Hamano <gitster@pobox.com> wrote:\n> Adrian Ratiu <adrian.ratiu@collabora.com> writes:\n>\n>> 9cf8547320 (clone: prevent clashing git dirs when cloning submodule in\n>> parallel, 2024-01-28) added a caller that passes a path read from the\n>> gitfile, which made the BUG() reachable.\n>>\n>> Return an error instead of BUG(), so the command dies with the same\n>> \"refusing to create/use ...\" message as when the submodulePathConfig\n>> extension is enabled.\n>\n> Makes sense.\n>\n> The above archaeology was quite illuminating.  It seems that the\n> offending commit came without the usual on-list reviews as part of\n> the Git 2.39.4/2.45.1 updates.\n\nYeah, I wasn't part of discussions on this, so I don't have the full\ncontext either, but I do think switching BUG() -> error() makes sense.\n\n>> Reported-by: Andreas Wendleder <gonsolo@gmail.com>\n>> Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>\n>> ---\n>>  submodule.c                 |  8 ++++++--\n>>  t/t7450-bad-git-dotfiles.sh | 14 ++++++++++++++\n>>  2 files changed, 20 insertions(+), 2 deletions(-)\n>>\n>> diff --git a/submodule.c b/submodule.c\n>> index 1302c11ddf..d00d820d42 100644\n>> --- a/submodule.c\n>> +++ b/submodule.c\n>> @@ -2410,10 +2410,14 @@ static int validate_submodule_legacy_git_dir(char *git_dir, const char *submodul\n>>  \t\tBUG(\"validate_submodule_git_dir() must be called with \"\n>>  \t\t    \"extensions.submodulePathConfig disabled.\");\n>>  \n>> +\t/*\n>> +\t * The git dir may come from a gitfile on disk, so a mismatch is\n>> +\t * not necessarily a bug in the caller.\n>> +\t */\n>\n> \"is not necessarily a bug\" is not incorrect per se, but it is only\n> relevant in the context of turning what was originally a BUG() into\n> a \"return error()\".  If this had been written to return an error\n> instead of calling BUG() from the beginning, you would not have\n> phrased the comment that way.\n>\n> If this if() statement needs a comment, we should state why these\n> two are expected to match, or why it is an error if they do not\n> match.\n\nGood point.\n\nI'll drop the comment addition in v2 since we don't need to over-explain\nthe BUG() -> error() transition.\n\n"},{"id":"558747","messageId":"xmqqv75t534o.fsf@gitster.g","threadId":"66859","inReplyTo":"20261118163249.1693361-4-adrian.ratiu@collabora.com","subject":"Re: [PATCH 3/3] submodule: accept a linked worktree as the submodule's git dir","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-18T19:52:07Z","receivedAt":"2026-11-18T19:52:07Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Adrian Ratiu <adrian.ratiu@collabora.com> writes:\n\n> A submodule's working tree can be a linked worktree of the submodule's\n> repository, created e.g. with:\n>\n>   git -C super/sub worktree add ../../wt/sub\n>\n> Its .git file then points to \"super/.git/modules/sub/worktrees/<id>\"\n> instead of \"super/.git/modules/sub\". t2405 already creates such a\n> submodule, but it doesn't test a recursive checkout, and its worktree\n> id happens to match the submodule name.\n\nIt is tempting to say \"don't do it then\", but if we can cater to the\nuse case that is great ;-)\n\n> @@ -2132,6 +2171,7 @@ int submodule_move_head(const char *path, const char *super_prefix,\n>  \tstruct child_process cp = CHILD_PROCESS_INIT;\n>  \tconst struct submodule *sub;\n>  \tint *error_code_ptr, error_code;\n> +\tint is_worktree = 0;\n>  \n>  \tif (!is_submodule_active(the_repository, path))\n>  \t\treturn 0;\n> @@ -2170,8 +2210,9 @@ int submodule_move_head(const char *path, const char *super_prefix,\n>  \t\t\t\tchar *git_dir = xstrdup(read_gitfile(dotgit));\n>  \n>  \t\t\t\tfree(dotgit);\n> -\t\t\t\tif (validate_submodule_git_dir(git_dir,\n> -\t\t\t\t\t\t\t       sub->name) < 0) {\n> +\t\t\t\tis_worktree = validate_submodule_gitfile_dir(git_dir,\n> +\t\t\t\t\t\t\t\t\t     sub->name);\n> +\t\t\t\tif (is_worktree < 0) {\n>  \t\t\t\t\tif (!the_repository->repository_format_submodule_path_cfg)\n>  \t\t\t\t\t\tadvise(_(\"enabling extensions.submodulePathConfig \"\n>  \t\t\t\t\t\t\t \"might fix the following error.\"));\n\nEarlier near the beginning of the function we initialized\nis_worktree to 0 and then only when submodule_uses_gitfile() is\ntrue, we update it with validate_submodule_gitfile_dir().\n\n> @@ -2191,7 +2232,13 @@ int submodule_move_head(const char *path, const char *super_prefix,\n>  \t\t\tsubmodule_reset_index(path, super_prefix);\n>  \t\t}\n>  \n> -\t\tif (old_head && (flags & SUBMODULE_MOVE_HEAD_FORCE)) {\n> +\t\t/*\n> +\t\t * Do not reconnect a linked worktree to the submodule's\n> +\t\t * main git dir: that would take over the git dir of another\n> +\t\t * working tree.\n> +\t\t */\n> +\t\tif (old_head && (flags & SUBMODULE_MOVE_HEAD_FORCE) &&\n> +\t\t    !is_worktree) {\n\nIf a linked-worktree submodule 'sub' contains a nested submodule\n'inner' whose .git is a directory, submodule_uses_gitfile(\"sub\")\nwould have returned 0 (because the check is recursive), we ran\nabsorb_git_dir_into_superproject() (which is also recursive so it\nwould cause .git in 'inner' to be absorbed), and is_worktree is\nstill 0 at this point, which means if() condition here is satisfied\n(if forced) and we will enter this block.  Would it cause an issue?\n\nI am wondering if the check for is_worktree should be moved outside\nthe else clause, i.e. making the overall flow look more like\n\n        if (old_head) {\n                if (!submodule_uses_gitfile(path))\n                        absorb_git_dir_into_superproject(path, super_prefix);\n\n                /*\n                 * Now path/.git is guaranteed to be a gitfile; \n                 * validate and detect worktrees.\n                 */\n                ...\n                is_worktree = validate_submodule_gitfile_dir(git_dir, sub->name);\n                ...\n        }\n\nOr am I grossly misreading the code flow?\n\nThanks.\n\n"},{"id":"558820","messageId":"871p8hjb6a.fsf@collabora.com","threadId":"66859","inReplyTo":"xmqqzev63pnh.fsf@gitster.g","subject":"Re: [PATCH 2/3] submodule: only suggest submodulePathConfig when it is disabled","fromName":"Adrian Ratiu","fromEmail":"adrian.ratiu@collabora.com","sentAt":"2026-11-19T11:46:53Z","receivedAt":"2026-11-19T11:46:53Z","isPatch":true,"sender":{"key":"adrian.ratiu@collabora.com","avatar":"https://avatars.githubusercontent.com/u/12472556?v=4"},"body":"On Wed, 18 Nov 2026, Junio C Hamano <gitster@pobox.com> wrote:\n> Adrian Ratiu <adrian.ratiu@collabora.com> writes:\n>\n>> When a recursive checkout refuses to use a submodule's git dir, the\n>> error message ends with:\n>>\n>>   Enabling extensions.submodulePathConfig should fix this.\n>>\n>> This is printed even when the extension is already enabled, which is\n>> confusing: the user is told to turn on something that is already on.\n>\n> The motivation sounds sensible.\n>\n>> Move the suggestion into a separate hint, as submodule_name_to_gitdir()\n>> already does, and only show it when the extension is disabled.\n>\n> Hmph, but submodule_name_to_gitdir() does\n>\n> \t/* validate because users might have modified the config */\n> \tif (validate_submodule_git_dir(buf->buf, submodule_name)) {\n> \t\tadvise(_(\"enabling extensions.submodulePathConfig might fix the \"\n> \t\t\t \"following error, if it's not already enabled.\"));\n> \t\tdie(_(\"refusing to create/use '%s' in another submodule's \"\n> \t\t      \" git dir.\"), buf->buf);\n> \t}\n>\n> which does not really check if it is enabled; it just hedges the\n> message by using \"might fix ... if it's not\" and lets the users do\n> the work themselves, which is not necessarily a bad approach to take\n> to simplify our job.\n>\n> Similarly, builtin/submodule--helper.c:clone_submodule(), which is\n> another caller of validate_submodule_git_dir(), has an unconditional\n> \"Enabling ... should fix this\" message, which we may want to give a\n> similar treatment.\n\nAck, I mis-remembered that we already checked the extension.\n\nHappy to reword as you suggested, but for v2 I'd also like to explore\ndropping the \"hedge\" and actually check in all three places, it should\nbe a trivial helper which reads repository_format_submodule_path_cfg.\n\n>> Reported-by: Andreas Wendleder <gonsolo@gmail.com>\n>> Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>\n>> ---\n>>  submodule.c                                | 10 ++++++----\n>>  t/t7425-submodule-gitdir-path-extension.sh | 14 ++++++++++++++\n>>  t/t7450-bad-git-dotfiles.sh                |  1 +\n>>  3 files changed, 21 insertions(+), 4 deletions(-)\n>>\n>> diff --git a/submodule.c b/submodule.c\n>> index d00d820d42..64cd8005f7 100644\n>> --- a/submodule.c\n>> +++ b/submodule.c\n>> @@ -2171,11 +2171,13 @@ int submodule_move_head(const char *path, const char *super_prefix,\n>>  \n>>  \t\t\t\tfree(dotgit);\n>>  \t\t\t\tif (validate_submodule_git_dir(git_dir,\n>> -\t\t\t\t\t\t\t       sub->name) < 0)\n>> +\t\t\t\t\t\t\t       sub->name) < 0) {\n>> +\t\t\t\t\tif (!the_repository->repository_format_submodule_path_cfg)\n>> +\t\t\t\t\t\tadvise(_(\"enabling extensions.submodulePathConfig \"\n>> +\t\t\t\t\t\t\t \"might fix the following error.\"));\n>>  \t\t\t\t\tdie(_(\"refusing to create/use '%s' in \"\n>> -\t\t\t\t\t      \"another submodule's git dir. \"\n>> -\t\t\t\t\t      \"Enabling extensions.submodulePathConfig \"\n>> -\t\t\t\t\t      \"should fix this.\"), git_dir);\n>> +\t\t\t\t\t      \"another submodule's git dir.\"), git_dir);\n>> +\t\t\t\t}\n>\n> It is not exactly a new issue, but this makes an already too deeply\n> nested block even worse.  I wonder if the entire \"if not dry-run, do\n> these\" block should be moved to a private helper function to make it\n> a bit easier to read.\n\nSure, I can add a helper here as well in v2. Thanks!\n\n"},{"id":"558841","messageId":"87y0aphv3v.fsf@collabora.com","threadId":"66859","inReplyTo":"xmqqv75t534o.fsf@gitster.g","subject":"Re: [PATCH 3/3] submodule: accept a linked worktree as the submodule's git dir","fromName":"Adrian Ratiu","fromEmail":"adrian.ratiu@collabora.com","sentAt":"2026-11-19T12:19:16Z","receivedAt":"2026-11-19T12:19:16Z","isPatch":true,"sender":{"key":"adrian.ratiu@collabora.com","avatar":"https://avatars.githubusercontent.com/u/12472556?v=4"},"body":"On Wed, 18 Nov 2026, Junio C Hamano <gitster@pobox.com> wrote:\n>> @@ -2191,7 +2232,13 @@ int submodule_move_head(const char *path, const char *super_prefix,\n>>  \t\t\tsubmodule_reset_index(path, super_prefix);\n>>  \t\t}\n>>  \n>> -\t\tif (old_head && (flags & SUBMODULE_MOVE_HEAD_FORCE)) {\n>> +\t\t/*\n>> +\t\t * Do not reconnect a linked worktree to the submodule's\n>> +\t\t * main git dir: that would take over the git dir of another\n>> +\t\t * working tree.\n>> +\t\t */\n>> +\t\tif (old_head && (flags & SUBMODULE_MOVE_HEAD_FORCE) &&\n>> +\t\t    !is_worktree) {\n>\n> If a linked-worktree submodule 'sub' contains a nested submodule\n> 'inner' whose .git is a directory, submodule_uses_gitfile(\"sub\")\n> would have returned 0 (because the check is recursive), we ran\n> absorb_git_dir_into_superproject() (which is also recursive so it\n> would cause .git in 'inner' to be absorbed), and is_worktree is\n> still 0 at this point, which means if() condition here is satisfied\n> (if forced) and we will enter this block.  Would it cause an issue?\n\nYes, good catch. I reproduced it with a \"sub\" linked worktree and a\n\"sub/inner/.git\" directory, a recursive checkout absorbs the \"inner\"\nand then rewrites sub/.git to point to \"$GIT_DIR/modules/sub\" which\ndoes not exist:\n\n  fatal: gitfile does not point to a valid repository: .git\n  error: Submodule 'sub' could not be updated.\n\nIt's basically the same breakage this patch is meant to fix, just\nreached through the absorb path.\n\n>\n> I am wondering if the check for is_worktree should be moved outside\n> the else clause, i.e. making the overall flow look more like\n>\n>         if (old_head) {\n>                 if (!submodule_uses_gitfile(path))\n>                         absorb_git_dir_into_superproject(path, super_prefix);\n>\n>                 /*\n>                  * Now path/.git is guaranteed to be a gitfile; \n>                  * validate and detect worktrees.\n>                  */\n>                 ...\n>                 is_worktree = validate_submodule_gitfile_dir(git_dir, sub->name);\n>                 ...\n>         }\n\nYes, that fixes it, the sub/.git is left alone and the submodule is\nchecked-out at the correct commit. The validation also runs after an\nabsorb, but absorb puts the gitdir where submodule_name_to_gitdir()\nsays it should be, so the check always passes.\n\n> Or am I grossly misreading the code flow?\n\nYou understood it perfectly. :) I'll do this in v2 as well.\n\nMany thanks!\n\n"},{"id":"558894","messageId":"xmqqmrr4v590.fsf@gitster.g","threadId":"66859","inReplyTo":"871p8hjb6a.fsf@collabora.com","subject":"Re: [PATCH 2/3] submodule: only suggest submodulePathConfig when it is disabled","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-19T22:14:03Z","receivedAt":"2026-11-19T22:14:03Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Adrian Ratiu <adrian.ratiu@collabora.com> writes:\n\n> ... dropping the \"hedge\" and actually check in all three places, it should\n> be a trivial helper which reads repository_format_submodule_path_cfg.\n\nSounds super sensible.\n\nThanks.\n\n"}]}