aboutsummaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorAdrian Ratiu <adrian.ratiu@collabora.com>2026-01-12 20:46:29 +0200
committerJunio C Hamano <gitster@pobox.com>2026-01-12 11:56:56 -0800
commit920fbe4d4ee8d4e191d33dde05a16ee0e74bdd44 (patch)
tree7c34bcb0415a2e96f886b20e106bd244c6753b98 /t
parent226694bdf4aaecd18f6cd4df12656cc61b213d16 (diff)
downloadgit-920fbe4d4ee8d4e191d33dde05a16ee0e74bdd44.tar.xz
submodule--helper: fix filesystem collisions by encoding gitdir paths
Fix nested filesystem collisions by url-encoding gitdir paths stored in submodule.%s.gitdir, when extensions.submodulePathConfig is enabled. Credit goes to Junio and Patrick for coming up with this design: the encoding is only applied when necessary, to newly added submodules. Existing modules don't need the encoding because git already errors out when detecting nested gitdirs before this patch. This commit adds the basic url-encoding and some tests. Next commits extend the encode -> validate -> retry loop to fix more conflicts. Suggested-by: Junio C Hamano <gitster@pobox.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>
Diffstat (limited to 't')
-rwxr-xr-xt/t7425-submodule-gitdir-path-extension.sh57
1 files changed, 57 insertions, 0 deletions
diff --git a/t/t7425-submodule-gitdir-path-extension.sh b/t/t7425-submodule-gitdir-path-extension.sh
index 89e2feab8b..ce1428a2ff 100755
--- a/t/t7425-submodule-gitdir-path-extension.sh
+++ b/t/t7425-submodule-gitdir-path-extension.sh
@@ -346,4 +346,61 @@ test_expect_success '`git clone --recurse-submodules` works after migration' '
)
'
+test_expect_success 'setup submodules with nested git dirs' '
+ git init nested &&
+ test_commit -C nested nested &&
+ (
+ cd nested &&
+ cat >.gitmodules <<-EOF &&
+ [submodule "hippo"]
+ url = .
+ path = thing1
+ [submodule "hippo/hooks"]
+ url = .
+ path = thing2
+ EOF
+ git clone . thing1 &&
+ git clone . thing2 &&
+ git add .gitmodules thing1 thing2 &&
+ test_tick &&
+ git commit -m nested
+ )
+'
+
+test_expect_success 'git dirs of encoded sibling submodules must not be nested' '
+ git clone -c extensions.submodulePathConfig=true --recurse-submodules nested clone_nested &&
+
+ verify_submodule_gitdir_path clone_nested hippo modules/hippo &&
+ git -C clone_nested config submodule.hippo.gitdir >actual &&
+ test_grep "\.git/modules/hippo$" actual &&
+
+ verify_submodule_gitdir_path clone_nested hippo/hooks modules/hippo%2fhooks &&
+ git -C clone_nested config submodule.hippo/hooks.gitdir >actual &&
+ test_grep "\.git/modules/hippo%2fhooks$" actual
+'
+
+test_expect_success 'submodule git dir nesting detection must work with parallel cloning' '
+ git clone -c extensions.submodulePathConfig=true --recurse-submodules --jobs=2 nested clone_parallel &&
+
+ verify_submodule_gitdir_path clone_parallel hippo modules/hippo &&
+ git -C clone_nested config submodule.hippo.gitdir >actual &&
+ test_grep "\.git/modules/hippo$" actual &&
+
+ verify_submodule_gitdir_path clone_parallel hippo/hooks modules/hippo%2fhooks &&
+ git -C clone_nested config submodule.hippo/hooks.gitdir >actual &&
+ test_grep "\.git/modules/hippo%2fhooks$" actual
+'
+
+test_expect_success 'disabling extensions.submodulePathConfig prevents nested submodules' '
+ (
+ cd clone_nested &&
+ # disable extension and verify failure
+ git config --replace-all extensions.submodulePathConfig false &&
+ test_must_fail git submodule add ./thing2 hippo/foobar &&
+ # re-enable extension and verify it works
+ git config --replace-all extensions.submodulePathConfig true &&
+ git submodule add ./thing2 hippo/foobar
+ )
+'
+
test_done