diff --git a/src/command/bump/mod.rs b/src/command/bump/mod.rs index 687632a3..9ef84a65 100644 --- a/src/command/bump/mod.rs +++ b/src/command/bump/mod.rs @@ -103,7 +103,7 @@ fn ensure_tag_is_greater_than_previous(current: &Tag, next: &Tag) -> Result<()> fn tag_or_fallback_to_zero(tag: Result) -> Result { match tag { Ok(ref tag) => Ok(tag.clone()), - Err(ref err) if err == &TagError::NoTag => Ok(Tag::default()), + Err(TagError::NoTag) => Ok(Tag::default()), Err(err) => Err(anyhow!(err)), } } diff --git a/src/conventional/commit.rs b/src/conventional/commit.rs index f3b53782..a7bf74a6 100644 --- a/src/conventional/commit.rs +++ b/src/conventional/commit.rs @@ -187,7 +187,7 @@ impl fmt::Display for Commit { impl PartialOrd for Commit { fn partial_cmp(&self, other: &Self) -> Option { - self.message.scope.partial_cmp(&other.message.scope) + Some(self.message.scope.cmp(&other.message.scope)) } } diff --git a/src/conventional/version.rs b/src/conventional/version.rs index fcafd654..f483435c 100644 --- a/src/conventional/version.rs +++ b/src/conventional/version.rs @@ -33,23 +33,23 @@ impl From for IncrementCommand { impl Ord for Increment { fn cmp(&self, other: &Self) -> Ordering { - self.partial_cmp(other).unwrap() + match (self, other) { + (increment, other) if increment == other => Ordering::Equal, + (Increment::Major, _) => Ordering::Greater, + (_, Increment::Major) => Ordering::Less, + (Increment::Minor, _) => Ordering::Greater, + (_, Increment::Minor) => Ordering::Less, + (Increment::Patch, Increment::Patch) => Ordering::Equal, + (Increment::NoBump, Increment::NoBump) => Ordering::Equal, + (Increment::Patch, Increment::NoBump) => Ordering::Greater, + (Increment::NoBump, Increment::Patch) => Ordering::Less, + } } } impl PartialOrd for Increment { fn partial_cmp(&self, other: &Self) -> Option { - match (self, other) { - (increment, other) if increment == other => Some(Ordering::Equal), - (Increment::Major, _) => Some(Ordering::Greater), - (_, Increment::Major) => Some(Ordering::Less), - (Increment::Minor, _) => Some(Ordering::Greater), - (_, Increment::Minor) => Some(Ordering::Less), - (Increment::Patch, Increment::Patch) => Some(Ordering::Equal), - (Increment::NoBump, Increment::NoBump) => Some(Ordering::Equal), - (Increment::Patch, Increment::NoBump) => Some(Ordering::Greater), - (Increment::NoBump, Increment::Patch) => Some(Ordering::Less), - } + Some(self.cmp(other)) } } diff --git a/src/git/tag.rs b/src/git/tag.rs index 0f33b12e..e2d74096 100644 --- a/src/git/tag.rs +++ b/src/git/tag.rs @@ -123,7 +123,7 @@ pub struct Tag { impl Ord for Tag { fn cmp(&self, other: &Self) -> Ordering { - self.partial_cmp(other).unwrap_or(Ordering::Less) + self.version.cmp(&other.version) } } @@ -137,15 +137,7 @@ impl PartialEq for Tag { impl PartialOrd for Tag { fn partial_cmp(&self, other: &Self) -> Option { - if self.package != other.package { - return None; - } - - if self.prefix != other.prefix { - return None; - } - - self.version.partial_cmp(&other.version) + Some(self.cmp(other)) } } diff --git a/tests/lib_tests/bump.rs b/tests/lib_tests/bump.rs index f01db863..cca5a419 100644 --- a/tests/lib_tests/bump.rs +++ b/tests/lib_tests/bump.rs @@ -9,8 +9,6 @@ use std::collections::HashMap; use std::path::Path; use std::path::PathBuf; -use crate::helpers::*; - #[sealed_test] fn bump_ok() -> Result<()> { // Arrange