Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird behavior with ignore pattern and **/* #343

Closed
timtim17 opened this issue Jan 5, 2022 · 3 comments · Fixed by #391
Closed

Weird behavior with ignore pattern and **/* #343

timtim17 opened this issue Jan 5, 2022 · 3 comments · Fixed by #391
Milestone

Comments

@timtim17
Copy link

timtim17 commented Jan 5, 2022

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 #329 (comment)

@mrmlnc mrmlnc modified the milestone: 3.2.12 Sep 8, 2022
@mrmlnc
Copy link
Owner

mrmlnc commented Sep 8, 2022

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 mrmlnc added this to the 4.0.0 milestone Apr 29, 2023
@mrmlnc
Copy link
Owner

mrmlnc commented Apr 29, 2023

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 mrmlnc modified the milestones: 4.0.0, 3.x.x May 6, 2023
@mrmlnc mrmlnc modified the milestones: 3.x.x, 3.3.0 May 13, 2023
@mrmlnc
Copy link
Owner

mrmlnc commented May 13, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants