From 8f6e3bd21375059a8071d834c83b390fd726927c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kurowski?= Date: Thu, 23 Nov 2023 11:05:23 +0100 Subject: [PATCH] fix: recursive directory filtering in `ShouldExclude` Ensure ignore rule `bar/` matches directories by appending `/`. Addresses issue where `bar/` didn't catch directories. After this change, both `bar` and `bar/` rules filter out the `bar` directory and its contents. --- files/filter.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/files/filter.go b/files/filter.go index 6b90f1f34..93e3e71e4 100644 --- a/files/filter.go +++ b/files/filter.go @@ -1,6 +1,7 @@ package files import ( + "fmt" "os" ignore "github.com/crackcomm/go-gitignore" @@ -45,5 +46,8 @@ func (filter *Filter) ShouldExclude(fileInfo os.FileInfo) (result bool) { if !filter.IncludeHidden && isHidden(fileInfo) { return true } + if fileInfo.IsDir() { + path = fmt.Sprintf("%s/", path) + } return filter.Rules.MatchesPath(path) }