diff --git a/changeset/commit.go b/changeset/commit.go index da38bd330..90a031f59 100644 --- a/changeset/commit.go +++ b/changeset/commit.go @@ -39,7 +39,10 @@ var ( // The result will have a '-dirty' suffix if the workspace was not clean func Get() string { once.Do(func() { - rev = get() + if rev == "" { + rev = get() + } + // It has been set through ldflags, do nothing }) return rev diff --git a/changeset/commit_test.go b/changeset/commit_test.go index 8774dfed8..a764d1865 100644 --- a/changeset/commit_test.go +++ b/changeset/commit_test.go @@ -73,6 +73,7 @@ func TestGet(t *testing.T) { for _, c := range cases { t.Run(c.name, func(t *testing.T) { + rev = "" once = sync.Once{} readBuildInfo = func() (info *debug.BuildInfo, ok bool) { return c.info, c.ok