Skip to content

Commit

Permalink
fix: Skip update --breaking in prerelase version
Browse files Browse the repository at this point in the history
  • Loading branch information
linyihai committed Jul 17, 2024
1 parent 8b1d18a commit 3973d78
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/cargo/util/toml_mut/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,18 @@ pub(crate) fn upgrade_requirement(
let comparators: CargoResult<Vec<_>> = raw_req
.comparators
.into_iter()
.map(|p| set_comparator(p, version))
.filter_map(|p| {
if p.pre.is_empty() {
Some(set_comparator(p, version))
} else {
None
}
})
.collect();
let comparators = comparators?;
let comparators: Vec<_> = comparators?;
if comparators.is_empty() {
return Ok(None);
}
let new_req = semver::VersionReq { comparators };
let mut new_req_text = new_req.to_string();
if new_req_text.starts_with('^') && !req.starts_with('^') {
Expand Down Expand Up @@ -217,5 +226,14 @@ mod test {
assert_req_bump("1.1.1", "=1.0.0", "=1.1.1");
assert_req_bump("2.0.0", "=1.0.0", "=2.0.0");
}

#[test]
fn ignore_prerelease() {
assert_req_bump("1.7.0", "2.0.0-beta.21", None);
assert_req_bump("1.7.0", ">=2.0.0-beta.21", None);
assert_req_bump("1.7.0", ">2.0.0-beta.21", None);
assert_req_bump("1.7.0", "<=2.0.0-beta.21", None);
assert_req_bump("1.7.0", "<2.0.0-beta.21", None);
}
}
}
34 changes: 34 additions & 0 deletions tests/testsuite/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2616,3 +2616,37 @@ fn update_breaking_mixed_pinning_renaming() {
"#]],
);
}

#[cargo_test]
fn update_breaking_pre_release() {
Package::new("bar", "2.0.0-beta.21").publish();

let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
edition = "2015"
authors = []
[dependencies]
bar = "2.0.0-beta.21"
"#,
)
.file("src/lib.rs", "")
.build();

p.cargo("generate-lockfile").run();

Package::new("bar", "1.7.0").publish();

p.cargo("update -Zunstable-options --breaking bar")
.masquerade_as_nightly_cargo(&["update-breaking"])
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
"#]])
.run();
}

0 comments on commit 3973d78

Please sign in to comment.