MCPcopy Create free account
hub / github.com/remotemobprogramming/mob / parseGitVersion

Function parseGitVersion

mob.go:53–81  ·  view source on GitHub ↗
(version string)

Source from the content-addressed store, hash-verified

51}
52
53func 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
83func (v GitVersion) Less(rhs GitVersion) bool {
84 return v.Major < rhs.Major ||

Callers 2

TestGitVersionParseFunction · 0.85
runFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestGitVersionParseFunction · 0.68