Description
Symfony version(s) affected
5.4.0 or greater
Description
I'm opening this as a regression of #39257. .gitignore
parsing for this use case is broken again on Symfony 5.4.
How to reproduce
The example from the issue doesn't work anymore:
/example/**
!/example/example.txt
!/example/packages
!/example/packages/example.yaml
!/example/test/
Possible Solution
I've tried to narrow down the issue. It seems to be related to this PR. Specifically, this code. This seems to abort the gitignore processing even though the file should be included.
I think the issue is that the code doesn't check if the .gitgnore
file that we're processing is in an ignored directory or not. It just aborts if we're an ignored directory which makes it ignore all the exclude rules. I think the fix for this is just to change the order of the guard clauses like so:
if (null === $regexps = $this->readGitignoreFile("{$parentDirectory}/.gitignore")) {
continue;
}
if ($this->isIgnored($parentDirectory)) {
$ignored = true;
// rules in ignored directories are ignored, no need to check further.
break;
}
$fileRelativePath = substr($fileRealPath, \strlen($parentDirectory) + 1);
This would mean that the isIgnored
check only kicks in if we found a .gitignore
in the parentDirectory
. In my testing, it seemed to solve the issue. But I don't have a complete understanding of the PR to know if I broke anything with it. If @julienfalque approves, happy to make a PR for this.
Additional Context
No response