Article View: linux.kernel.git
Article #3432[PATCH] builtin/clone: fix --revision with SHA-256 commits
From: Andrei Șova
Date: Fri, 20 Nov 2026 04:00
Date: Fri, 20 Nov 2026 04:00
101 lines
13676 bytes
13676 bytes
The refspec item is created before the destination repository's hash algorithm
is set up, so when cloning repositories using the SHA-256 object format
parse_refspec incorrectly parses the hash.
Signed-off-by: Andrei Șova <andreisva2023@gmail.com>
---
Hello Git developers,
I was messing around with a repository using the SHA-256 object format
and I noticed that --revision doesn't work if you give it a SHA-256
commit hash, so I put together this fix and a test case.
Thanks,
Andrei Șova
builtin/clone.c | 15 ++++++++++++++-
t/t5621-clone-revision.sh | 15 +++++++++++++++
2 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/builtin/clone.c b/builtin/clone.c
index 4b9929b980..69513a14c2 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -963,6 +963,7 @@ int cmd_clone(int argc,
struct string_list server_options = STRING_LIST_INIT_NODUP;
const char *bundle_uri = NULL;
char *option_rev = NULL;
+ int rev_refspec_idx = 0;
struct clone_opts opts = CLONE_OPTS_INIT;
@@ -1484,6 +1485,7 @@ int cmd_clone(int argc,
opts.wants_head = 0;
opts.detach = 1;
+ rev_refspec_idx = remote->fetch.nr;
refspec_append(&remote->fetch, option_rev);
}
@@ -1525,6 +1527,17 @@ int cmd_clone(int argc,
create_reference_database(the_repository, NULL, 1);
startup_info->have_repository = 1;
+ if (option_rev) {
+ /*
+ * Re-initialize the refspec since potential hashes might have been
+ * parsed under the wrong algorithm.
+ */
+ struct refspec_item *r = &remote->fetch.items[rev_refspec_idx];
+ refspec_item_clear(r);
+ if (!refspec_item_init_fetch(r, option_rev, the_repository->hash_algo))
+ die(_("invalid refspec '%s'"), option_rev);
+ }
+
/*
* Before fetching from the remote, download and install bundle
* data from the --bundle-uri option.
@@ -1588,7 +1601,7 @@ int cmd_clone(int argc,
}
}
- if (refs)
+ if (refs || (option_rev && remote->fetch.items[rev_refspec_idx].exact_sha1))
mapped_refs = wanted_peer_refs(&opts, refs, &remote->fetch);
if (mapped_refs) {
diff --git a/t/t5621-clone-revision.sh b/t/t5621-clone-revision.sh
index 54789423f8..1afac8abaa 100755
--- a/t/t5621-clone-revision.sh
+++ b/t/t5621-clone-revision.sh
@@ -78,6 +78,21 @@ test_expect_success 'clone with --revision being a raw commit hash' '
test_must_fail git -C dst config remote.origin.fetch
'
+test_expect_success 'clone with --revision being a raw SHA-256 commit hash' '
+ test_when_finished "rm -rf src256 dst256" &&
+ git init --object-format=sha256 src256 &&
+ test_commit -C src256 --no-tag "initial commit" &&
+ oid=$(git -C src256 rev-parse HEAD) &&
+ GIT_DEFAULT_HASH=sha1 git clone --no-local --revision=$oid src256 dst256 &&
+ echo $oid >expect &&
+ git -C dst256 rev-parse HEAD >actual &&
+ test_must_fail git -C dst256 symbolic-ref -q HEAD >/dev/null &&
+ test_cmp expect actual &&
+ git -C dst256 for-each-ref refs >actual &&
+ test_must_be_empty actual &&
+ test_must_fail git -C dst256 config remote.origin.fetch
+'
+
test_expect_success 'clone with --revision and --bare' '
test_when_finished "rm -rf dst" &&
git clone --revision=refs/heads/main --bare . dst &&
--
2.55.0
Technical Details
Message-ID:
<87mrr486sg.fsf@gmail.com>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-75894-linux-kernel-git=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-75894-linux-kernel-git=dewy.ru
From: andreisva2023@gmail.com (=?UTF-8?q?Andrei=20=C8=98ova?=)
Newsgroups: linux.kernel.git
Subject: [PATCH] builtin/clone: fix --revision with SHA-256 commits
Date: Thu, 19 Nov 2026 21:00:52 -0700
Organization: Usenet Network
Message-ID: <87mrr486sg.fsf@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
logging-data="3060781"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:tSpLgRB6T8ZDvBpjukyZLgudNYE= sha256:qiI26tIQ4ny5/fyYT5/sviyYhvGNkEXYaUW2APv40pk=
sha1:JV+uHmI+YFA78+gskxambdV9OWs= sha256:bHSFITVGF7O42Il9AMiqv1SvPdnpayy9fEQx15FJatY=
List-ID: <git.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 210081158A8; Fri, 20 Nov 2026 07:29:48 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id LyOj0WII1JE1;
Fri, 20 Nov 2026 07:29:40 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=git+bounces-75894-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
by mail.dewy.ru (Postfix) with ESMTPS id B0C551158A3; Fri, 20 Nov 2026 07:29:30 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by tor.lore.kernel.org (Postfix) with ESMTP id D78A7E736D; Fri, 20 Nov 2026 04:29:26 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1795148964;
b=qvVVFn3WlGX9MjwwHWSnAThgnSV8GjaUXKABx6SAizCuundFGgl56shOTggMuSA+LV0b
kI7DasotgmS45n3EkGdGlynXCsfRI4KWP+HaHIep2J5BxqnhuNsirRwJCe6WvcFLEG1dB
3By1v7XxXwvkgKncWjdZeUGAcRgR3DjjG3TARpdfn9w1o5paJllQ26wNQEdeZNQY6bk3L
8GEtX3++BldY7/Qi4EoPy6TWuMazhz4yYwCtfKIf4I+UI6qvlfw6c1QzSHtmMbWVvy4cY
c184lhtYa9gOh2nEcWkjGgOj0uxxWMrAq4gNNG5/Um2WorPWP/p3xzsM2vlyH9PvYLg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795148964;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
Received:From:To:Subject:Date:Message-ID:X-Mailing-List:List-Id:
List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
Precedence:MIME-Version:Content-Type:Content-Transfer-Encoding;
bh=XsS+XGqIdE4cMAz//wIwiKIBx3Jvlq91qULwS3a9eZs=;
b=MrKe/wR+IjIwPf2HBO4EhRFdksE21zWgx2TB4qk9E0Kor99HrHVz+4+FqH7fTEEeL+aM
9G8FFv/eLp3YZoCyNRNF1BAGIjV+1dvWSStCseJY7383JTop9XCfiQ45MAM+nxubohWaL
PwTHjnzNCYu7i287VQ0Fkf2rK/6gK+KYYFy7q60L4ke7DDlJy1p5e24+zSk5j6GLAizDr
rfyz8O0MzCOMOJ0jgVoHorjJyhM9NEzvx2WlsH6SLoUXmEUgpltKKYRgH+kgEd9G6mzyc
SNivheYaKML3alr6NQl964ukLO7nDMOpFjMp/eHGjGT2Y6IcXCiWPgjv5dsesQL089A==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="C/OrDSDR";
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 7AC64606A332;
Fri, 20 Nov 2026 04:29:24 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=C/OrDSDR
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.43
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1795148963;
b=El/+f6PsrRijk9AHIufg0olD4vP0RA8omD/J7rWj3USORk0mUD2MDrH2nfku6dZNn4R8
FzTJs8Npot9kvMNnld30pzNf620BqzlKznVpZf2QOVXzddB6ZBP18N75kAam8wx2cHyf2
d47Qd+d91RE1r3eEM7hTlJb9fwl7/oCVime2FJmRZDUzOLPt2dTof123PfA2fpmXWlwQr
tSL6aLfrFTqSrLZ+Df+mT2ztCL1OH4AWHrV+lHttj+KhTY+X0iZClNU05cl91iJlUP1rQ
Lu7dzBnlVXqw3wv9FSoOzspHb9a0QvcWMmP2gSNzCcOQ7He1WEmV6uTCSKrwPoDBGHw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795148963;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Subject:Date:
Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding;
bh=XsS+XGqIdE4cMAz//wIwiKIBx3Jvlq91qULwS3a9eZs=;
b=jXb9ZLbuLjQAxEn562npmQ4YkmwUshr+Ps6D8RfTZPxVcgZKcV1VKyuLLJzM5szQWN/6
FaoEYSw5VZ00Pvqji/Jaw0PVm642Hg8t9c63p2H9U3tLZOugvOXhe5kwyJ0NHiL3x+RJo
HLM9sC961ZB0SBJpM5cAeobA0y8yV9teYZtf0VABWktSFCQeXI3ln6rA1R7zCcmnPS3to
TxULlcxOcTmNBLUmnvCmRYMjpm5pMnT/4QK+EDEaezyBB6FpgZVdZoeIxmHEzsK8xzyxT
aM8UxD2ktht49LaoGQcbFsGXTwqwG5y3Ba5B50bbsIGd9pIcwKOn5fL94HjufdKaPkA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="C/OrDSDR";
arc=none smtp.remote-ip=209.85.216.43
X-Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 40885606A320
for <git@vger.kernel.org>; Fri, 20 Nov 2026 04:29:23 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 40885606A320
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-3b1bb072438so53472a91.1
for <git@vger.kernel.org>; Thu, 19 Nov 2026 20:29:23 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1795148962; x=1795753762; darn=vger.kernel.org;
h=content-transfer-encoding:content-type:mime-version:message-id:date
:subject:to:from:from:to:cc:subject:date:message-id:reply-to
:content-type;
bh=XsS+XGqIdE4cMAz//wIwiKIBx3Jvlq91qULwS3a9eZs=;
b=C/OrDSDRzXsfKIdkaejBbV1SfKQKWpXzvCjRlcD3zaHLYzNO36KmBflYUNMqiJvcBZ
ViiHKt73wgGlAUqd3prbKjbpvThBFO4dd3DPOVjvpf91lnFbZIDOQFPEzD2vvsypi7pd
yaE8+o3AQW1kqKJieDniEsbT8I8LRXzWsFPpt8iqNOozjvioqkhgncL6i6VEb78j6ikL
gNMKEqoIvk083cUg53mtlJt8yhoE0PAyXrsJ++2snPFiC2Nnw5HWa9xdbXJSzPdfov+N
Vhwu7he1V3TsCzhyw/dhqMNhVdS+eS40RxAjLlSVz9oxWIp2vdfVGS3T77QZVFqGHzCk
EfEA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1795148962; x=1795753762;
h=content-transfer-encoding:content-type:mime-version:message-id:date
:subject:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=XsS+XGqIdE4cMAz//wIwiKIBx3Jvlq91qULwS3a9eZs=;
b=Sx0amHCg5DSbJ5RN+GsjnNPRlCgd4H/t35HXMCrcds+4Ih7n88RxvxPwymcHiYtnCe
DSlZaCGnj0ShxJ5Psi8HXNBlu1uDXhdk85fcKZJxMScNZ7EG8SA2iYt0YImrgzMWJBUi
0T7WXd5w2+FF+ShMoLVsjXZXtcJtfV6edN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MTP id 98e67ed59e1d1-3b41c7d65c2mr2521869a91.1.1795148962441;
Thu, 19 Nov 2026 20:29:22 -0800 (PST)
X-Received: from pamplemousse ([2604:3d08:9d7b:1d10::e3f])
by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b40f4312dfsm4011442a91.3.2026.11.19.20.29.20
for <git@vger.kernel.org>
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Thu, 19 Nov 2026 20:29:20 -0800 (PST)
X-Mailing-List: git@vger.kernel.org
X-List-Post: <mailto:git@vger.kernel.org>
X-List-Help: <mailto:git+help@vger.kernel.org>
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:git+owner@vger.kernel.org>
X-Precedence: list