From 501c8be467d771cb9fa28518d81826a341600464 Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Wed, 23 Mar 2022 10:29:08 +0100 Subject: [PATCH] fix: configure domain for .sourceignore rules This ensures the scope while looking for matches is properly set, and rules are thus correctly matched. Signed-off-by: Hidde Beydals --- controllers/gitrepository_controller.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/controllers/gitrepository_controller.go b/controllers/gitrepository_controller.go index 6fa4bc10f..79a693712 100644 --- a/controllers/gitrepository_controller.go +++ b/controllers/gitrepository_controller.go @@ -21,6 +21,7 @@ import ( "errors" "fmt" "os" + "path/filepath" "strings" "time" @@ -496,7 +497,8 @@ func (r *GitRepositoryReconciler) reconcileArtifact(ctx context.Context, defer unlock() // Load ignore rules for archiving - ps, err := sourceignore.LoadIgnorePatterns(dir, nil) + ignoreDomain := strings.Split(dir, string(filepath.Separator)) + ps, err := sourceignore.LoadIgnorePatterns(dir, ignoreDomain) if err != nil { return sreconcile.ResultEmpty, &serror.Event{ Err: fmt.Errorf("failed to load source ignore patterns from repository: %w", err), @@ -504,11 +506,11 @@ func (r *GitRepositoryReconciler) reconcileArtifact(ctx context.Context, } } if obj.Spec.Ignore != nil { - ps = append(ps, sourceignore.ReadPatterns(strings.NewReader(*obj.Spec.Ignore), nil)...) + ps = append(ps, sourceignore.ReadPatterns(strings.NewReader(*obj.Spec.Ignore), ignoreDomain)...) } // Archive directory to storage - if err := r.Storage.Archive(&artifact, dir, SourceIgnoreFilter(ps, nil)); err != nil { + if err := r.Storage.Archive(&artifact, dir, SourceIgnoreFilter(ps, ignoreDomain)); err != nil { e := &serror.Event{ Err: fmt.Errorf("unable to archive artifact to storage: %w", err), Reason: sourcev1.ArchiveOperationFailedReason,