strbuf_release(&sb);
break;
case S_IFDIR:
- return repo_resolve_gitlink_ref(istate->repo, path, "HEAD", oid);
+ if (repo_resolve_gitlink_ref(istate->repo, path, "HEAD", oid))
+ return -1;
+ if (&hash_algos[oid->algo] != istate->repo->hash_algo)
+ return error(_("cannot add a submodule of a different hash algorithm"));
+ break;
default:
return error(_("%s: unsupported file type"), path);
}
)
'
+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" &&
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
'