// GetVersion returns the current HEAD git commit if .git exists
182485
func GetVersion() string {
	if currentGitHead == "" {
		b, err := ioutil.ReadFile(".git/HEAD")

		if err != nil {
			currentGitHead = "unknown"
			return currentGitHead
		}

		p := refRE.FindStringSubmatch(string(b))

		if len(p) < 2 {
			currentGitHead = string(b)
			return currentGitHead
		}

		b, err = ioutil.ReadFile(".git/" + p[1])
		if err != nil {
			currentGitHead = p[1]
			return currentGitHead
		}

		currentGitHead = string(b)
	}
	return currentGitHead
}
1189446
func getVersionInfo(pkg string) (*version.Info, error) {
	git := newGit(pkg)
	commitID, err := git.commitID()
	if err != nil {
		return nil, fmt.Errorf("failed to obtain git commit ID: %v\n", err)
	}
	treeState, err := git.treeState()
	if err != nil {
		return nil, fmt.Errorf("failed to determine git tree state: %v\n", err)
	}
	tag, err := git.tag(commitID)
	if err != nil {
		tag = ""
	}
	if tag != "" {
		tag = semverify(tag)
		if treeState == dirty {
			tag = tag + "-" + string(treeState)
		}
	}
	return &version.Info{
		Version:      tag,
		GitCommit:    commitID,
		GitTreeState: string(treeState),
	}, nil
}
774122
func getVersion(job *api.Job) uint64 {
	if job.Version != nil {
		return *job.Version
	}

	return 0
}
455765
func GetRunningVersion() (*Version, error) {
	return getVersionFromName(
		fmt.Sprintf("%s.%s-%s", runtime.Version(), runtime.GOOS, runtime.GOARCH))
}
1106592
func (g *Git) Version(ctx context.Context) semver.Version {
	v := semver.Version{}

	cmd := exec.CommandContext(ctx, "git", "version")
	cmdout, err := cmd.Output()
	if err != nil {
		out.Debug(ctx, "Failed to run 'git version': %s", err)
		return v
	}

	svStr := strings.TrimPrefix(string(cmdout), "git version ")
	if p := strings.Fields(svStr); len(p) > 0 {
		svStr = p[0]
	}

	sv, err := semver.ParseTolerant(svStr)
	if err != nil {
		out.Debug(ctx, "Failed to parse '%s' as semver: %s", svStr, err)
		return v
	}
	return sv
}
180759
func ArchiveVersion(gitCommit string) string {
	vsn := Version
	if VersionMeta != "stable" {
		vsn += "-" + VersionMeta
	}
	if len(gitCommit) >= 8 {
		vsn += "-" + gitCommit[:8]
	}
	return vsn
}
1190398
func (tree *MutableTree) GetVersioned(key []byte, version int64) (
	index int64, value []byte,
) {
	if tree.versions[version] {
		t, err := tree.GetImmutable(version)
		if err != nil {
			return -1, nil
		}
		return t.Get(key)
	}
	return -1, nil
}
566041
func GetVersions(property *Property) (*Versions, error) {
	versions := NewVersions()
	if err := versions.GetVersions(property); err != nil {
		return nil, err
	}

	return versions, nil
}
446014
func getVersion(lastSeenBinaryVersion *string) error {
	// Create the get request for the etcd version endpoint.
	req, err := http.NewRequest("GET", etcdVersionScrapeURI, nil)
	if err != nil {
		return fmt.Errorf("failed to create GET request for etcd version: %v", err)
	}

	// Send the get request and receive a response.
	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		return fmt.Errorf("failed to receive GET response for etcd version: %v", err)
	}
	defer resp.Body.Close()

	// Obtain EtcdVersion from the JSON response.
	var version EtcdVersion
	if err := json.NewDecoder(resp.Body).Decode(&version); err != nil {
		return fmt.Errorf("failed to decode etcd version JSON: %v", err)
	}

	// Return without updating the version if it stayed the same since last time.
	if *lastSeenBinaryVersion == version.BinaryVersion {
		return nil
	}

	// Delete the metric for the previous version.
	if *lastSeenBinaryVersion != "" {
		deleted := etcdVersion.Delete(prometheus.Labels{"binary_version": *lastSeenBinaryVersion})
		if !deleted {
			return errors.New("failed to delete previous version's metric")
		}
	}

	// Record the new version in a metric.
	etcdVersion.With(prometheus.Labels{
		"binary_version": version.BinaryVersion,
	}).Set(0)
	*lastSeenBinaryVersion = version.BinaryVersion
	return nil
}
1307825
func (s *ConfigService) GetVersion() (string, *Response, error) {
	u := "config/server/version"
	return getStringResponseWithoutOptions(s.client, u)
}
311241
func (s *RPCServer) GetVersion(args api.GetVersionIn, out *api.GetVersionOut) error {
	out.DelveVersion = version.DelveVersion.String()
	out.APIVersion = s.s.config.APIVersion
	return nil
}
180985
func Version(buildVer, buildDate, commitHash string) Option {
	return func(o *Options) {
		BuildVersion = buildVer
		BuildDate = buildDate
		CommitHash = commitHash
	}
}
1119028
func CheckVersion(version int32) {
	if version < PACKED_VERSION_START {
		panic(fmt.Sprintf("Version is too old, should be at least %v (got %v)", PACKED_VERSION_START, version))
	} else if version > VERSION_CURRENT {
		panic(fmt.Sprintf("Version is too new, should be at most %v (got %v)", VERSION_CURRENT, version))
	}
}
694635
func (db *SQLStorage) GetVersion(gun data.GUN, tufRole data.RoleName, version int) (*time.Time, []byte, error) {
	var row TUFFile
	q := db.Select("created_at, data").Where(
		&TUFFile{
			Gun:     gun.String(),
			Role:    tufRole.String(),
			Version: version,
		},
	).First(&row)
	if err := isReadErr(q, row); err != nil {
		return nil, nil, err
	}
	return &(row.CreatedAt), row.Data, nil
}
1266138
func (cs *ConfigurationService) GetVersion(ctx context.Context) (v *Version, resp *APIResponse, err error) {
	v = &Version{}
	_, resp, err = cs.client.getAction(ctx, &APIClientRequest{
		Path:         "version",
		ResponseBody: v,
		APIVersion:   apiV1,
	})
	return
}
1234800
func GetVersionFromSource(projectRootDir string, packageFilePath string) (ver version.Version, err error) {
	jsonBody, err := ioutil.ReadFile(packageFilePath)
	if err != nil {
		return
	}

	pkgver := struct {
		Version string `json:"version"`
	}{}

	if err = jsonex.Unmarshal(jsonBody, &pkgver); err != nil {
		return
	}

	ver.Version = pkgver.Version

	ver.GoVersion = runtime.Version()

	commitTime, err := getGitCommitTime(projectRootDir)
	if err != nil {
		return
	}
	ver.BuildTime = commitTime

	hash, err := getGitHash(projectRootDir)
	if err != nil {
		return
	}
	ver.GitCommit = hash

	return
}
836280
func (v VersionsFile) ResolveVersion(pkg, ver string) (common.Pin, error) {
	if common.ValidateInstanceID(ver, common.AnyHash) == nil {
		return common.Pin{PackageName: pkg, InstanceID: ver}, nil
	}
	if iid, ok := v[unresolvedVer{pkg, ver}]; ok {
		return common.Pin{PackageName: pkg, InstanceID: iid}, nil
	}
	return common.Pin{}, errors.Reason("not in the versions file").Err()
}