Skip to content

Commit 282ad55

Browse files
Merge branch 'main' into update-linter-ci
2 parents 7fea7c4 + dcf7f88 commit 282ad55

File tree

3 files changed

+49
-9
lines changed

3 files changed

+49
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ This changelog was created using the `clu` binary
1010

1111
- (ci) [#60](https://github.com/MalteHerrmann/changelog-utils/pull/60) Bump changelog linter to v0.2.0.
1212

13+
### Bug Fixes
14+
15+
- (lint) [#61](https://github.com/MalteHerrmann/changelog-utils/pull/61) Fix version comparison.
16+
1317
## [v1.2.0](https://github.com/MalteHerrmann/changelog-utils/releases/tag/v1.2.0) - 2024-08-03
1418

1519
### Features

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ The available subcommands can be listed when running `clu help`:
3030
Usage: clu <COMMAND>
3131

3232
Commands:
33-
add Adds a new entry to the unreleased section of the changelog
34-
fix Applies all possible auto-fixes to the changelog
35-
lint Checks if the changelog contents adhere to the defined rules
36-
init Initializes the changelog configuration in the current directory
37-
config Adjust the changelog configuration like allowed categories, change types or other
38-
release Turns the Unreleased section into a new release with the given version
39-
help Print this message or the help of the given subcommand(s)
33+
add Adds a new entry to the unreleased section of the changelog
34+
create-pr Creates a PR in the configured target repository and adds the corresponding changelog entry
35+
fix Applies all possible auto-fixes to the changelog
36+
lint Checks if the changelog contents adhere to the defined rules
37+
init Initializes the changelog configuration in the current directory
38+
config Adjust the changelog configuration like allowed categories, change types or other
39+
release Turns the Unreleased section into a new release with the given version
40+
help Print this message or the help of the given subcommand(s)
4041

4142
Options:
4243
-h, --help Print help

src/version.rs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,32 @@ impl Version {
1616
return true;
1717
}
1818

19-
if self.minor > other.major {
19+
if self.major < other.major {
20+
return false;
21+
}
22+
23+
if self.minor > other.minor {
2024
return true;
2125
}
2226

23-
if self.patch > other.major {
27+
if self.minor < other.minor {
28+
return false;
29+
}
30+
31+
if self.patch > other.patch {
2432
return true;
2533
}
2634

35+
if self.patch < other.patch {
36+
return false;
37+
}
38+
2739
match self.rc_version {
2840
Some(v) => match other.rc_version {
2941
Some(v_other) => v > v_other,
3042
None => false,
3143
},
44+
// NOTE: if self is not an rc, but other is -> self is greater
3245
None => other.rc_version.is_some(),
3346
}
3447
}
@@ -69,6 +82,28 @@ pub fn parse(version: &str) -> Result<Version, VersionError> {
6982
mod version_tests {
7083
use super::*;
7184

85+
#[test]
86+
fn test_greater() {
87+
let a = parse("v1.1.1-rc1").expect("failed to parse version");
88+
89+
assert!(a.gt(&parse("v0.2.0").unwrap()));
90+
assert!(a.gt(&parse("v0.0.2").unwrap()));
91+
assert!(a.gt(&parse("v0.0.2-rc2").unwrap()));
92+
assert!(a.gt(&parse("v1.0.1-rc1").unwrap()));
93+
assert!(a.gt(&parse("v1.0.2-rc2").unwrap()));
94+
assert!(a.gt(&parse("v1.0.1-rc2").unwrap()));
95+
assert!(a.gt(&parse("v1.1.0-rc1").unwrap()));
96+
assert!(a.gt(&parse("v1.1.1-rc0").unwrap()));
97+
98+
assert!(!a.gt(&parse("v1.1.1").unwrap()));
99+
assert!(!a.gt(&parse("v1.1.1-rc2").unwrap()));
100+
assert!(!a.gt(&parse("v1.1.2-rc1").unwrap()));
101+
assert!(!a.gt(&parse("v1.2.0").unwrap()));
102+
assert!(!a.gt(&parse("v1.2.0-rc1").unwrap()));
103+
assert!(!a.gt(&parse("v2.0.0").unwrap()));
104+
assert!(!a.gt(&parse("v2.0.0-rc1").unwrap()));
105+
}
106+
72107
#[test]
73108
fn test_is_valid_version_pass() {
74109
let version = parse("v10.0.2").expect("failed to parse version");

0 commit comments

Comments
 (0)