diff --git a/internal/tmpl/tmpl.go b/internal/tmpl/tmpl.go index f7a5a9a8c..624b526fe 100644 --- a/internal/tmpl/tmpl.go +++ b/internal/tmpl/tmpl.go @@ -46,6 +46,8 @@ const ( tagBody = "TagBody" releaseURL = "ReleaseURL" isGitDirty = "IsGitDirty" + isGitClean = "IsGitClean" + gitTreeState = "GitTreeState" major = "Major" minor = "Minor" patch = "Patch" @@ -83,6 +85,10 @@ const ( func New(ctx *context.Context) *Template { sv := ctx.Semver rawVersionV := fmt.Sprintf("%d.%d.%d", sv.Major, sv.Minor, sv.Patch) + treeState := "clean" + if ctx.Git.Dirty { + treeState = "dirty" + } fields := map[string]interface{}{} for k, v := range map[string]interface{}{ @@ -101,6 +107,8 @@ func New(ctx *context.Context) *Template { commitTimestamp: ctx.Git.CommitDate.UTC().Unix(), gitURL: ctx.Git.URL, isGitDirty: ctx.Git.Dirty, + isGitClean: !ctx.Git.Dirty, + gitTreeState: treeState, env: ctx.Env, date: ctx.Date.UTC().Format(time.RFC3339), timestamp: ctx.Date.UTC().Unix(), diff --git a/internal/tmpl/tmpl_test.go b/internal/tmpl/tmpl_test.go index b61247b78..e1daa59a0 100644 --- a/internal/tmpl/tmpl_test.go +++ b/internal/tmpl/tmpl_test.go @@ -92,6 +92,8 @@ func TestWithArtifact(t *testing.T) { "nightly false": `nightly {{.IsNightly}}`, "draft true": `draft {{.IsDraft}}`, "dirty true": `dirty {{.IsGitDirty}}`, + "clean false": `clean {{.IsGitClean}}`, + "state dirty": `state {{.GitTreeState}}`, "env bar: barrrrr": `env bar: {{ envOrDefault "BAR" "barrrrr" }}`, "env foo: bar": `env foo: {{ envOrDefault "FOO" "barrrrr" }}`, diff --git a/www/docs/customization/templates.md b/www/docs/customization/templates.md index d1dbb6693..579a946ff 100644 --- a/www/docs/customization/templates.md +++ b/www/docs/customization/templates.md @@ -25,6 +25,8 @@ In fields that support templates, these fields are always available: | `.CommitDate` | the UTC commit date in RFC 3339 format | | `.CommitTimestamp` | the UTC commit date in Unix format | | `.GitURL` | the git remote url | +| `.GitTreeState` | either 'clean' or 'dirty'. Since v1.24 | +| `.IsGitClean` | whether or not current git state is clean. Since v1.24 | | `.IsGitDirty` | whether or not current git state is dirty. Since v1.19 | | `.Major` | the major part of the version[^tag-is-semver] | | `.Minor` | the minor part of the version[^tag-is-semver] |