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 15, 2024
1 parent 0b801d1 commit e3aab3a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
18 changes: 12 additions & 6 deletions src/cargo/util/toml_mut/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ pub(crate) fn upgrade_requirement(
.into_iter()
.map(|p| set_comparator(p, version))
.collect();
let comparators = comparators?;
let comparators: Vec<_> = comparators?.into_iter().flatten().collect();
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 @@ -48,7 +51,7 @@ pub(crate) fn upgrade_requirement(
fn set_comparator(
mut pred: semver::Comparator,
version: &semver::Version,
) -> CargoResult<semver::Comparator> {
) -> CargoResult<Option<semver::Comparator>> {
match pred.op {
semver::Op::Wildcard => {
pred.major = version.major;
Expand All @@ -58,7 +61,7 @@ fn set_comparator(
if pred.patch.is_some() {
pred.patch = Some(version.patch);
}
Ok(pred)
Ok(Some(pred))
}
semver::Op::Exact => Ok(assign_partial_req(version, pred)),
semver::Op::Greater | semver::Op::GreaterEq | semver::Op::Less | semver::Op::LessEq => {
Expand All @@ -77,7 +80,10 @@ fn set_comparator(
fn assign_partial_req(
version: &semver::Version,
mut pred: semver::Comparator,
) -> semver::Comparator {
) -> Option<semver::Comparator> {
if !pred.pre.is_empty() {
return None;
}
pred.major = version.major;
if pred.minor.is_some() {
pred.minor = Some(version.minor);
Expand All @@ -86,7 +92,7 @@ fn assign_partial_req(
pred.patch = Some(version.patch);
}
pred.pre = version.pre.clone();
pred
Some(pred)
}

fn unsupported_version_req(req: impl Display) -> anyhow::Error {
Expand Down Expand Up @@ -220,7 +226,7 @@ mod test {

#[test]
fn caret_prerelease() {
assert_req_bump("1.7.0", "2.0.0-beta.21", "1.7.0");
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 e3aab3a

Please sign in to comment.