From 91e4a183bdbd9fd6cf7647c921527dc951a585f1 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sat, 24 Aug 2019 15:32:11 +0200 Subject: repo: fix git version parsing with broken version --- repository/git.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'repository/git.go') diff --git a/repository/git.go b/repository/git.go index 9ec7905a..dfd7fed4 100644 --- a/repository/git.go +++ b/repository/git.go @@ -7,6 +7,7 @@ import ( "io" "os/exec" "path" + "regexp" "strconv" "strings" @@ -331,8 +332,16 @@ func (repo *GitRepo) gitVersionLT218() (bool, error) { return false, err } - versionString := strings.Fields(versionOut)[2] - version, err := semver.Make(versionString) + // extract the version and truncate potential bad parts + // ex: 2.23.0.rc1 instead of 2.23.0-rc1 + r := regexp.MustCompile(`(\d+\.){1,2}\d+`) + + extracted := r.FindString(versionOut) + if extracted == "" { + return false, fmt.Errorf("unreadable git version %s", versionOut) + } + + version, err := semver.Make(extracted) if err != nil { return false, err } -- cgit