Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
Closed
@carlalexander

Description

@carlalexander
Issue body actions

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.