Subject: [PATCH 9/9] t: add gitdir encoding tests

From: Adrian Ratiu <[email-masked]>
Date: Sun, 17 Aug 2025 00:36:42 +0300

Add some tests to further exercise the gitdir encoding functionality
alongside the existing mixed directory and nested gitdir tests.

Signed-off-by: Adrian Ratiu <[email-masked]>
---
 t/t7425-submodule-mixed-gitdir-paths.sh | 52 +++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/t/t7425-submodule-mixed-gitdir-paths.sh b/t/t7425-submodule-mixed-gitdir-paths.sh
index 902b2560ca..cfdf487a56 100755
--- a/t/t7425-submodule-mixed-gitdir-paths.sh
+++ b/t/t7425-submodule-mixed-gitdir-paths.sh
@@ -152,4 +152,56 @@ test_expect_success 'checkout -f --recurse-submodules must corectly handle neste
 	verify_submodule_gitdir_path clone_nested hippo/hooks submodules/hippo%2fhooks
 '
 
+test_expect_success 'new style submodule gitdir paths are properly encoded' '
+	(
+		cd main &&
+
+		# add new-style submodule name containing /
+		git submodule add ../new-sub foo/bar &&
+		git commit -m "add foo/bar" &&
+
+		# simulate existing legacy submodule name containing escaping char %
+		git clone --separate-git-dir .git/modules/foo%bar ../legacy-sub foo%bar  &&
+		cat >>.gitmodules <<-EOF &&
+		[submodule "foo%bar"]
+			path = foo%bar
+			url = ../legacy-sub
+		EOF
+		git add .gitmodules &&
+		git commit -m "add foo%bar" &&
+
+		# add new style submodule name containing escaping char %
+		git submodule add ../new-sub fooish%bar &&
+		git commit -m "add fooish%bar" &&
+
+		# add a mixed case submdule name
+		git submodule add ../new-sub FooBar &&
+		git commit -m "add FooBar" &&
+
+		# add a reserved name on Windows
+		git submodule add ../new-sub COM1 &&
+		git commit -m "add COM1"
+	) &&
+	verify_submodule_gitdir_path main foo/bar submodules/foo%2fbar &&
+	verify_submodule_gitdir_path main foo%bar modules/foo%bar &&
+	verify_submodule_gitdir_path main fooish%bar submodules/fooish%25bar &&
+	verify_submodule_gitdir_path main FooBar submodules/_foo_bar &&
+	verify_submodule_gitdir_path main COM1 submodules/_c_o_m1
+'
+
+test_expect_success 'submodule encoded name exceeds max name limit' '
+	(
+		cd main &&
+
+		# find the system NAME_MAX (fall back to 255 if unknown)
+		name_max=$(getconf NAME_MAX . 2>/dev/null || echo 255) &&
+
+		# each "%" char encodes to "%25" (3 chars), ensure we exceed NAME_MAX
+		count=$((name_max + 10)) &&
+		longname=$(printf "%%%0.s" $(seq 1 $count)) &&
+
+		test_must_fail git submodule add ../new-sub "$longname"
+	)
+'
+
 test_done
-- 
2.50.1.679.gbf363a8fbb.dirty