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 7880fc8 commit 7bbb671
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
21 changes: 17 additions & 4 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 @@ -219,8 +228,12 @@ mod test {
}

#[test]
fn caret_prerelease() {
assert_req_bump("1.7.0", "2.0.0-beta.21", "1.7.0");
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);
}
}
}
3 changes: 0 additions & 3 deletions tests/testsuite/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2646,9 +2646,6 @@ fn update_breaking_pre_release() {
.masquerade_as_nightly_cargo(&["update-breaking"])
.with_stderr_data(str![[r#"
[UPDATING] `dummy-registry` index
[UPGRADING] bar ^2.0.0-beta.21 -> ^1.7.0
[LOCKING] 1 package to latest compatible version
[DOWNGRADING] bar v2.0.0-beta.21 -> v1.7.0
"#]])
.run();
Expand Down

0 comments on commit 7bbb671

Please sign in to comment.