diff --git a/build/git.go b/build/git.go index e7b5d8eb..d80a00ba 100644 --- a/build/git.go +++ b/build/git.go @@ -67,7 +67,13 @@ func getGitAttributes(ctx context.Context, contextPath string, dockerfilePath st if sha, err := gitc.FullCommit(); err != nil && !gitutil.IsUnknownRevision(err) { return res, errors.Wrapf(err, "buildx: failed to get git commit") } else if sha != "" { - if gitc.IsDirty() { + checkDirty := false + if v, ok := os.LookupEnv("BUILDX_GIT_CHECK_DIRTY"); ok { + if v, err := strconv.ParseBool(v); err == nil { + checkDirty = v + } + } + if checkDirty && gitc.IsDirty() { sha += "-dirty" } if setGitLabels { diff --git a/build/git_test.go b/build/git_test.go index 18d995b0..5d65b64b 100644 --- a/build/git_test.go +++ b/build/git_test.go @@ -131,6 +131,7 @@ func TestGetGitAttributes(t *testing.T) { func TestGetGitAttributesDirty(t *testing.T) { setupTest(t) + t.Setenv("BUILDX_GIT_CHECK_DIRTY", "true") // make a change to test dirty flag df := []byte("FROM alpine:edge\n")