From 1c15c722fe3b0518566591f9a9cae4ba2df732f8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 7 Jun 2018 22:33:03 +0300 Subject: [PATCH] Install pre-release versions by default for git deps closes #5627 --- src/cargo/ops/cargo_install.rs | 9 ++++++++- tests/testsuite/install.rs | 25 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/cargo/ops/cargo_install.rs b/src/cargo/ops/cargo_install.rs index 9516aac09..201a7203c 100644 --- a/src/cargo/ops/cargo_install.rs +++ b/src/cargo/ops/cargo_install.rs @@ -480,9 +480,16 @@ where None => None, }; let vers = vers.as_ref().map(|s| &**s); + let vers_spec = if vers.is_none() && source.source_id().is_registry() { + // Avoid pre-release versions from crate.io + // unless explicitly asked for + Some("*") + } else { + vers + }; let dep = Dependency::parse_no_deprecated( name, - Some(vers.unwrap_or("*")), + vers_spec, source.source_id(), )?; let deps = source.query_vec(&dep)?; diff --git a/tests/testsuite/install.rs b/tests/testsuite/install.rs index 6c24e17f0..0559c5704 100644 --- a/tests/testsuite/install.rs +++ b/tests/testsuite/install.rs @@ -138,6 +138,31 @@ warning: be sure to add `[..]` to your PATH to be able to run the installed bina assert_that(cargo_home(), has_installed_exe("foo")); } +#[test] +fn installs_beta_version_by_explicit_name_from_git() { + let p = git::repo(&paths::root().join("foo")) + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.3.0-beta.1" + authors = [] + "#, + ) + .file("src/main.rs", "fn main() {}") + .build(); + + assert_that( + cargo_process("install") + .arg("--git") + .arg(p.url().to_string()) + .arg("foo"), + execs().with_status(0), + ); + assert_that(cargo_home(), has_installed_exe("foo")); +} + #[test] fn missing() { pkg("foo", "0.0.1");