git/t/lib-verify-submodule-gitdir-path.sh
Adrian Ratiu 7ad97f4bea submodule: introduce extensions.submodulePathConfig
The idea of this extension is to abstract away the submodule gitdir
path implementation: everyone is expected to use the config and not
worry about how the path is computed internally, either in git or
other implementations.

With this extension enabled, the submodule.<name>.gitdir repo config
becomes the single source of truth for all submodule gitdir paths.

The submodule.<name>.gitdir config is added automatically for all new
submodules when this extension is enabled.

Git will throw an error if the extension is enabled and a config is
missing, advising users how to migrate. Migration is manual for now.

E.g. to add a missing config entry for an existing "foo" module:
git config submodule.foo.gitdir .git/modules/foo

Suggested-by: Junio C Hamano <gitster@pobox.com>
Suggested-by: Phillip Wood <phillip.wood123@gmail.com>
Suggested-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-01-08 11:05:15 +09:00

25 lines
880 B
Bash

# Helper to verify if repo $1 contains a submodule named $2 with gitdir path $3
# This does not check filesystem existence. That is done in submodule.c via the
# submodule_name_to_gitdir() API which this helper ends up calling. The gitdirs
# might or might not exist (e.g. when adding a new submodule), so this only
# checks the expected configuration path, which might be overridden by the user.
verify_submodule_gitdir_path () {
repo="$1" &&
name="$2" &&
path="$3" &&
(
cd "$repo" &&
# Compute expected absolute path
expected="$(git rev-parse --git-common-dir)/$path" &&
expected="$(test-tool path-utils real_path "$expected")" &&
# Compute actual absolute path
actual="$(git submodule--helper gitdir "$name")" &&
actual="$(test-tool path-utils real_path "$actual")" &&
echo "$expected" >expect &&
echo "$actual" >actual &&
test_cmp expect actual
)
}