Merge pull request #6534 from jsternberg/copy-ignored-file-linter-negated-matches

linter: do not attempt to check for copying ignored file when negated patterns exist
This commit is contained in:
Tõnis Tiigi authored and GitHub committed 2026-02-24 13:16:20 -08:00
commit 373d0adc5c
2 files changed
+17 -1

No files matched your search

@@ -2041,7 +2041,13 @@ func addReachableStages(s *dispatchState, stages map[*dispatchState]struct{}) {
}
func validateCopySourcePath(src string, cfg *copyConfig) error {
if cfg.ignoreMatcher == nil {
// Do not validate copy source paths if there is no dockerignore file
// or if the dockerignore file contains exclusions.
//
// Exclusions are too difficult to statically determine if they're proper
// because it's ok for a directory to be excluded and a file inside the directory
// to be negated.
if cfg.ignoreMatcher == nil || cfg.ignoreMatcher.Exclusions() {
return nil
}
cmd := "Copy"
@@ -230,6 +230,16 @@ COPY ./Dockerfile .
Dockerfile: dockerfile,
DockerIgnore: dockerignore,
})
// No warnings should occur if we copy the directory.
dockerfile = []byte(`
FROM scratch
COPY . .
`)
checkLinterWarnings(t, sb, &lintTestParams{
Dockerfile: dockerfile,
DockerIgnore: dockerignore,
})
}
func testSecretsUsedInArgOrEnv(t *testing.T, sb integration.Sandbox) {