internal/build: add support for git tag in local Environment
I didn't add this initially because the command I tried was too slow. The 'git for-each-ref ...' invocation takes 40ms on my machine. That ought to be acceptable.
This commit is contained in:
parent
92959cd4ef
commit
e1e2df656a
@ -88,8 +88,9 @@ func LocalEnv() Environment {
|
|||||||
env.Branch = b
|
env.Branch = b
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Note that we don't get the current git tag. It would slow down
|
if env.Tag == "" {
|
||||||
// builds and isn't used by anything.
|
env.Tag = RunGit("for-each-ref", "--points-at=HEAD", "--count=1", "--format=%(refname:short)", "refs/tags")
|
||||||
|
}
|
||||||
return env
|
return env
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,6 +76,8 @@ func VERSION() string {
|
|||||||
return string(bytes.TrimSpace(version))
|
return string(bytes.TrimSpace(version))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var warnedAboutGit bool
|
||||||
|
|
||||||
// RunGit runs a git subcommand and returns its output.
|
// RunGit runs a git subcommand and returns its output.
|
||||||
// The command must complete successfully.
|
// The command must complete successfully.
|
||||||
func RunGit(args ...string) string {
|
func RunGit(args ...string) string {
|
||||||
@ -83,7 +85,10 @@ func RunGit(args ...string) string {
|
|||||||
var stdout, stderr bytes.Buffer
|
var stdout, stderr bytes.Buffer
|
||||||
cmd.Stdout, cmd.Stderr = &stdout, &stderr
|
cmd.Stdout, cmd.Stderr = &stdout, &stderr
|
||||||
if err := cmd.Run(); err == exec.ErrNotFound {
|
if err := cmd.Run(); err == exec.ErrNotFound {
|
||||||
log.Println("no git in PATH")
|
if !warnedAboutGit {
|
||||||
|
log.Println("Warning: can't find 'git' in PATH")
|
||||||
|
warnedAboutGit = true
|
||||||
|
}
|
||||||
return ""
|
return ""
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
log.Fatal(strings.Join(cmd.Args, " "), ": ", err, "\n", stderr.String())
|
log.Fatal(strings.Join(cmd.Args, " "), ": ", err, "\n", stderr.String())
|
||||||
|
Loading…
Reference in New Issue
Block a user