diff --git a/pkg/skaffold/sync/sync.go b/pkg/skaffold/sync/sync.go index c89196e53c5..b45c183d453 100644 --- a/pkg/skaffold/sync/sync.go +++ b/pkg/skaffold/sync/sync.go @@ -217,9 +217,9 @@ func autoSyncItem(ctx context.Context, a *latest.Artifact, tag string, e filemon } func latestTag(image string, builds []graph.Artifact) string { - for _, build := range builds { - if build.ImageName == image { - return build.Tag + for _, _build := range builds { + if _build.ImageName == image { + return _build.Tag } } return "" @@ -227,6 +227,7 @@ func latestTag(image string, builds []graph.Artifact) string { func intersect(ctx context.Context, contextWd, containerWd string, syncRules []*latest.SyncRule, files []string) (syncMap, error) { ret := make(syncMap) + hadMismatch := false for _, f := range files { relPath, err := filepath.Rel(contextWd, f) if err != nil { @@ -240,11 +241,15 @@ func intersect(ctx context.Context, contextWd, containerWd string, syncRules []* if len(dsts) == 0 { log.Entry(ctx).Infof("Changed file %s does not match any sync pattern. Skipping sync", relPath) - return nil, nil + hadMismatch = true + continue } ret[f] = dsts } + if len(ret) == 0 && hadMismatch { + return nil, nil + } return ret, nil } diff --git a/pkg/skaffold/sync/sync_test.go b/pkg/skaffold/sync/sync_test.go index 43078cc1346..30847f7ae65 100644 --- a/pkg/skaffold/sync/sync_test.go +++ b/pkg/skaffold/sync/sync_test.go @@ -81,6 +81,58 @@ func TestNewSyncItem(t *testing.T) { Delete: map[string][]string{}, }, }, + { + description: "manual: match copy partial match first", + artifact: &latest.Artifact{ + ImageName: "test", + Sync: &latest.Sync{ + Manual: []*latest.SyncRule{{Src: "*.html", Dest: "."}}, + }, + Workspace: ".", + }, + builds: []graph.Artifact{ + { + ImageName: "test", + Tag: "test:123", + }, + }, + evt: filemon.Events{ + Added: []string{"someOtherFile.txt", "index.html"}, + }, + expected: &Item{ + Image: "test:123", + Copy: map[string][]string{ + "index.html": {"index.html"}, + }, + Delete: map[string][]string{}, + }, + }, + { + description: "manual: match copy partial match last", + artifact: &latest.Artifact{ + ImageName: "test", + Sync: &latest.Sync{ + Manual: []*latest.SyncRule{{Src: "*.html", Dest: "."}}, + }, + Workspace: ".", + }, + builds: []graph.Artifact{ + { + ImageName: "test", + Tag: "test:123", + }, + }, + evt: filemon.Events{ + Added: []string{"index.html", "someOtherFile.txt"}, + }, + expected: &Item{ + Image: "test:123", + Copy: map[string][]string{ + "index.html": {"index.html"}, + }, + Delete: map[string][]string{}, + }, + }, { description: "manual: no tag for image", artifact: &latest.Artifact{