Skip to content

Commit

Permalink
Auto merge of #11268 - arlosi:fix-sparse-publish, r=ehuss
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Oct 22, 2022
2 parents b1b25a0 + 49fb8f3 commit 174ec74
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1521,8 +1521,7 @@ impl TomlManifest {
d.rev.take();
// registry specifications are elaborated to the index URL
if let Some(registry) = d.registry.take() {
let src = SourceId::alt_registry(config, &registry)?;
d.registry_index = Some(src.url().to_string());
d.registry_index = Some(config.get_registry_index(&registry)?.to_string());
}
Ok(TomlDependency::Detailed(d))
}
Expand Down
48 changes: 48 additions & 0 deletions tests/testsuite/alt_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1337,3 +1337,51 @@ source = "sparse+http://[..]/"
checksum = "f6a200a9339fef960979d94d5c99cbbfd899b6f5a396a55d9775089119050203""#,
);
}

#[cargo_test]
fn publish_with_transitive_dep() {
let _alt1 = RegistryBuilder::new()
.http_api()
.http_index()
.alternative_named("Alt-1")
.build();
let _alt2 = RegistryBuilder::new()
.http_api()
.http_index()
.alternative_named("Alt-2")
.build();

let p1 = project()
.file(
"Cargo.toml",
r#"
[package]
name = "a"
version = "0.5.0"
"#,
)
.file("src/lib.rs", "")
.build();
p1.cargo("publish -Zsparse-registry --registry Alt-1")
.masquerade_as_nightly_cargo(&["sparse-registry"])
.run();

let p2 = project()
.file(
"Cargo.toml",
r#"
[package]
name = "b"
version = "0.6.0"
publish = ["Alt-2"]
[dependencies]
a = { version = "0.5.0", registry = "Alt-1" }
"#,
)
.file("src/lib.rs", "")
.build();
p2.cargo("publish -Zsparse-registry")
.masquerade_as_nightly_cargo(&["sparse-registry"])
.run();
}

0 comments on commit 174ec74

Please sign in to comment.