Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #2773 with new precise encode #5205

Merged
merged 5 commits into from
Mar 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_generate_lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub fn update_lockfile(ws: &Workspace, opts: &UpdateOptions) -> CargoResult<()>
// seems like a pretty hokey reason to single out
// the registry as well.
let precise = if dep.source_id().is_registry() {
format!("{}={}", dep.name(), precise)
format!("{}={}->{}", dep.name(), dep.version(), precise)
} else {
precise.to_string()
};
Expand Down
15 changes: 11 additions & 4 deletions src/cargo/sources/registry/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,20 @@ impl<'cfg> RegistryIndex<'cfg> {
.map(|s| s.0.clone());

// Handle `cargo update --precise` here. If specified, our own source
// will have a precise version listed of the form `<pkg>=<req>` where
// `<pkg>` is the name of a crate on this source and `<req>` is the
// will have a precise version listed of the form
// `<pkg>=<p_req>o-><f_req>` where `<pkg>` is the name of a crate on
// this source, `<p_req>` is the version installed and `<f_req> is the
// version requested (argument to `--precise`).
let summaries = summaries.filter(|s| match source_id.precise() {
Some(p) if p.starts_with(&*dep.name()) && p[dep.name().len()..].starts_with('=') => {
let vers = &p[dep.name().len() + 1..];
s.version().to_string() == vers
let mut vers = p[dep.name().len() + 1..].splitn(2, "->");
if dep.version_req()
.matches(&Version::parse(vers.next().unwrap()).unwrap())
{
vers.next().unwrap() == s.version().to_string()
} else {
true
}
}
_ => true,
});
Expand Down
55 changes: 55 additions & 0 deletions tests/testsuite/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,58 @@ fn change_package_version() {

assert_that(p.cargo("build"), execs().with_status(0));
}

#[test]
fn update_precise() {
Package::new("log", "0.1.0").publish();
Package::new("serde", "0.1.0").publish();
Package::new("serde", "0.2.1").publish();

let p = project("foo")
.file(
"Cargo.toml",
r#"
[package]
name = "bar"
version = "0.0.1"
authors = []

[dependencies]
serde = "0.2"
foo = { path = "foo" }
"#,
)
.file("src/lib.rs", "")
.file(
"foo/Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
authors = []

[dependencies]
serde = "0.1"
"#,
)
.file("foo/src/lib.rs", "")
.build();

assert_that(p.cargo("build"), execs().with_status(0));

Package::new("serde", "0.2.0").publish();

assert_that(
p.cargo("update")
.arg("-p")
.arg("serde:0.2.1")
.arg("--precise")
.arg("0.2.0"),
execs().with_status(0).with_stderr(
"\
[UPDATING] registry `[..]`
[UPDATING] serde v0.2.1 -> v0.2.0
",
),
);
}