summaryrefslogtreecommitdiff
path: root/object-file.c
diff options
context:
space:
mode:
authorbrian m. carlson <sandals@crustytoothpaste.net>2025-11-15 00:58:17 +0000
committerJunio C Hamano <gitster@pobox.com>2025-11-15 11:51:37 -0800
commit66c78e0653a4e60c625b8400da31da0ba5bd1286 (patch)
treebae64a12e70c9537d7ce2eafd340de38bcb91e49 /object-file.c
parentbb5c624209fcaebd60b9572b2cc8c61086e39b57 (diff)
object-file: disallow adding submodules of different hash algo
The design of the hash algorithm transition plan is that objects stored must be entirely in one algorithm since we lack any way to indicate a mix of algorithms. This also includes submodules, but we have traditionally not enforced this, which leads to various problems when trying to clone or check out the the submodule from the remote. Since this cannot work in the general case, restrict adding a submodule of a different algorithm to the index. Add tests for git add and git submodule add that these are rejected. Note that we cannot check this in git fsck because the malformed submodule is stored in the tree as an object ID which is either truncated (when a SHA-256 submodule is added to a SHA-1 repository) or padded with zeros (when a SHA-1 submodule is added to a SHA-256 repository). We cannot detect even the latter case because someone could have an actual submodule that actually ends in 24 zeros, which would be a false positive. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'object-file.c')
-rw-r--r--object-file.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/object-file.c b/object-file.c
index 2bc36ab3ee..6ff6cf7549 100644
--- a/object-file.c
+++ b/object-file.c
@@ -1296,7 +1296,11 @@ int index_path(struct index_state *istate, struct object_id *oid,
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);
}