-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Finder] GitIgnore creates incorrect regex when ignoring 'everything in subdirectory but..' #37424
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
Comments
Added a possible fix to the reproducer: https://github.com/Jeroeny/reproduce/blob/gitign/Gitignore.php |
I think the fix is not right either, because the way gitignore works is not that all negative rules (un-ignoring files again) are matched after positive rules (ignoring files). AFAIK, the order of rules is relevant. |
Indeed, the order is very important for the final result. I'm still testing the possible solution a bit, but haven't found a case yet where it's incorrect. Edit: Now I have (incorrect in both versions): !var/x.txt
var/x.txt
!/x.txt
/x.txt
|
I had to change the way the regex is built up, to take lines' order into consideration. I made a new class in the reproducer that correctly matches files when they are re-ignored (or re-unignored) on lines after a previous line that (un-)ignored it: https://github.com/Jeroeny/reproduce/blob/gitign/GitignoreNew.php The regex per positive It seems to work so far. |
…tories and take order of lines into account (Jeroeny) This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [Finder] Fix GitIgnore parser when dealing with (sub)directories and take order of lines into account | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #37424 | License | MIT The new regex is made per positive `.gitignore` line. Which is a match group followed by a negative lookbehind with all the negations that were on lines after that line. This also fixes some other bugs that didn't match the `.gitignore` spec and two incorrect tests. I think it's likely that there are more edge cases this PR may not cover, but I haven't found them yet. See the issue for more info. Commits ------- 609dcf6 [Finder] Fix GitIgnore parser when dealing with (sub)directories and take order of lines into account
Symfony version(s) affected: >=4.3
Description
When you want to ignore everything in a certain directory, except some specific files,
these are the
.gitignore
rules that can be used:You might think
/example/packages/
will be unignored by this, but that is not the case according to the.gitignore
standard.With this setup, any files in
/example/packages/
besides/example/packages/example.yaml
will be ignored. But theGitignore::toRegex
does not match this logic properly.See also: https://git-scm.com/docs/gitignore and https://stackoverflow.com/a/61556103/3265437
How to reproduce
https://github.com/Jeroeny/reproduce/tree/gitign
Possible Solution
The regex building logic would have to be adjusted. I've looked into this but wasn't able to fix it yet.
Additional context
See the reproducer.
The text was updated successfully, but these errors were encountered: