--- v2
+++ v5
@@ -1,37 +1,36 @@
-Already during 'git submodule add' we cache a pointer to the
+Already during 'git submodule add' we record 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.
+submodule absorbgitdirs'. Let's start adding that pointer during 'git
+submodule absorbgitdirs' 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(-)
+ submodule.c | 9 ++++++
+ t/t7412-submodule-absorbgitdirs.sh | 50 ++++++++++++++++++++++++++++--
+ 2 files changed, 57 insertions(+), 2 deletions(-)
diff --git a/submodule.c b/submodule.c
-index 0b1d9c1dde..4b314bf09c 100644
+index c689070524..2e54dcf1a2 100644
--- a/submodule.c
+++ b/submodule.c
-@@ -2065,6 +2065,7 @@ static void relocate_single_git_dir_into_superproject(const char *path)
+@@ -2097,6 +2097,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;
+ struct strbuf new_gitdir = STRBUF_INIT;
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)
+@@ -2127,6 +2128,14 @@ 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));
++ relative_path(absolute_path(get_git_common_dir()),
++ real_new_git_dir, &sb));
+
+ strbuf_release(&config_path);
+ strbuf_release(&sb);
@@ -39,10 +38,10 @@
free(real_old_git_dir);
free(real_new_git_dir);
diff --git a/t/t7412-submodule-absorbgitdirs.sh b/t/t7412-submodule-absorbgitdirs.sh
-index 1cfa150768..e2d78e01df 100755
+index 1cfa150768..b6f229043d 100755
--- a/t/t7412-submodule-absorbgitdirs.sh
+++ b/t/t7412-submodule-absorbgitdirs.sh
-@@ -30,7 +30,14 @@ test_expect_success 'absorb the git dir' '
+@@ -30,7 +30,17 @@ 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 &&
@@ -50,14 +49,67 @@
+ 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 &&
++ submodule_gitdir="$(git -C sub1 rev-parse --path-format=absolute --git-common-dir)" &&
++ superproject_gitdir="$(git rev-parse --path-format=absolute --git-common-dir)" &&
++
++ test-tool path-utils relative_path "$superproject_gitdir" \
++ "$submodule_gitdir" >expect &&
++ git -C sub1 config submodule.superprojectGitDir >actual &&
+
+ test_cmp expect actual
'
test_expect_success 'absorbing does not fail for deinitialized submodules' '
+@@ -61,7 +71,16 @@ test_expect_success 'absorb the git dir in a nested submodule' '
+ git status >actual.1 &&
+ git -C sub1/nested rev-parse HEAD >actual.2 &&
+ test_cmp expect.1 actual.1 &&
+- test_cmp expect.2 actual.2
++ test_cmp expect.2 actual.2 &&
++
++ sub1_gitdir="$(git -C sub1 rev-parse --path-format=absolute --git-common-dir)" &&
++ sub1_nested_gitdir="$(git -C sub1/nested rev-parse --path-format=absolute --git-common-dir)" &&
++
++ test-tool path-utils relative_path "$sub1_gitdir" "$sub1_nested_gitdir" \
++ >expect &&
++ git -C sub1/nested config submodule.superprojectGitDir >actual &&
++
++ test_cmp expect actual
+ '
+
+ test_expect_success 're-setup nested submodule' '
+@@ -130,4 +149,31 @@ test_expect_success 'absorbing fails for a submodule with multiple worktrees' '
+ test_i18ngrep "not supported" error
+ '
+
++test_expect_success 'absorbgitdirs works when called from a superproject worktree' '
++ # set up a worktree of the superproject
++ git worktree add wt &&
++ (
++ cd wt &&
++
++ # create a new unembedded git dir
++ git init sub4 &&
++ test_commit -C sub4 first &&
++ git submodule add ./sub4 &&
++ test_tick &&
++
++ # absorb the git dir
++ git submodule absorbgitdirs sub4 &&
++
++ # make sure the submodule cached the superproject gitdir correctly
++ submodule_gitdir="$(git -C sub4 rev-parse --path-format=absolute --git-common-dir)" &&
++ superproject_gitdir="$(git rev-parse --path-format=absolute --git-common-dir)" &&
++
++ test-tool path-utils relative_path "$superproject_gitdir" \
++ "$submodule_gitdir" >expect &&
++ git -C sub4 config submodule.superprojectGitDir >actual &&
++
++ test_cmp expect actual
++ )
++'
++
+ test_done
--
-2.32.0.272.g935e593368-goog
+2.34.0.rc0.344.g81b53c2807-goog