fast-glob icon indicating copy to clipboard operation
fast-glob copied to clipboard

Weird behavior with ignore pattern and **/*

Open timtim17 opened this issue 2 years ago • 1 comments

Environment

  • OS Version: MacOS Monterrey 12.1
  • Node.js Version: v16.13.0
  • fast-glob: 3.2.7

Actual behavior

aus@Austins-MBP src % node index.js
[ 'foo/bar.txt', 'foo/ignore.txt' ]
[ 'foo/bar.txt', 'test/baz/.not_this_either.txt' ]
[ 'foo/bar.txt' ]

Results A: Works as expected. Gets all txt files, ignoring any in the test directory. Results B: Does not work as expected. It does correctly give me all text files in the foo folder, except for the ignored ignore.txt, but it also gives me one of (but notably not all) files in the test directory. Results C: Works as expected, after making a slight change to the ignore option.

Expected behavior

aus@Austins-MBP src % node index.js
[ 'foo/bar.txt', 'foo/ignore.txt' ]
[ 'foo/bar.txt' ]
[ 'foo/bar.txt' ]

Steps to reproduce

  1. See code sample

Code sample

aus@Austins-MBP src % tree -a
.
├── foo
│   ├── bar.txt
│   └── ignore.txt
├── index.js
└── test
    ├── baz
    │   ├── .not_this_either.txt
    │   └── also_no.txt
    └── no.txt

3 directories, 6 files
const fg = require('fast-glob');

const resultsA = fg.sync('**/*.txt', {
    ignore: ['**/test/**/*']
});
console.log(resultsA);

const resultsB = fg.sync('**/!(ignore)*.txt', {
    ignore: ['**/test/**/*']
});
console.log(resultsB);

const resultsC = fg.sync('**/!(ignore)*.txt', {
    ignore: ['**/test/**']
});
console.log(resultsC);

Originally posted by @timtim17 in https://github.com/mrmlnc/fast-glob/issues/329#issuecomment-978833580

timtim17 avatar Jan 05 '22 02:01 timtim17

Hello, @timtim17,

Thanks for the issue and the detailed description of the problem.

Yeap, this is a bug. The bug relates to our pattern processing mechanism on the input. We must always exclude files that start with a dot when their path covers by a common pattern (**/*) in the ignore option.

If you specify the dot option, everything will work correctly. The pattern (**/test/**) works because it excludes reading the directory (the directory is not read at all). When the pattern (**/test/**/*) is specified, the directory is read first and then a found entries are excluded by pattern.

mrmlnc avatar Sep 08 '22 06:09 mrmlnc

To solve this problem, we need to make a breaking change. We need to enable matching for files that start with a dot for negative patterns.

mrmlnc avatar Apr 29 '23 17:04 mrmlnc

I think this issue can be fixed in the current major version of the package, because this change affects only a part of the patterns.

Already fixed in the master. Will be shipped with 3.3.0.

mrmlnc avatar May 13 '23 20:05 mrmlnc