Skip to content

Commit

Permalink
Auto merge of #11177 - arlosi:sparse-lockfile, r=weihanglo
Browse files Browse the repository at this point in the history
Fix sparse registry lockfile urls containing 'registry+sparse+'

The `Cargo.lock` file for alternative sparse registries incorrectly lists the url as `registry+sparse+` rather than `sparse+`.

Fixes #10963
  • Loading branch information
bors committed Oct 7, 2022
2 parents 37f39f6 + 10d3b3d commit aff3bb8
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/cargo/core/source/source_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,16 @@ impl<'a> fmt::Display for SourceIdAsUrl<'a> {
kind: SourceKind::Registry,
ref url,
..
} => write!(f, "registry+{}", url),
} => {
// For sparse http registry the URL already contains the prefix.
if url.scheme().starts_with("sparse+") {
// e.g. sparse+http://example.com
write!(f, "{url}")
} else {
// e.g. registry+http://example.com
write!(f, "registry+{url}")
}
}
SourceIdInner {
kind: SourceKind::LocalRegistry,
ref url,
Expand Down
49 changes: 49 additions & 0 deletions tests/testsuite/alt_registry.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Tests for alternative registries.

use cargo::util::IntoUrl;
use cargo_test_support::compare::assert_match_exact;
use cargo_test_support::publish::validate_alt_upload;
use cargo_test_support::registry::{self, Package, RegistryBuilder};
use cargo_test_support::{basic_manifest, git, paths, project};
Expand Down Expand Up @@ -1309,3 +1310,51 @@ fn both_index_and_registry() {
.run();
}
}

#[cargo_test]
fn sparse_lockfile() {
let _registry = registry::RegistryBuilder::new()
.http_index()
.alternative()
.build();
Package::new("foo", "0.1.0").alternative(true).publish();

let p = project()
.file(
"Cargo.toml",
r#"
[project]
name = "a"
version = "0.5.0"
authors = []
[dependencies]
foo = { registry = 'alternative', version = '0.1.0'}
"#,
)
.file("src/lib.rs", "")
.build();

p.cargo("-Zsparse-registry generate-lockfile")
.masquerade_as_nightly_cargo(&["sparse-registry"])
.run();
assert_match_exact(
&p.read_lockfile(),
r#"# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "a"
version = "0.5.0"
dependencies = [
"foo",
]
[[package]]
name = "foo"
version = "0.1.0"
source = "sparse+http://[..]/"
checksum = "f6a200a9339fef960979d94d5c99cbbfd899b6f5a396a55d9775089119050203""#,
);
}

0 comments on commit aff3bb8

Please sign in to comment.