Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow compatible upgrade from rc to minor versions #1498

Merged
merged 2 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/portable/instance/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ fn upgrade_local_cmd(cmd: &Command, name: &str) -> anyhow::Result<()> {
// we rely on presence of the version specifying options instead to
// define how we want upgrade to be performed. This is mostly useful
// for tests.
if pkg_ver.is_compatible(&inst_ver) && !(cmd.force && ver_option) && !cmd.force_dump_restore {
if inst_ver.is_compatible(&pkg_ver) && !(cmd.force && ver_option) && !cmd.force_dump_restore {
upgrade_compatible(inst, pkg)
} else {
upgrade_incompatible(inst, pkg, cmd.non_interactive)
Expand Down
2 changes: 1 addition & 1 deletion src/portable/project/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ fn upgrade_local(
// since some selector like `--to-latest` was specified we assume
// user want to treat this upgrade as incompatible and do the
// upgrade. This is mostly for testing.
if pkg_ver.is_compatible(&inst_ver) && !cmd.force {
if inst_ver.is_compatible(&pkg_ver) && !cmd.force {
upgrade::upgrade_compatible(inst, pkg)?;
} else {
migrations::upgrade_check::to_version(&pkg, project)?;
Expand Down
43 changes: 40 additions & 3 deletions src/portable/ver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,20 @@ impl Filter {
impl Specific {
pub fn is_compatible(&self, other: &Specific) -> bool {
use MinorVersion::*;

if self.major != other.major {
return false;
}

// when major versions match
match (&self.minor, &other.minor) {
(Minor(_), Minor(_)) if self.major == other.major => true,
// all dev/alpha/rc are incompatible as well as different major
// but fully matching versions are always compatible
// rc can be upgraded to any rc or minor
(Rc(_), Rc(_) | Minor(_)) => true,

// minor can be upgraded to any minor
(Minor(_), Minor(_)) => true,

// all other cases: upgrade only in exact match
_ => self == other,
}
}
Expand Down Expand Up @@ -441,3 +451,30 @@ fn filter() {
}
);
}

#[test]
fn is_compatible() {
assert!(Specific::from_str("6.0-rc.3")
.unwrap()
.is_compatible(&Specific::from_str("6.0").unwrap()));

assert!(Specific::from_str("6.0-rc.3")
.unwrap()
.is_compatible(&Specific::from_str("6.0-rc.2").unwrap()));

assert!(Specific::from_str("6.0-rc.2")
.unwrap()
.is_compatible(&Specific::from_str("6.0-rc.3").unwrap()));

assert!(!Specific::from_str("5.0-rc.2")
.unwrap()
.is_compatible(&Specific::from_str("6.0-rc.3").unwrap()));

assert!(Specific::from_str("6.0")
.unwrap()
.is_compatible(&Specific::from_str("6.1").unwrap()));

assert!(Specific::from_str("6.2")
.unwrap()
.is_compatible(&Specific::from_str("6.1").unwrap()));
}
Loading