Add branch name to build version when appropriate
This commit is contained in:
parent
9b1bebc9b2
commit
8418fae82b
29
build.go
29
build.go
|
@ -492,12 +492,41 @@ func getVersion() string {
|
||||||
}
|
}
|
||||||
// ... then see if we have a Git tag.
|
// ... then see if we have a Git tag.
|
||||||
if ver, err := getGitVersion(); err == nil {
|
if ver, err := getGitVersion(); err == nil {
|
||||||
|
if strings.Contains(ver, "-") {
|
||||||
|
// The version already contains a hash and stuff. See if we can
|
||||||
|
// find a current branch name to tack onto it as well.
|
||||||
|
return ver + getBranchSuffix()
|
||||||
|
}
|
||||||
return ver
|
return ver
|
||||||
}
|
}
|
||||||
// This seems to be a dev build.
|
// This seems to be a dev build.
|
||||||
return "unknown-dev"
|
return "unknown-dev"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getBranchSuffix() string {
|
||||||
|
bs, err := runError("git", "branch", "-a", "--contains")
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
branches := bytes.Split(bs, []byte{'\n'})
|
||||||
|
if len(branches) == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// "git branch" returns the current branch with an asterisk and space in
|
||||||
|
// "front of it, otherwise just spaces. Remove all that stuff.
|
||||||
|
branch := bytes.TrimLeft(branches[0], " \t*")
|
||||||
|
|
||||||
|
// The branch name may be on the form "remotes/origin/foo" from which we
|
||||||
|
// just want "foo".
|
||||||
|
parts := bytes.Split(branch, []byte{'/'})
|
||||||
|
if len(parts) == 0 || len(parts[len(parts)-1]) == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return "-" + string(parts[len(parts)-1])
|
||||||
|
}
|
||||||
|
|
||||||
func buildStamp() int64 {
|
func buildStamp() int64 {
|
||||||
bs, err := runError("git", "show", "-s", "--format=%ct")
|
bs, err := runError("git", "show", "-s", "--format=%ct")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue