aboutsummaryrefslogtreecommitdiffstats
path: root/t/lib-verify-submodule-gitdir-path.sh
diff options
context:
space:
mode:
authorAdrian Ratiu <adrian.ratiu@collabora.com>2025-11-07 17:05:46 +0200
committerJunio C Hamano <gitster@pobox.com>2025-11-07 09:01:11 -0800
commit829f0f6b5ae1dced0e6b7a6a819b010845f1d119 (patch)
tree288353641ea76bbfbc23a106a564ab958c233242 /t/lib-verify-submodule-gitdir-path.sh
parentbuiltin/credential-store: move is_rfc3986_unreserved to url.[ch] (diff)
downloadgit-829f0f6b5ae1dced0e6b7a6a819b010845f1d119.tar.gz
git-829f0f6b5ae1dced0e6b7a6a819b010845f1d119.zip
submodule: add extension to encode gitdir paths
Add a submoduleEncoding extension which fixes filesystem collisions by encoding gitdir paths. At a high level, this implements a mechanism to encode -> validate -> retry until a working gitdir path is found. Credit goes to Junio for coming up with this design: encoding is only applied when necessary, e.g. uppercase characters are encoded only on case-folding filesystems and only if a real conflict is detected. To make this work, we rely on the submodule.<name>.gitdir config as the single source of truth for gitidir paths: the config is always set when the extension is enabled. Users who care about gitdir paths are expected to get/set the config and not the underlying encoding implementation. This commit adds the basic encoding logic which addresses nested gitdirs. The next commit fixes case-folding, the next commit fixes names longer than NAME_MAX. The idea is the encoding can be improved over time in a way which is transparent to users. Suggested-by: Junio C Hamano <gitster@pobox.com> Suggested-by: Phillip Wood <phillip.wood123@gmail.com> Suggested-by: Patrick Steinhardt <ps@pks.im> Based-on-patch-by: Brandon Williams <bwilliams.eng@gmail.com> Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/lib-verify-submodule-gitdir-path.sh')
-rw-r--r--t/lib-verify-submodule-gitdir-path.sh24
1 files changed, 24 insertions, 0 deletions
diff --git a/t/lib-verify-submodule-gitdir-path.sh b/t/lib-verify-submodule-gitdir-path.sh
new file mode 100644
index 0000000000..62794df976
--- /dev/null
+++ b/t/lib-verify-submodule-gitdir-path.sh
@@ -0,0 +1,24 @@
+# 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
+ )
+}