@@ -98,5 +98,5 @@ submodule.superprojectGitDir::
reference to determine whether the current repo is a submodule to
another repo; if this reference is absent, Git will treat the current
repo as though it is not a submodule (this does not make a difference to
- most Git commands). It is set automatically during submodule creation
- and 'git submodule absorbgitdir'.
+ most Git commands). It is set automatically during submodule creation,
+ update, and 'git submodule absorbgitdir'.
@@ -449,6 +449,21 @@ cmd_update()
;;
esac
+ # Store a poitner to the superproject's gitdir. This may have
+ # changed, unless it's a fresh clone. Write to worktree if
+ # applicable, and point to superproject's worktree gitdir if
+ # applicable.
+ 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,31 @@ 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_expect_success 'submodule update uses config.worktree if applicable' '
+ (cd super &&
+ git -C submodule config --unset submodule.superprojectGitDir &&
+ git -C submodule config extensions.worktreeConfig true &&
+ 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_file_not_empty "$(git -C submodule rev-parse --absolute-git-dir)/config.worktree"
+ )
+'
+
test_done
A recorded 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 pointer. 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> --- Documentation/config/submodule.txt | 4 ++-- git-submodule.sh | 15 +++++++++++++++ t/t7406-submodule-update.sh | 27 +++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-)