@@ -2065,6 +2065,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 "
@@ -2096,6 +2097,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);
@@ -30,7 +30,14 @@ test_expect_success 'absorb the git dir' '
git status >actual.1 &&
git -C sub1 rev-parse HEAD >actual.2 &&
test_cmp expect.1 actual.1 &&
- test_cmp expect.2 actual.2
+ test_cmp expect.2 actual.2 &&
+
+ # make sure the submodule cached the superproject gitdir correctly
+ test-tool path-utils real_path . >expect &&
+ test-tool path-utils real_path \
+ "$(git -C sub1 config submodule.superprojectGitDir)" >actual &&
+
+ test_cmp expect actual
'
test_expect_success 'absorbing does not fail for deinitialized submodules' '
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 | 9 ++++++++- 2 files changed, 18 insertions(+), 1 deletion(-)