Skip to content

Commit

Permalink
Auto merge of #5205 - gibix:i2773, r=alexcrichton
Browse files Browse the repository at this point in the history
fix #2773 with new precise encode

Changed the precise encode from <pkg>=<precise> to <pkg>=<present_version>-><future_version> in order to check the correct requirements.

cc @lu-zero
  • Loading branch information
bors committed Mar 27, 2018
2 parents 715fc78 + 1a26e86 commit d079a10
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 5 deletions.
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 @@ -182,13 +182,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
",
),
);
}

0 comments on commit d079a10

Please sign in to comment.