Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Finder]: Regression of gitIgnore unable to exclude a directory and its content #45048

Closed
@carlalexander

Description

@carlalexander

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

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