diff --git a/fs/filter/filter.go b/fs/filter/filter.go index 1714dabf5..304ab87f8 100644 --- a/fs/filter/filter.go +++ b/fs/filter/filter.go @@ -267,6 +267,10 @@ func (f *Filter) addDirGlobs(Include bool, glob string) error { func (f *Filter) Add(Include bool, glob string) error { isDirRule := strings.HasSuffix(glob, "/") isFileRule := !isDirRule + // Make excluding "dir/" equivalent to excluding "dir/**" + if isDirRule && !Include { + glob += "**" + } if strings.Contains(glob, "**") { isDirRule, isFileRule = true, true } diff --git a/fs/filter/filter_test.go b/fs/filter/filter_test.go index 1fc4ef671..3d5439fe2 100644 --- a/fs/filter/filter_test.go +++ b/fs/filter/filter_test.go @@ -523,6 +523,21 @@ func TestFilterAddDirRuleOrFileRule(t *testing.T) { + (^|/)potato$ --- Directory filter rules --- + ^.*$`, + }, + { + false, + "potato/", + `--- File filter rules --- +- (^|/)potato/.*$ +--- Directory filter rules --- +- (^|/)potato/.*$`, + }, + { + true, + "potato/", + `--- File filter rules --- +--- Directory filter rules --- ++ (^|/)potato/$`, }, { false,