aboutsummaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorAdrian Ratiu <adrian.ratiu@collabora.com>2026-01-12 20:46:32 +0200
committerJunio C Hamano <gitster@pobox.com>2026-01-12 11:56:57 -0800
commite897c9b7f31cf83e93cfefe1f82eb4a18337c9b1 (patch)
tree2f4df5ed1d0fb4172b00e9770a86a186d87fc71e /t
parent82c36fa0a987c9c8617f5ded41834f7487e616e2 (diff)
downloadgit-e897c9b7f31cf83e93cfefe1f82eb4a18337c9b1.tar.xz
submodule: detect conflicts with existing gitdir configs
Credit goes to Emily and Josh for testing and noticing a corner-case which caused conflicts with existing gitdir configs to silently pass validation, then fail later in add_submodule() with a cryptic error: fatal: A git directory for 'nested%2fsub' is found locally with remote(s): origin /.../trash directory.t7425-submodule-gitdir-path-extension/sub This change ensures the validation step checks existing gitdirs for conflicts. We only have to do this for submodules having gitdirs, because those without submodule.%s.gitdir need to be migrated and will throw an error earlier in the submodule codepath. Quoting Josh: My testing setup has been as follows: * Using our locally-built Git with our downstream patch of [1] included: * create a repo "sub" * create a repo "super" * In "super": * mkdir nested * git submodule add ../sub nested/sub * Verify that the submodule's gitdir is .git/modules/nested%2fsub * Using a build of git from upstream `next` plus this series: * git config set --global extensions.submodulepathconfig true * git clone --recurse-submodules super super2 * create a repo "nested%2fsub" * In "super2": * git submodule add ../nested%2fsub At this point I'd expect the collision detection / encoding to take effect, but instead I get the error listed above. End quote Suggested-by: Josh Steadmon <steadmon@google.com> 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.sh28
1 files changed, 28 insertions, 0 deletions
diff --git a/t/t7425-submodule-gitdir-path-extension.sh b/t/t7425-submodule-gitdir-path-extension.sh
index a76e64a9f7..ea86ecf7ee 100755
--- a/t/t7425-submodule-gitdir-path-extension.sh
+++ b/t/t7425-submodule-gitdir-path-extension.sh
@@ -497,4 +497,32 @@ test_expect_success CASE_INSENSITIVE_FS 'verify hashing conflict resolution as a
verify_submodule_gitdir_path cloned-hash "Foo" "modules/${hash}"
'
+test_expect_success 'submodule gitdir conflicts with previously encoded name (local config)' '
+ git init -b main super_with_encoded &&
+ (
+ cd super_with_encoded &&
+
+ git config core.repositoryformatversion 1 &&
+ git config extensions.submodulePathConfig true &&
+
+ # Add a submodule with a nested path
+ git submodule add --name "nested/sub" ../sub nested/sub &&
+ test_commit add-encoded-gitdir &&
+
+ verify_submodule_gitdir_path . "nested/sub" "modules/nested%2fsub" &&
+ test_path_is_dir ".git/modules/nested%2fsub"
+ ) &&
+
+ # create a submodule that will conflict with the encoded gitdir name:
+ # the existing gitdir is ".git/modules/nested%2fsub", which is used
+ # by "nested/sub", so the new submod will get another (non-conflicting)
+ # name: "nested%252fsub".
+ (
+ cd super_with_encoded &&
+ git submodule add ../sub "nested%2fsub" &&
+ verify_submodule_gitdir_path . "nested%2fsub" "modules/nested%252fsub" &&
+ test_path_is_dir ".git/modules/nested%252fsub"
+ )
+'
+
test_done