MCPcopy
hub / github.com/syncthing/syncthing / getGitVersion

Function getGitVersion

build.go:935–969  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

933}
934
935func getGitVersion() (string, error) {
936 // The current version as Git sees it
937 bs, err := runError("git", "describe", "--always", "--dirty", "--abbrev=8")
938 if err != nil {
939 return "", err
940 }
941 vcur := string(bs)
942
943 // The closest current tag name
944 bs, err = runError("git", "describe", "--always", "--abbrev=0")
945 if err != nil {
946 return "", err
947 }
948 v0 := string(bs)
949
950 // To be more semantic-versionish and ensure proper ordering in our
951 // upgrade process, we make sure there's only one hyphen in the version.
952
953 versionRe := regexp.MustCompile(`-([0-9]{1,3}-g[0-9a-f]{5,10}(-dirty)?)`)
954 if m := versionRe.FindStringSubmatch(vcur); len(m) > 0 {
955 suffix := strings.ReplaceAll(m[1], "-", ".")
956
957 if strings.Contains(v0, "-") {
958 // We're based of a tag with a prerelease string. We can just
959 // add our dev stuff directly.
960 return fmt.Sprintf("%s.dev.%s", v0, suffix), nil
961 }
962
963 // We're based on a release version. We need to bump the patch
964 // version and then add a -dev prerelease string.
965 next := nextPatchVersion(v0)
966 return fmt.Sprintf("%s-dev.%s", next, suffix), nil
967 }
968 return vcur, nil
969}
970
971func getVersion() string {
972 // First try for a RELEASE file or $VERSION env var,

Callers 1

getVersionFunction · 0.85

Calls 3

runErrorFunction · 0.85
nextPatchVersionFunction · 0.85
ContainsMethod · 0.80

Tested by

no test coverage detected