Skip to content

Commit

Permalink
Merge pull request #1650 from crazy-max/dirty-optin
Browse files Browse the repository at this point in the history
build: makes git dirty check opt-in
  • Loading branch information
tonistiigi committed Feb 28, 2023
2 parents f2ac30f + 0645acf commit 5e685c0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion build/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions build/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 5e685c0

Please sign in to comment.