Skip to content

Commit aaa3391

Browse files
committed
fix: handle git-describe suffixes in version comparison
parseVersion failed to parse versions like "v0.3.0-7-g09160b8" produced by git describe, causing the update check to always report up-to-date. Strip the suffix before parsing so the semver comparison works correctly.
1 parent a728249 commit aaa3391

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

src/internal/selfupdate/selfupdate.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ func isNewer(latest, current string) bool {
172172

173173
func parseVersion(v string) []int {
174174
v = strings.TrimPrefix(v, "v")
175+
// Strip git-describe suffix (e.g. "0.3.0-7-g09160b8" → "0.3.0")
176+
if idx := strings.Index(v, "-"); idx >= 0 {
177+
v = v[:idx]
178+
}
175179
parts := strings.Split(v, ".")
176180
if len(parts) != 3 {
177181
return nil

src/internal/selfupdate/selfupdate_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func TestIsNewer(t *testing.T) {
1717
{"v0.0.1", "v0.1.0", false},
1818
{"v1.0.0", "v1.0.0", false},
1919
{"v2.0.0", "v1.99.99", true},
20+
{"v0.3.1", "v0.3.0-7-g09160b8", true},
2021
}
2122
for _, tt := range tests {
2223
t.Run(tt.latest+"_vs_"+tt.current, func(t *testing.T) {
@@ -55,6 +56,8 @@ func TestParseVersion(t *testing.T) {
5556
{"v1.2.3", []int{1, 2, 3}},
5657
{"0.1.0", []int{0, 1, 0}},
5758
{"v0.0.0", []int{0, 0, 0}},
59+
{"v0.3.0-7-g09160b8", []int{0, 3, 0}},
60+
{"v1.2.3-rc1", []int{1, 2, 3}},
5861
}
5962
for _, tt := range tests {
6063
t.Run(tt.input, func(t *testing.T) {

0 commit comments

Comments
 (0)