Skip to content

[Finder] GitIgnore creates incorrect regex when ignoring 'everything in subdirectory but..' #37424

@Jeroeny

Description

@Jeroeny

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:

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

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 the Gitignore::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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions