mirror of
https://github.com/octoleo/restic.git
synced 2024-11-25 22:27:35 +00:00
Merge pull request #281 from restic/version-with-git
build.go: use new combined version string
This commit is contained in:
commit
9aefc2b7a6
43
build.go
43
build.go
@ -200,22 +200,41 @@ func test(gopath string, args ...string) error {
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
// getVersion returns a version string, either from the file VERSION in the
|
||||
// current directory or from git.
|
||||
func getVersion() string {
|
||||
v, err := ioutil.ReadFile("VERSION")
|
||||
version := strings.TrimSpace(string(v))
|
||||
if err == nil {
|
||||
verbosePrintf("version from file 'VERSION' is %s\n", version)
|
||||
return version
|
||||
// getVersion returns the version string from the file VERSION in the current
|
||||
// directory.
|
||||
func getVersionFromFile() string {
|
||||
buf, err := ioutil.ReadFile("VERSION")
|
||||
if err != nil {
|
||||
verbosePrintf("error reading file VERSION: %v\n", err)
|
||||
return ""
|
||||
}
|
||||
|
||||
return gitVersion()
|
||||
return strings.TrimSpace(string(buf))
|
||||
}
|
||||
|
||||
// gitVersion returns a version string that identifies the currently checked
|
||||
// out git commit.
|
||||
func gitVersion() string {
|
||||
// getVersion returns a version string which is a combination of the contents
|
||||
// of the file VERSION in the current directory and the version from git (if
|
||||
// available).
|
||||
func getVersion() string {
|
||||
versionFile := getVersionFromFile()
|
||||
versionGit := getVersionFromGit()
|
||||
|
||||
verbosePrintf("version from file 'VERSION' is %q, version from git %q\n",
|
||||
versionFile, versionGit)
|
||||
|
||||
switch {
|
||||
case versionFile == "":
|
||||
return versionGit
|
||||
case versionGit == "":
|
||||
return versionFile
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s (%s)", versionFile, versionGit)
|
||||
}
|
||||
|
||||
// getVersionFromGit returns a version string that identifies the currently
|
||||
// checked out git commit.
|
||||
func getVersionFromGit() string {
|
||||
cmd := exec.Command("git", "describe",
|
||||
"--long", "--tags", "--dirty", "--always")
|
||||
out, err := cmd.Output()
|
||||
|
Loading…
Reference in New Issue
Block a user