Merge pull request #3352 from fjl/build-git-tag

internal/build: use 'git tag --points-at' to get the current tag
This commit is contained in:
Péter Szilágyi 2016-11-28 10:33:12 +02:00 committed by GitHub
commit 2b9cd71d67
1 changed files with 6 additions and 1 deletions

View File

@ -20,6 +20,7 @@ import (
"flag" "flag"
"fmt" "fmt"
"os" "os"
"strings"
) )
var ( var (
@ -89,11 +90,15 @@ func LocalEnv() Environment {
} }
} }
if env.Tag == "" { if env.Tag == "" {
env.Tag = RunGit("for-each-ref", "--points-at=HEAD", "--count=1", "--format=%(refname:short)", "refs/tags") env.Tag = firstLine(RunGit("tag", "-l", "--points-at", "HEAD"))
} }
return env return env
} }
func firstLine(s string) string {
return strings.Split(s, "\n")[0]
}
func applyEnvFlags(env Environment) Environment { func applyEnvFlags(env Environment) Environment {
if !flag.Parsed() { if !flag.Parsed() {
panic("you need to call flag.Parse before Env or LocalEnv") panic("you need to call flag.Parse before Env or LocalEnv")