Skip to content

[Finder]: GitIgnore unable to exclude a directory and its content #39257

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

Closed
carlalexander opened this issue Dec 1, 2020 · 2 comments
Closed

Comments

@carlalexander
Copy link

Symfony version(s) affected: >=4.4.12

Description

I'm trying to exclude a directory and its content. I have a configuration similar to the one described in #37560. I'm trying to keep all the content in /example/test/.

/example/**
!/example/example.txt
!/example/packages
!/example/packages/example.yaml
!/example/test/

This configuration will only retain the /example/test directory, but not its content. If I try a .gitignore like the one below, PCRE breaks completely:

/example/**
!/example/example.txt
!/example/packages
!/example/packages/example.yaml
!/example/test*

PCRE doesn't handle lookbehind that don't have a fixed length. So the above .gitignore file will cause preg_match(): Compilation failed: lookbehind assertion is not fixed length warnings. This, in turn, causes the whole .gitignore regex to not work and none of the rules get enforced.

@soullivaneuh
Copy link
Contributor

Got exactly the same bug with this example:

!/public/*icon.*
!/public/*.php
public/toto

Feel free to use it as fixture to reproduce the bug. 👍

@tacman
Copy link
Contributor

tacman commented Mar 24, 2021

I'm getting this with

!/local/**/index.php

in .gitignore (from here: https://github.com/Piwigo/Piwigo/blob/master/.gitignore#L9)

fabpot added a commit that referenced this issue May 9, 2021
This PR was squashed before being merged into the 4.4 branch.

Discussion
----------

Fix/Rewrite .gitignore regex builder

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | fix #39257
| License       | MIT
| Doc PR        | no

This PR fixes `.gitignore` with exclude wildcard ignore rules like `!a/*/b` were failing with `preg_match(): Compilation failed: lookbehind assertion is not fixed length at offset` PHP error.

Functionality/performance was verified against large `.gitignore` files:
- https://github.com/PrestaShop/PrestaShop/blob/1.7.7.3/.gitignore
- https://github.com/dotnet/installer/blob/v5.0.202/.gitignore
- https://github.com/dotnet/runtime/blob/v5.0.5/.gitignore

This PR also improves the testing cases.

Commits
-------

83f9fd3 Fix/Rewrite .gitignore regex builder
@fabpot fabpot closed this as completed May 9, 2021
carlalexander added a commit to ymirapp/cli that referenced this issue Jun 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants