Skip to content

Commit 2b9cd71

Browse files
authored
Merge pull request #3352 from fjl/build-git-tag
internal/build: use 'git tag --points-at' to get the current tag
2 parents 6061707 + 20899c0 commit 2b9cd71

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

internal/build/env.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"flag"
2121
"fmt"
2222
"os"
23+
"strings"
2324
)
2425

2526
var (
@@ -89,11 +90,15 @@ func LocalEnv() Environment {
8990
}
9091
}
9192
if env.Tag == "" {
92-
env.Tag = RunGit("for-each-ref", "--points-at=HEAD", "--count=1", "--format=%(refname:short)", "refs/tags")
93+
env.Tag = firstLine(RunGit("tag", "-l", "--points-at", "HEAD"))
9394
}
9495
return env
9596
}
9697

98+
func firstLine(s string) string {
99+
return strings.Split(s, "\n")[0]
100+
}
101+
97102
func applyEnvFlags(env Environment) Environment {
98103
if !flag.Parsed() {
99104
panic("you need to call flag.Parse before Env or LocalEnv")

0 commit comments

Comments
 (0)