@@ -449,6 +449,20 @@ cmd_update()
;;
esac
+ # Cache a pointer to the superproject's gitdir. This may have
+ # changed, unless it's a fresh clone. Writes it to worktree
+ # if applicable, otherwise to local.
+ if test -z "$just_cloned"
+ then
+ sm_gitdir="$(git -C "$sm_path" rev-parse --absolute-git-dir)"
+ relative_gitdir="$(git rev-parse --path-format=relative \
+ --prefix "${sm_gitdir}" \
+ --git-dir)"
+
+ git -C "$sm_path" config --worktree \
+ submodule.superprojectgitdir "$relative_gitdir"
+ fi
+
if test -n "$recursive"
then
(
@@ -1061,4 +1061,16 @@ test_expect_success 'submodule update --quiet passes quietness to fetch with a s
)
'
+test_expect_success 'submodule update adds superproject gitdir to older repos' '
+ (cd super &&
+ git -C submodule config --unset submodule.superprojectGitdir &&
+ git submodule update &&
+ test-tool path-utils relative_path \
+ "$(git rev-parse --absolute-git-dir)" \
+ "$(git -C submodule rev-parse --absolute-git-dir)" >expect &&
+ git -C submodule config submodule.superprojectGitdir >actual &&
+ test_cmp expect actual
+ )
+'
+
test_done
A recorded hint path to the superproject's gitdir might be added during 'git submodule add', but in some cases - like submodules which were created before 'git submodule add' learned to record that info - it might be useful to update the hint. Let's do it during 'git submodule update', when we already have a handle to the superproject while calling operations on the submodules. Signed-off-by: Emily Shaffer <emilyshaffer@google.com> --- git-submodule.sh | 14 ++++++++++++++ t/t7406-submodule-update.sh | 12 ++++++++++++ 2 files changed, 26 insertions(+)