Skip to content

Finder: ignoreVCSIgnored() remove or document deviations with VCS results  #58175

Open
@regilero

Description

@regilero

Symfony version(s) affected

7.1.4

Description

ignoreVCSIgnored() tickets such as #49703 or #37781 have noticed that ignoreVCSIgnored() may not perform the .gitignore parsing exactly as git would do.

Currently the main detected issue is that git may also parse global config files and subdirectories (and parents) to widen the rules.

But I think it is also extremely dubious to expect parsing a ..gitignore file in the same way as git because:

  • even git may react differently between versions on some rules
  • a lot of rules are badly written in .gitignore files and silently ignored by git
  • some rules seems to be well written and are still silently ignored by git
  • the rule syntax is really complex. For example this Stack Overflow comment https://stackoverflow.com/a/78046706/550618 points the different behaviors of matching rules. The "middle slash" rule.

With a real .gitignore file, containing years of rules added where no one knows why some rules are active or not (I mean a real life project), trying a PHP parsing of this file to obtain a valid list of git files has a lot of chances to deviate from git ls-files --cached --others --exclude-standard.

Note that this git command would also list files that were added before addition of a rule that would now exclude the file, or added with a force flag. So at the end it is not even an equivalent of listing files validated by the .gitignore file.

How to reproduce

mkdir -p ignoretest/a/foo
touch ignoretest/a/foo/file
touch ignoretest/a/foo/muff
touch ignoretest/a/foo/zorg
cp -ar a/foo a/bar
cp -ar ignoretest/a ignoretest/b
cp -ar ignoretest/a ignoretest/c
cp -ar ignoretest/a ignoretest/d

You would get something like:

ignoretest/
  \- a/
     \- bar/
       |- file
       |- muff
       |- zorg
     \- foo/
       |- file
       |- muff
       |- zorg
   - b/
     \- bar/
       |- file
       |- muff
       |- zorg
     \- foo/
       |- file
       |- muff
       |- zorg
   - c/
     \- bar/
       |- file
       |- muff
       |- zorg
     \- foo/
       |- file
       |- muff
       |- zorg
   - d/
     \- bar/
       |- file
       |- muff
       |- zorg
     \- foo/
       |- file
       |- muff
       |- zorg

For the .gitignore file:

# exclude everything from a (without exceptions)
/ignoretest/a/
# invalid exception (a subfolder is not parsed)
!/ignoretest/a/foo

# exclude everything from b
/ignoretest/b/*
# working exception
# (the b/* on previous rule allows for exceptions)
!/ignoretest/b/foo

# exclude everything from c
/ignoretest/c/*
# non working exception in git (not sure why)
!/ignoretest/c/foo/*

# exclude everything from d
/ignoretest/d/*
# working exception on bar
!/ignoretest/d/bar
# specially exclude all in d/foo
/ignoretest/d/foo/*
# non working exception in git (not sure why)
!/ignoretest/d/foo/file
# keep all muff files in d
!/ignoretest/d/*/muff

# and then ignore all foo/muff (for a, b, c and d)
/**/foo/muff

After a git add this is what is really tracked in git (tested with 2.40.0 and 2.34.1):

ignoretest/
   - b/
     \- foo/
       |- file
       |- zorg
   - d/
     \- bar/
       |- file
       |- muff
       |- zorg

And this is what is reported by ignoreVCSIgnored()

ignoretest/
  \- a/       # nope extra folder
     \- foo/  # nope extra folder
   - b/
     \- foo/   # missing two files here (file and zorg) !
   - c/        # nope extra folder
     \- foo/   # nope extra folder
       |- file # nope extra file
       |- zorg # nope extra file
   - d/
     \- bar/
       |- muff # OK
               # missing 2 files here (file and zorg)!
     \- foo/   # nope
       |- file # nope extra file

Possible Solution

  • Remove ignoreVCSIgnored() in the Finder
  • or document the fact that this function is a "best effort" at tracking the real behavior of git
  • or use git commands to extract the list of ignored files (and respect a good design, who's better at parsing git configuration with all the git quirks than git?)

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