Skip to content

Commit 6867277

Browse files
committed
Auto merge of #10831 - arlosi:sparse-publish-fix, r=Eh2406
Fix publishing to crates.io with -Z sparse-registry Attempting to publish a crate to crates.io with `-Z sparse-registry` failed with the following error: ``` error: failed to publish to registry at https://crates.io Caused by: the remote server responded with an error: Dependency `serde` is hosted on another registry. Cross-registry dependencies are not permitted on crates.io. ``` The check in `registry.rs` `dep_registry_id != registry_id` caused the `publish` operation include the crates.io index url in the HTTP request because the id was replaced. The crates.io API seems to require that the `registry` field is not present. This change fixes the issue by making the `registry` function return the non-replaced crates.io `source_id` only for this case. Other replacement indices of crates.io continue to include the registry URL when publishing. Tested manually by publishing `arlosi-cargo-test` to crates.io with `-Z sparse-registry` Fixes #10828 r? `@Eh2406`
2 parents bc28260 + 132afd3 commit 6867277

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/cargo/ops/registry.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,6 @@ fn verify_dependencies(
196196
if super::check_dep_has_version(dep, true)? {
197197
continue;
198198
}
199-
// Allow publishing to crates.io with index.crates.io as a source replacement.
200-
if registry_src.is_default_registry() && dep.source_id().is_default_registry() {
201-
continue;
202-
}
203199
// TomlManifest::prepare_for_publish will rewrite the dependency
204200
// to be just the `version` field.
205201
if dep.source_id() != registry_src {
@@ -535,6 +531,13 @@ fn registry(
535531
None
536532
};
537533
let handle = http_handle(config)?;
534+
// Workaround for the sparse+https://index.crates.io replacement index. Use the non-replaced
535+
// source_id so that the original (github) url is used when publishing a crate.
536+
let sid = if sid.is_default_registry() {
537+
SourceId::crates_io(config)?
538+
} else {
539+
sid
540+
};
538541
Ok((Registry::new_handle(api_host, token, handle), reg_cfg, sid))
539542
}
540543

0 commit comments

Comments
 (0)