Skip to content

Commit e1e2df6

Browse files
committed
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.
1 parent 92959cd commit e1e2df6

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

‎internal/build/env.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ func LocalEnv() Environment {
8888
env.Branch = b
8989
}
9090
}
91-
// Note that we don't get the current git tag. It would slow down
92-
// builds and isn't used by anything.
91+
if env.Tag == "" {
92+
env.Tag = RunGit("for-each-ref", "--points-at=HEAD", "--count=1", "--format=%(refname:short)", "refs/tags")
93+
}
9394
return env
9495
}
9596

‎internal/build/util.go‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,19 @@ func VERSION() string {
7676
return string(bytes.TrimSpace(version))
7777
}
7878

79+
var warnedAboutGit bool
80+
7981
// RunGit runs a git subcommand and returns its output.
8082
// The command must complete successfully.
8183
func RunGit(args ...string) string {
8284
cmd := exec.Command("git", args...)
8385
var stdout, stderr bytes.Buffer
8486
cmd.Stdout, cmd.Stderr = &stdout, &stderr
8587
if err := cmd.Run(); err == exec.ErrNotFound {
86-
log.Println("no git in PATH")
88+
if !warnedAboutGit {
89+
log.Println("Warning: can't find 'git' in PATH")
90+
warnedAboutGit = true
91+
}
8792
return ""
8893
} else if err != nil {
8994
log.Fatal(strings.Join(cmd.Args, " "), ": ", err, "\n", stderr.String())

0 commit comments

Comments
 (0)