diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-10-12 10:38:18 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-10-12 10:44:10 +0300 |
commit | 7b259cf7e76ddf9e31ae15f66fee4c899e3f5453 (patch) | |
tree | 9ef43ae2d453059ab57a56705a5a3637c46d9514 | |
parent | 99c7de6455d846a5fb98622b23afe151abc50bac (diff) |
git: Fix parsing of dashed -rc versions
Typically, Git release candidates use a dashed "-rc0" suffix to indicate
the prerelease status. We currently fail to parse this correctly as we
expect the rc suffix to be separated by a dot instead, e.g. "2.29.0.rc0"
instead of the actual "2.29.0-rc0".
Fix the issue by correctly parsing the dashed form.
-rw-r--r-- | changelogs/unreleased/pks-git-version-dashed-rcs.yml | 5 | ||||
-rw-r--r-- | internal/git/proto.go | 7 | ||||
-rw-r--r-- | internal/git/proto_test.go | 4 |
3 files changed, 15 insertions, 1 deletions
diff --git a/changelogs/unreleased/pks-git-version-dashed-rcs.yml b/changelogs/unreleased/pks-git-version-dashed-rcs.yml new file mode 100644 index 000000000..315db593c --- /dev/null +++ b/changelogs/unreleased/pks-git-version-dashed-rcs.yml @@ -0,0 +1,5 @@ +--- +title: 'git: Fix parsing of dashed -rc versions' +merge_request: 2639 +author: +type: fixed diff --git a/internal/git/proto.go b/internal/git/proto.go index 69a414820..9edc5af46 100644 --- a/internal/git/proto.go +++ b/internal/git/proto.go @@ -140,11 +140,16 @@ func parseVersion(versionStr string) (version, error) { var ver version for i, v := range []*uint32{&ver.major, &ver.minor, &ver.patch} { - n64, err := strconv.ParseUint(versionSplit[i], 10, 32) + rcSplit := strings.SplitN(versionSplit[i], "-", 2) + n64, err := strconv.ParseUint(rcSplit[0], 10, 32) if err != nil { return version{}, err } + if len(rcSplit) == 2 && strings.HasPrefix(rcSplit[1], "rc") { + ver.rc = true + } + *v = uint32(n64) } diff --git a/internal/git/proto_test.go b/internal/git/proto_test.go index 3386c41d4..18e128666 100644 --- a/internal/git/proto_test.go +++ b/internal/git/proto_test.go @@ -88,6 +88,9 @@ func TestVersionComparator(t *testing.T) { {"1.1.1.rc0", "1.1.1", true}, {"1.1.1.rc0", "1.1.1.rc0", false}, {"1.1.1.rc0", "1.1.0", false}, + {"1.1.1-rc0", "1.1.1-rc0", false}, + {"1.1.1-rc0", "1.1.1", true}, + {"1.1.1", "1.1.1-rc0", false}, } { actual, err := git.VersionLessThan(tc.v1, tc.v2) require.NoError(t, err) @@ -106,6 +109,7 @@ func TestSupportsReferenceTransactionHook(t *testing.T) { {"2.28.0.rc2", true}, {"2.28.1", true}, {"2.28.0.468.g1be91c4e2f", true}, + {"2.29.0-rc1", true}, {"3.0.0", true}, } { actual, err := git.SupportsReferenceTransactionHook(tc.version) |