aboutsummaryrefslogtreecommitdiffstats
path: root/repository
diff options
context:
space:
mode:
authorAmine <hilalyamine@gmail.com>2019-08-24 15:42:58 +0200
committerGitHub <noreply@github.com>2019-08-24 15:42:58 +0200
commit69ed22443efe9f38a67024f1f678b64a8363e33b (patch)
treec35e74d4a02f6109d2b24b9d2d79889ac9387835 /repository
parent8870fa9d9202a311cf67c2b29a06c4ccfc664399 (diff)
parent91e4a183bdbd9fd6cf7647c921527dc951a585f1 (diff)
downloadgit-bug-69ed22443efe9f38a67024f1f678b64a8363e33b.tar.gz
Merge pull request #202 from MichaelMure/fix-git-version
repo: fix git version parsing with broken version
Diffstat (limited to 'repository')
-rw-r--r--repository/git.go13
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
}