Skip to content

Commit

Permalink
Pre-release v1.11.0-pr.2
Browse files Browse the repository at this point in the history
Fix the following bug.
- Versions are not compared correctly in check-update subcommand.
  • Loading branch information
mithrandie committed May 19, 2019
2 parents b097629 + df7fdac commit 6b84b22
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 8 deletions.
22 changes: 14 additions & 8 deletions lib/action/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,23 @@ func (v *Version) IsLaterThan(v2 *Version) bool {
return false
}

if v.Major > v2.Major {
return true
if v.Major != v2.Major {
return v.Major > v2.Major
}
if v.Minor > v2.Minor {
return true
if v.Minor != v2.Minor {
return v.Minor > v2.Minor
}
if v.Patch > v2.Patch {
return true
if v.Patch != v2.Patch {
return v.Patch > v2.Patch
}
if 0 < v2.PreRelease && v.PreRelease > v2.PreRelease {
return true
if v.PreRelease != v2.PreRelease {
if v.PreRelease == 0 {
return true
}
if v2.PreRelease == 0 {
return false
}
return v.PreRelease > v2.PreRelease
}
return false
}
Expand Down
58 changes: 58 additions & 0 deletions lib/action/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ var versionIsLaterThanTests = []struct {
},
Result: false,
},
{
Version1: &Version{
Major: 1,
Minor: 2,
Patch: 1,
},
Version2: &Version{
Major: 1,
Minor: 3,
Patch: 0,
},
Result: false,
},
{
Version1: &Version{
Major: 2,
Expand Down Expand Up @@ -77,6 +90,51 @@ var versionIsLaterThanTests = []struct {
},
Result: true,
},
{
Version1: &Version{
Major: 1,
Minor: 2,
Patch: 3,
PreRelease: 0,
},
Version2: &Version{
Major: 1,
Minor: 2,
Patch: 3,
PreRelease: 4,
},
Result: true,
},
{
Version1: &Version{
Major: 1,
Minor: 2,
Patch: 3,
PreRelease: 4,
},
Version2: &Version{
Major: 1,
Minor: 2,
Patch: 3,
PreRelease: 0,
},
Result: false,
},
{
Version1: &Version{
Major: 1,
Minor: 2,
Patch: 3,
PreRelease: 4,
},
Version2: &Version{
Major: 1,
Minor: 2,
Patch: 3,
PreRelease: 5,
},
Result: false,
},
}

func TestVersion_IsLaterThan(t *testing.T) {
Expand Down

0 comments on commit 6b84b22

Please sign in to comment.