(version string)
| 51 | } |
| 52 | |
| 53 | func parseGitVersion(version string) GitVersion { |
| 54 | // The git version string can be customized, so we need a more complex regex, for example: git version 2.38.1.windows.1 |
| 55 | // "git" and "version" are optional, and the version number can be x, x.y or x.y.z |
| 56 | r := regexp.MustCompile(`(?:git)?(?: version )?(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?`) |
| 57 | matches := r.FindStringSubmatch(version) |
| 58 | var v GitVersion |
| 59 | var err error |
| 60 | if len(matches) > r.SubexpIndex("major") { |
| 61 | v.Major, err = strconv.Atoi(matches[r.SubexpIndex("major")]) |
| 62 | if err != nil { |
| 63 | v.Major = 0 |
| 64 | return v |
| 65 | } |
| 66 | } |
| 67 | if len(matches) > r.SubexpIndex("minor") { |
| 68 | v.Minor, err = strconv.Atoi(matches[r.SubexpIndex("minor")]) |
| 69 | if err != nil { |
| 70 | v.Minor = 0 |
| 71 | return v |
| 72 | } |
| 73 | } |
| 74 | if len(matches) > r.SubexpIndex("patch") { |
| 75 | v.Patch, err = strconv.Atoi(matches[r.SubexpIndex("patch")]) |
| 76 | if err != nil { |
| 77 | v.Patch = 0 |
| 78 | } |
| 79 | } |
| 80 | return v |
| 81 | } |
| 82 | |
| 83 | func (v GitVersion) Less(rhs GitVersion) bool { |
| 84 | return v.Major < rhs.Major || |
no outgoing calls