mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-03 07:12:27 +00:00
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.
|
||||
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
|
||||
}
|
||||
// This seems to be a dev build.
|
||||
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 {
|
||||
bs, err := runError("git", "show", "-s", "--format=%ct")
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user