aboutsummaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2025-11-24 15:46:39 -0800
committerJunio C Hamano <gitster@pobox.com>2025-11-24 15:46:40 -0800
commitd91d79f26d5f2fb0468f42bf5d44356dce15a414 (patch)
treede53faa3734dbc893bceabc212dfdbd70ffa5acf /t
parent54f7817456940bb1f72cb747328e5fde75307dc3 (diff)
parent6fe288bfbcbbabc3d399dd71f876dccf71affff0 (diff)
downloadgit-d91d79f26d5f2fb0468f42bf5d44356dce15a414.tar.xz
Merge branch 'bc/submodule-force-same-hash'
Adding a repository that uses a different hash function is a no-no, but "git submodule add" did nt prevent it, which has been corrected. * bc/submodule-force-same-hash: read-cache: drop submodule check from add_to_cache() object-file: disallow adding submodules of different hash algo
Diffstat (limited to 't')
-rwxr-xr-xt/t3700-add.sh26
-rwxr-xr-xt/t7400-submodule-basic.sh25
2 files changed, 51 insertions, 0 deletions
diff --git a/t/t3700-add.sh b/t/t3700-add.sh
index df580a5806..af93e53c12 100755
--- a/t/t3700-add.sh
+++ b/t/t3700-add.sh
@@ -388,6 +388,7 @@ test_expect_success 'error on a repository with no commits' '
test_must_fail git add empty >actual 2>&1 &&
cat >expect <<-EOF &&
error: '"'empty/'"' does not have a commit checked out
+ error: unable to index file '"'empty/'"'
fatal: adding files failed
EOF
test_cmp expect actual
@@ -541,6 +542,31 @@ test_expect_success 'all statuses changed in folder if . is given' '
)
'
+test_expect_success 'cannot add a submodule of a different algorithm' '
+ git init --object-format=sha256 sha256 &&
+ (
+ cd sha256 &&
+ test_commit abc &&
+ git init --object-format=sha1 submodule &&
+ test_commit -C submodule def &&
+ test_must_fail git add submodule 2>err &&
+ test_grep "cannot add a submodule of a different hash algorithm" err &&
+ git ls-files --stage >entries &&
+ test_grep ! ^160000 entries
+ ) &&
+ git init --object-format=sha1 sha1 &&
+ (
+ cd sha1 &&
+ test_commit abc &&
+ git init --object-format=sha256 submodule &&
+ test_commit -C submodule def &&
+ test_must_fail git add submodule 2>err &&
+ test_grep "cannot add a submodule of a different hash algorithm" err &&
+ git ls-files --stage >entries &&
+ test_grep ! ^160000 entries
+ )
+'
+
test_expect_success CASE_INSENSITIVE_FS 'path is case-insensitive' '
path="$(pwd)/BLUB" &&
touch "$path" &&
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index fd3e7e355e..e6b551daad 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -407,6 +407,31 @@ test_expect_success 'submodule add in subdirectory with relative path should fai
test_grep toplevel output.err
'
+test_expect_success 'submodule add of a different algorithm fails' '
+ git init --object-format=sha256 sha256 &&
+ (
+ cd sha256 &&
+ test_commit abc &&
+ git init --object-format=sha1 submodule &&
+ test_commit -C submodule def &&
+ test_must_fail git submodule add "$submodurl" submodule 2>err &&
+ test_grep "cannot add a submodule of a different hash algorithm" err &&
+ git ls-files --stage >entries &&
+ test_grep ! ^160000 entries
+ ) &&
+ git init --object-format=sha1 sha1 &&
+ (
+ cd sha1 &&
+ test_commit abc &&
+ git init --object-format=sha256 submodule &&
+ test_commit -C submodule def &&
+ test_must_fail git submodule add "$submodurl" submodule 2>err &&
+ test_grep "cannot add a submodule of a different hash algorithm" err &&
+ git ls-files --stage >entries &&
+ test_grep ! ^160000 entries
+ )
+'
+
test_expect_success 'setup - add an example entry to .gitmodules' '
git config --file=.gitmodules submodule.example.url git://example.com/init.git
'