-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion.go
More file actions
31 lines (26 loc) · 913 Bytes
/
version.go
File metadata and controls
31 lines (26 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package gittools
import (
"regexp"
)
// declare the regular expression for matching version strings
var _VERSION *regexp.Regexp
// Version returns the version string for the installed git executable,
// or an error if this cannot be determined.
func Version() (string, error) {
// attempt to extract the version of the current git executable
// - we don't need to be in a particular directory for this
// so default to the current directory
_bytes, _err := Run("--version")
if _err != nil {
return "", _err
}
// attempt to parse the version string
// - we're looking for a dotted sequence of numbers
return _VERSION.FindString(string(_bytes)), nil
} // Version()
func init() {
// compile the regular expression pattern
// - we're looking for a.c.b numbers
// - this may need to be expanded to include modifiers (e.g. "-dev")
_VERSION = regexp.MustCompile("\\d+(\\.\\d+)*")
} // init()