# Fix proposed for git clone --revision when the commit hash is SHA-256

_The refspec is parsed before the hash algorithm is known, so valid commit IDs in a non-default format are rejected._

Section: Patches. Edition of 2026-11-21. Written by an AI editor from the thread "[PATCH] builtin/clone: fix --revision with SHA-256 commits" (4 messages): https://gitlist.dev/t/66892

Andrei Șova sent a patch to builtin/clone.c with a test in t5621. The bug: git clone --revision fails when given a valid commit hash in an algorithm that does not match the default. Under protocol v2 it dies with "Remote revision ... not found in upstream origin". Under protocol v1 the message is "couldn't find remote ref".

The cause, per Șova, is that the refspec item is created before the destination repository's hash algorithm is set up, so parse_refspec parses the hash incorrectly. The first patch delayed initializing the refspec item until the remote's hash algorithm was known.

Junio C Hamano asked for improvements to the commit message. He wanted it to state what fails for the user, including the different messages under protocol v2 and v0/v1. He also noted that the problem occurs in the opposite direction too, whenever the default hash differs from the remote's, so the title should be reworded rather than saying "with SHA-256".

Şova explained that simply delaying initialization does not work. The ref prefixes need to be set up before fetching remote refs, which is how the remote hash algorithm is learned, and they depend on the refspec item. After looking at refspec_ref_prefixes, he now thinks it is acceptable not to initialize the prefixes when --revision is used, since as far as he understands they are only an optimization. This would also remove an extra case in the "if (refs)" check. A revised patch has not yet appeared in the excerpts.
