From 24f6408ed7a6a6830e8c3060ba9c865dbbe40335 Mon Sep 17 00:00:00 2001 From: Ben Schumacher Date: Wed, 2 Nov 2022 15:25:48 +0100 Subject: [PATCH] Add notice to build info if build is dirty (#123) --- experimental/command/info.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/experimental/command/info.go b/experimental/command/info.go index b90056f..a882cb5 100644 --- a/experimental/command/info.go +++ b/experimental/command/info.go @@ -27,6 +27,7 @@ func BuildInfo(manifest model.Manifest) (string, error) { revision string revisionShort string buildTime time.Time + dirty bool ) for _, s := range info.Settings { switch s.Key { @@ -40,6 +41,10 @@ func BuildInfo(manifest model.Manifest) (string, error) { if err != nil { return "", err } + case "vcs.modified": + if s.Value == "true" { + dirty = true + } } } @@ -50,12 +55,18 @@ func BuildInfo(manifest model.Manifest) (string, error) { path = strings.TrimSuffix(path, matches[len(matches)-1]) } + dirtyText := "" + if dirty { + dirtyText = " (dirty)" + } + commit := fmt.Sprintf("[%s](https://%s/commit/%s)", revisionShort, path, revision) - return fmt.Sprintf("%s version: %s, %s, built %s with %s\n", + return fmt.Sprintf("%s version: %s, %s%s, built %s with %s\n", manifest.Name, manifest.Version, commit, + dirtyText, buildTime.Format(time.RFC1123), info.GoVersion), nil