Skip to content

Commit 90b5df8

Browse files
committed
Auto merge of #5616 - matklad:install-betas-from-git, r=alexcrichton
Install pre-release versions by default for git deps Recently we've fixed a bug where `cargo install foo` would install `foo 2.0-beta.1` instead of `foo 1.0`, but this behavior is wrong for git and path deps.
2 parents ce455cd + 1c15c72 commit 90b5df8

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/cargo/ops/cargo_install.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,16 @@ where
480480
None => None,
481481
};
482482
let vers = vers.as_ref().map(|s| &**s);
483+
let vers_spec = if vers.is_none() && source.source_id().is_registry() {
484+
// Avoid pre-release versions from crate.io
485+
// unless explicitly asked for
486+
Some("*")
487+
} else {
488+
vers
489+
};
483490
let dep = Dependency::parse_no_deprecated(
484491
name,
485-
Some(vers.unwrap_or("*")),
492+
vers_spec,
486493
source.source_id(),
487494
)?;
488495
let deps = source.query_vec(&dep)?;

tests/testsuite/install.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,31 @@ warning: be sure to add `[..]` to your PATH to be able to run the installed bina
138138
assert_that(cargo_home(), has_installed_exe("foo"));
139139
}
140140

141+
#[test]
142+
fn installs_beta_version_by_explicit_name_from_git() {
143+
let p = git::repo(&paths::root().join("foo"))
144+
.file(
145+
"Cargo.toml",
146+
r#"
147+
[package]
148+
name = "foo"
149+
version = "0.3.0-beta.1"
150+
authors = []
151+
"#,
152+
)
153+
.file("src/main.rs", "fn main() {}")
154+
.build();
155+
156+
assert_that(
157+
cargo_process("install")
158+
.arg("--git")
159+
.arg(p.url().to_string())
160+
.arg("foo"),
161+
execs().with_status(0),
162+
);
163+
assert_that(cargo_home(), has_installed_exe("foo"));
164+
}
165+
141166
#[test]
142167
fn missing() {
143168
pkg("foo", "0.0.1");

0 commit comments

Comments
 (0)