@@ -2064,6 +2064,7 @@ static void relocate_single_git_dir_into_superproject(const char *path)
char *old_git_dir = NULL, *real_old_git_dir = NULL, *real_new_git_dir = NULL;
char *new_git_dir;
const struct submodule *sub;
+ struct strbuf config_path = STRBUF_INIT, sb = STRBUF_INIT;
if (submodule_uses_worktrees(path))
die(_("relocate_gitdir for submodule '%s' with "
@@ -2095,6 +2096,15 @@ static void relocate_single_git_dir_into_superproject(const char *path)
relocate_gitdir(path, real_old_git_dir, real_new_git_dir);
+ /* cache pointer to superproject's gitdir */
+ /* NEEDSWORK: this may differ if experimental.worktreeConfig is enabled */
+ strbuf_addf(&config_path, "%s/config", real_new_git_dir);
+ git_config_set_in_file(config_path.buf, "submodule.superprojectGitdir",
+ relative_path(get_super_prefix_or_empty(),
+ path, &sb));
+
+ strbuf_release(&config_path);
+ strbuf_release(&sb);
free(old_git_dir);
free(real_old_git_dir);
free(real_new_git_dir);
@@ -29,6 +29,7 @@ test_expect_success 'absorb the git dir' '
test -d .git/modules/sub1 &&
git status >actual.1 &&
git -C sub1 rev-parse HEAD >actual.2 &&
+ test . -ef "$(git -C sub1 config submodule.superprojectGitDir)" &&
test_cmp expect.1 actual.1 &&
test_cmp expect.2 actual.2
'
Already during 'git submodule add' we cache a pointer to the superproject's gitdir. However, this doesn't help brand-new submodules created with 'git init' and later absorbed with 'git submodule absorbgitdir'. Let's start adding that pointer during 'git submodule absorbgitdir' too. Signed-off-by: Emily Shaffer <emilyshaffer@google.com> --- submodule.c | 10 ++++++++++ t/t7412-submodule-absorbgitdirs.sh | 1 + 2 files changed, 11 insertions(+)