diff options
author | Michael Muré <batolettre@gmail.com> | 2019-08-24 15:32:11 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2019-08-24 15:32:11 +0200 |
commit | 91e4a183bdbd9fd6cf7647c921527dc951a585f1 (patch) | |
tree | c35e74d4a02f6109d2b24b9d2d79889ac9387835 /repository | |
parent | 8870fa9d9202a311cf67c2b29a06c4ccfc664399 (diff) | |
download | git-bug-91e4a183bdbd9fd6cf7647c921527dc951a585f1.tar.gz |
repo: fix git version parsing with broken version
Diffstat (limited to 'repository')
-rw-r--r-- | repository/git.go | 13 |
1 files changed, 11 insertions, 2 deletions
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 } |