Skip to content

Commit 5da2858

Browse files
committed
Auto merge of #13718 - ehuss:github-fast-path-redirect, r=weihanglo
Fix github fast path redirect. This fixes the GitHub fast-path check to look up the sha of a git ref. At some point, GitHub changed the API to redirect to a different URL. Currently cargo is failing the fast-path lookup with 301 response code. This can be tested in a project with a git dependency, and running `CARGO_LOG=cargo::sources::git::utils=debug cargo fetch` to verify it is picking up the fast path. This currently can't be tested in CI due to #13563.
2 parents c00bbc1 + 5836a96 commit 5da2858

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Diff for: src/cargo/sources/git/utils.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,7 @@ fn github_fast_path(
14131413
// the branch has moved.
14141414
if let Some(local_object) = local_object {
14151415
if is_short_hash_of(rev, local_object) {
1416+
debug!("github fast path already has {local_object}");
14161417
return Ok(FastPathRev::UpToDate);
14171418
}
14181419
}
@@ -1452,6 +1453,7 @@ fn github_fast_path(
14521453
handle.get(true)?;
14531454
handle.url(&url)?;
14541455
handle.useragent("cargo")?;
1456+
handle.follow_location(true)?; // follow redirects
14551457
handle.http_headers({
14561458
let mut headers = List::new();
14571459
headers.append("Accept: application/vnd.github.3.sha")?;
@@ -1472,14 +1474,17 @@ fn github_fast_path(
14721474

14731475
let response_code = handle.response_code()?;
14741476
if response_code == 304 {
1477+
debug!("github fast path up-to-date");
14751478
Ok(FastPathRev::UpToDate)
14761479
} else if response_code == 200 {
14771480
let oid_to_fetch = str::from_utf8(&response_body)?.parse::<Oid>()?;
1481+
debug!("github fast path fetch {oid_to_fetch}");
14781482
Ok(FastPathRev::NeedsFetch(oid_to_fetch))
14791483
} else {
14801484
// Usually response_code == 404 if the repository does not exist, and
14811485
// response_code == 422 if exists but GitHub is unable to resolve the
14821486
// requested rev.
1487+
debug!("github fast path bad response code {response_code}");
14831488
Ok(FastPathRev::Indeterminate)
14841489
}
14851490
}

0 commit comments

Comments
 (0)