Skip to content

Commit b1440b0

Browse files
committed
build: makes git dirty check opt-in
Signed-off-by: CrazyMax <[email protected]>
1 parent a3286a0 commit b1440b0

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

build/git.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,13 @@ func getGitAttributes(ctx context.Context, contextPath string, dockerfilePath st
6767
if sha, err := gitc.FullCommit(); err != nil && !gitutil.IsUnknownRevision(err) {
6868
return res, errors.Wrapf(err, "buildx: failed to get git commit")
6969
} else if sha != "" {
70-
if gitc.IsDirty() {
70+
checkDirty := false
71+
if v, ok := os.LookupEnv("BUILDX_GIT_CHECK_DIRTY"); ok {
72+
if v, err := strconv.ParseBool(v); err == nil {
73+
checkDirty = v
74+
}
75+
}
76+
if checkDirty && gitc.IsDirty() {
7177
sha += "-dirty"
7278
}
7379
if setGitLabels {

build/git_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ func TestGetGitAttributes(t *testing.T) {
131131

132132
func TestGetGitAttributesDirty(t *testing.T) {
133133
setupTest(t)
134+
t.Setenv("BUILDX_GIT_CHECK_DIRTY", "true")
134135

135136
// make a change to test dirty flag
136137
df := []byte("FROM alpine:edge\n")

0 commit comments

Comments
 (0)