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

gitIgnore and negation patterns - not following gitIgnore specs #244

Open
yuri-scarbaci-lenio opened this issue Dec 15, 2023 · 5 comments
Open

Comments

@yuri-scarbaci-lenio
Copy link

(Thanks for reporting an issue to micromatch! If you haven't already read the contributor guidelines, Please do that now, then proceed to fill out the details below.)

Please describe the minimum necessary steps to reproduce this issue:

https://stackblitz.com/edit/node-61bbcz?file=package.json,micromatch.js,picomatch.js,nanomatch.js,ignore.js

in the console of stackblitz run the npm run test command and check the output

What is happening that shouldn't be?

I am not sure if this is intended, but if this is,
it may be worth to make it explicit in the docs
given the following

const patterns = ['cdn/*', '!cdn/readme.md'];

I expect this mean "match everything under the cdn folder except the file readme.md"

What should be happening instead?

everything at all ever results as a match because no matter what (or that's what I understand, I may be wrong, but it's not matching only under cdn folder except the given file)

Notes

I have created a comparison between different libraries because I have seen the Author actually use other libraries as a reference to double-check what other does,
I am personally trying to achieve what https://www.npmjs.com/package/ignore does, maybe this library was not even meant to be able to achieve this standard

@jonschlinkert
Copy link
Member

jonschlinkert commented Dec 15, 2023

Hi @yuri-scarbaci-lenio, this is by design, as this project follows bash, extglob, and globstar specs, which differ from gitignore specs in several ways, as you've pointed out.

Given that this is expected behavior, I'd be happy to keep this open to discuss ideas for adding gitignore support. Thoughts?


On a related note, I'm pretty sure I created a library that uses micromatch to create gitignore-compliant glob patterns. I'll try to see where that is, or if I even published it. All I could find was https://github.com/jonschlinkert/parse-gitignore, which only parses the files (I think).

@yuri-scarbaci-lenio
Copy link
Author

I think that if this is meant by design altering the scope of the project would be counter productive on the long run,

In my opinion the best thing would be just being as straightforward about this as possible,
as someone not familiar with the nuances of the difference between all the possible matching specs it has took me a lot of analysis and back and forth to even understand that syntax that looks so very similar can be interpreted in so many different way,

Since you are already mentioning comparison with similar matching libraries specifically, maybe adding a callout for this there in the comparison table

Feature minimatch micromatch picomatch nanomatch extglob braces expand-brackets ignore
...
File system operations - - - - - - - -
Support for gitIgnore specs - - - - - - -

would help this, I can't imagine being the first one to get confused here :)

@jonschlinkert
Copy link
Member

as someone not familiar with the nuances of the difference between all the possible matching specs it has took me a lot of analysis and back and forth to even understand that syntax that looks so very similar can be interpreted in so many different way

As someone who is quite familiar with most of the matching specs, it took me forever to understand lol. I know exactly what you mean.

I can't imagine being the first one to get confused here :)

Don't be too hard on yourself, lol. I'm sure other people have asked, but even if they haven't, if you've spent enough time around my projects you'll know that I'm more confused than anyone.

maybe adding a callout for this there in the comparison table

That's a good idea. Instead of a table maybe we should just add a brief mention to the readme, probably in the section that mentions bash (I'm pretty sure that's on the readme but don't quote me, I can't look at the moment but I will in a little bit.). We could just say something like, "if you're looking for something to help with matching gitignore patterns, there are some important differences in behavior in how bash and gitignore... etc. etc."

I'd be happy to take a PR if you feel like writing something.

@yuri-scarbaci-lenio
Copy link
Author

yuri-scarbaci-lenio commented Dec 15, 2023

I'd be happy to take a PR if you feel like writing something.

Sure, I will create a PR ASAP

Do you know what's the name of the specs your libraries are matching?

For reference gitIgnore is based on the fnmatch specs as per
CLI man(ual) git ignore : man 5 gitignore

GITIGNORE(5)                  Git Manual                    GITIGNORE(5)

NAME
       gitignore - Specifies intentionally untracked files to ignore

specifically:


DESCRIPTION
       [...]
       Each line in a gitignore file specifies a pattern.
       [...]

PATTERN FORMAT
       [...]
       See fnmatch(3) and the FNM_PATHNAME flag for a more detailed description.

https://man7.org/linux/man-pages/man3/fnmatch.3.html
--> https://man7.org/linux/man-pages/man7/glob.7.html

yuri-scarbaci-lenio added a commit to yuri-scarbaci-lenio/micromatch that referenced this issue Dec 15, 2023
@yuri-scarbaci-lenio
Copy link
Author

Created #245

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

No branches or pull requests

2 participants