mirror of
https://github.com/octoleo/restic.git
synced 2024-11-29 16:23:59 +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
41
build.go
41
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.
|
||||
// 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 strings.TrimSpace(string(buf))
|
||||
}
|
||||
|
||||
// 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 {
|
||||
v, err := ioutil.ReadFile("VERSION")
|
||||
version := strings.TrimSpace(string(v))
|
||||
if err == nil {
|
||||
verbosePrintf("version from file 'VERSION' is %s\n", version)
|
||||
return version
|
||||
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 gitVersion()
|
||||
return fmt.Sprintf("%s (%s)", versionFile, versionGit)
|
||||
}
|
||||
|
||||
// gitVersion returns a version string that identifies the currently checked
|
||||
// out git commit.
|
||||
func gitVersion() string {
|
||||
// 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