From 489b174bc03f00ff0f28ab65c9c7ed4aaacbe8fc Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Wed, 14 Jan 2026 21:05:44 -0500 Subject: [PATCH 1/2] fix(git): `src` in refspec must be full hash or a real ref This works: ``` git fetch https://github.com/rust-lang/cargo '+d559ea31ecab7ff1db8a1a9d98029891f32f6f4b:refs/remotes/origin/HEAD' ``` This doesn't: ``` git fetch https://github.com/rust-lang/cargo '+d559ea:refs/remotes/origin/HEAD' ``` --- src/cargo/sources/git/utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cargo/sources/git/utils.rs b/src/cargo/sources/git/utils.rs index 878d71f9ac6..8ebeacc879c 100644 --- a/src/cargo/sources/git/utils.rs +++ b/src/cargo/sources/git/utils.rs @@ -1007,7 +1007,7 @@ pub fn fetch( fast_path_rev = true; refspecs.push(format!("+{0}:refs/commit/{0}", oid_to_fetch)); } else if !matches!(shallow, gix::remote::fetch::Shallow::NoChange) - && rev.parse::().is_ok() + && rev_to_oid(rev).is_some() { // There is a specific commit to fetch and we will do so in shallow-mode only // to not disturb the previous logic. From 4407f1a64cdec089f7ce87d9bf858aadd2ce6782 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Wed, 14 Jan 2026 21:07:13 -0500 Subject: [PATCH 2/2] fix(git): ensure GitHub responds full hash It is unlikely the responses is partial hash, though Oid::from_str has issue of padding zeros, so we being a bit defensive here. --- src/cargo/sources/git/utils.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cargo/sources/git/utils.rs b/src/cargo/sources/git/utils.rs index 8ebeacc879c..d0668fc55a8 100644 --- a/src/cargo/sources/git/utils.rs +++ b/src/cargo/sources/git/utils.rs @@ -1569,8 +1569,10 @@ fn github_fast_path( if response_code == 304 { debug!("github fast path up-to-date"); Ok(FastPathRev::UpToDate) - } else if response_code == 200 { - let oid_to_fetch = str::from_utf8(&response_body)?.parse::()?; + } else if response_code == 200 + && let Some(oid_to_fetch) = rev_to_oid(str::from_utf8(&response_body)?) + { + // response expected to be a full hash hexstring (40 or 64 chars) debug!("github fast path fetch {oid_to_fetch}"); Ok(FastPathRev::NeedsFetch(oid_to_fetch)) } else {