Skip to content

Commit 174ec74

Browse files
committed
Auto merge of #11268 - arlosi:fix-sparse-publish, r=ehuss
Fix publishing with a dependency on a sparse registry ### What does this PR try to resolve? On publishing, the `registry_index` field was being set to the registry URL without the `sparse+` prefix. During the verification build, Cargo would attempt to fetch the registry as a `git` registry. Caused by #11209. Fixes #11263. ### How should we test and review this PR? Added a test that fails without the change.
2 parents b1b25a0 + 49fb8f3 commit 174ec74

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

src/cargo/util/toml/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1521,8 +1521,7 @@ impl TomlManifest {
15211521
d.rev.take();
15221522
// registry specifications are elaborated to the index URL
15231523
if let Some(registry) = d.registry.take() {
1524-
let src = SourceId::alt_registry(config, &registry)?;
1525-
d.registry_index = Some(src.url().to_string());
1524+
d.registry_index = Some(config.get_registry_index(&registry)?.to_string());
15261525
}
15271526
Ok(TomlDependency::Detailed(d))
15281527
}

tests/testsuite/alt_registry.rs

+48
Original file line numberDiff line numberDiff line change
@@ -1337,3 +1337,51 @@ source = "sparse+http://[..]/"
13371337
checksum = "f6a200a9339fef960979d94d5c99cbbfd899b6f5a396a55d9775089119050203""#,
13381338
);
13391339
}
1340+
1341+
#[cargo_test]
1342+
fn publish_with_transitive_dep() {
1343+
let _alt1 = RegistryBuilder::new()
1344+
.http_api()
1345+
.http_index()
1346+
.alternative_named("Alt-1")
1347+
.build();
1348+
let _alt2 = RegistryBuilder::new()
1349+
.http_api()
1350+
.http_index()
1351+
.alternative_named("Alt-2")
1352+
.build();
1353+
1354+
let p1 = project()
1355+
.file(
1356+
"Cargo.toml",
1357+
r#"
1358+
[package]
1359+
name = "a"
1360+
version = "0.5.0"
1361+
"#,
1362+
)
1363+
.file("src/lib.rs", "")
1364+
.build();
1365+
p1.cargo("publish -Zsparse-registry --registry Alt-1")
1366+
.masquerade_as_nightly_cargo(&["sparse-registry"])
1367+
.run();
1368+
1369+
let p2 = project()
1370+
.file(
1371+
"Cargo.toml",
1372+
r#"
1373+
[package]
1374+
name = "b"
1375+
version = "0.6.0"
1376+
publish = ["Alt-2"]
1377+
1378+
[dependencies]
1379+
a = { version = "0.5.0", registry = "Alt-1" }
1380+
"#,
1381+
)
1382+
.file("src/lib.rs", "")
1383+
.build();
1384+
p2.cargo("publish -Zsparse-registry")
1385+
.masquerade_as_nightly_cargo(&["sparse-registry"])
1386+
.run();
1387+
}

0 commit comments

Comments
 (0)