Skip to content

Commit cee67c1

Browse files
committed
Support empty env var when it can't be unset
Signed-off-by: David Gageot <[email protected]>
1 parent 105c214 commit cee67c1

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

build/git.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import (
1515
const DockerfileLabel = "com.docker.image.source.entrypoint"
1616

1717
func addGitProvenance(ctx context.Context, contextPath string, dockerfilePath string) (map[string]string, error) {
18-
v, ok := os.LookupEnv("BUILDX_GIT_LABELS")
19-
if !ok || contextPath == "" {
18+
v := os.Getenv("BUILDX_GIT_LABELS")
19+
if (v != "1" && v != "full") || contextPath == "" {
2020
return nil, nil
2121
}
2222
labels := make(map[string]string, 0)

build/git_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ func TestAddGitProvenanceDataWithoutEnv(t *testing.T) {
6464
assert.Nilf(t, labels, "No labels expected")
6565
}
6666

67+
func TestAddGitProvenanceDataWitEmptyEnv(t *testing.T) {
68+
defer setupTest(t)(t)
69+
os.Setenv("BUILDX_GIT_LABELS", "")
70+
labels, err := addGitProvenance(context.Background(), repoDir, filepath.Join(repoDir, "Dockerfile"))
71+
assert.Nilf(t, err, "No error expected")
72+
assert.Nilf(t, labels, "No labels expected")
73+
}
74+
6775
func TestAddGitProvenanceDataWithoutLabels(t *testing.T) {
6876
defer setupTest(t)(t)
6977
os.Setenv("BUILDX_GIT_LABELS", "full")

0 commit comments

Comments
 (0)