Adrian Ratiu, working on sha256 remote support in Jujutsu (which uses Git for networking), noted there is no way to get a repository's object format without cloning it. Clone learns it from the protocol handshake but does not show it anywhere else.

His patch describes two problems with the current workflow. If the remote has refs, git fetch into a mismatched empty repository can fail with a format error, and git ls-remote only shows the format indirectly through object ID length, which would stop working if a future hash had the same length as an existing one. If the remote is empty, ls-remote prints nothing and fetch succeeds, so the new local repository can silently get the wrong format, which only shows up later.

Junio Hamano checked that transport_get_hash_algo() returns the hash algorithm relayed from connect.c:get_remote_refs(). Even over an old protocol that does not declare a format, it yields GIT_HASH_SHA1_LEGACY, so there is no unknown case to handle. He said the patch looks good and that existing tests give adequate coverage.