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

Skip to content

[Finder] Ignore paths from .gitignore #26714

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hkdobrev opened this issue Mar 30, 2018 · 15 comments
Closed

[Finder] Ignore paths from .gitignore #26714

hkdobrev opened this issue Mar 30, 2018 · 15 comments

Comments

@hkdobrev
Copy link
Contributor

Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? yes
Symfony version 4.1

Finder::ignoreVCS() is great at ignoring file patterns for the files created by popular VCS systems.

However, it would be great to be able to instruct Finder to actually exclude the paths excluded by .gitignore.

So if we have .gitignore:

vendor/
cache/
Finder::create()
	->files()
    ->ignoreVCS(true) // <--- Ignores `.git`
	->ignoreVCSIgnored(true); // <--- Ignores vendor/ and cache/

I think this would simplify a lot of Finder configurations which currently manually exclude the git-ignored paths or manually include everything else.

@fabpot
Copy link
Member

fabpot commented Mar 31, 2018

That's a great idea.

@Simperfit
Copy link
Contributor

Do you want to do it @hkdobrev ?

@hkdobrev
Copy link
Contributor Author

I'll take a stab at it.

@hkdobrev
Copy link
Contributor Author

hkdobrev commented Apr 2, 2018

👋 @naderman @Seldaek
Following up from composer/composer#1567 and the latest implementation in https://github.com/composer/composer/blob/c2fbbe3b86788eb507a0f4f45f9fdc623ca579c4/src/Composer/Package/Archiver/ArchivableFilesFinder.php I think it would be great to extract all Finder-related code out of Composer in a package or in the Finder component itself for this feature without reinventing the wheel.

I like how this turned out https://github.com/composer/xdebug-handler recently with everything starting from composer/composer#6802 and phpstan/phpstan#605.

I'm keen to help on extracting that code out of Composer. A small bit of refactoring would be needed to be usable with an existing finder or to incorporate it into Finder itself.

Please let me know if this is something you'd accept help with! Thanks!

Approaches:

1️⃣ Extract Composer filters and finder-related code to a composer/vcs-finder repo. Require the repo in symfony/finder for that feature. This would introduce the first dependency to symfony/finder though.
2️⃣ Incorporate the Composer filters in symfony/finder itself and Composer can use them as a simple configuration to their archive finder as composer/composer already depends on symfony/finder. However, this feature would be probably in 4.1 or 4.2 while Composer still supports older versions of symfony/finder.
3️⃣ Same as 2️⃣, but don't actually change Composer code until it moves to symfony/finder:^4.1 or above as a dependency.

@Seldaek
Copy link
Member

Seldaek commented Apr 18, 2018

@hkdobrev The main problem is we can't upgrade to latest Symfony releases, so this is not really that interesting to me, but if you like to duplicate the code in symfony I'd say why not, one day we can use it and drop it from composer.. I'd say option 3 is the best.

@hkdobrev
Copy link
Contributor Author

@Seldaek Thanks for the input! I'll try it out.

@naderman
Copy link
Member

There are also some problems with the current implementation composer/composer#5681

And there's an argument to be made that composer should only really care about gitattributes export options and not the ignore file at all, since that's for adding files and not exporting them.

@hkdobrev
Copy link
Contributor Author

I have good understanding of the structure in Composer, the latest Finder code and their differences. I've started implementing it with separate filters where people could choose which files to use. When I have something presentable I'll open a PR to request comments on the external API.

@naderman Thank you for your input, I'll take these into consideration!

@SpacePossum
Copy link
Contributor

@hkdobrev are you still working on this? we would like something like this for PHP-CS-Fixer as well :)

@ntzm
Copy link

ntzm commented Aug 20, 2018

Any updates on this @hkdobrev?

@nicolas-grekas nicolas-grekas added the Help wanted Issues and PRs which are looking for volunteers to complete them. label Feb 25, 2019
@inmarelibero
Copy link
Contributor

Hi all, I'm currently working on https://packagist.org/packages/inmarelibero/gitignore-checker

can I try to propose an implementation of this issue?

ahmedsbytes pushed a commit to ahmedsbytes/symfony that referenced this issue Mar 5, 2019
@ahmedsbytes
Copy link

ahmedsbytes commented Mar 5, 2019

Hi @inmarelibero
I worked on implementation for this feature couple of days ago when I saw @nicolas-grekas tweet about help needed issues
but did not submit it because I can not find a place that have git-ignore to regex in any language to port to php, so I was trying to write as many tests as possible for my gitignore to regex converter
when I saw your comment I got excited and created draft PR for the progress, maybe you have more info about this

ahmedsbytes pushed a commit to ahmedsbytes/symfony that referenced this issue Mar 5, 2019
@inmarelibero
Copy link
Contributor

@amaabdou ah great

I decided to implement a stand alone library (also due to the comment of @SpacePossum #26714 (comment)) in order to be reusable everywhere and not too tied with Symfony

hint: unfortunately rules cannot be synthetized only with regex, as .gitignore does not follow straight regexes

we could split the work btw: you could work on the PR and I could work on the library? what do you think of it? and if possible of course helping each other ;)

I would hear what some mantainer would say about this, as developing things without anyone knowing is a bad practice

@inmarelibero
Copy link
Contributor

maybe @Simperfit ?

@ahmedsbytes
Copy link

Sorry @inmarelibero for not replying quickly to you, I was spending my holiday :D

Honestly I was looking forward to using regex, it is a little complicated and annoying I know and I was pulling my hair while doing it but seems more convenient for this case but I could be wrong

Anyway I submitted the PR with as many cases I could for now, lets see how the review will go, if it went okay then cool, if not we can use the library you created

@nicolas-grekas nicolas-grekas removed the Help wanted Issues and PRs which are looking for volunteers to complete them. label Mar 18, 2019
@fabpot fabpot closed this as completed Mar 22, 2019
fabpot pushed a commit to ahmedsbytes/symfony that referenced this issue Mar 22, 2019
fabpot added a commit that referenced this issue Mar 22, 2019
This PR was squashed before being merged into the 4.3-dev branch (closes #30448).

Discussion
----------

 [Finder] Ignore paths from .gitignore #26714

| Q             | A
| ------------- | ---
| Branch?       | master for features
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #26714
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

<!--
Write a short README entry for your feature/bugfix here (replace this comment block.)
This will help people understand your PR and can be used as a start of the Doc PR.
Additionally:
 - Bug fixes must be submitted against the lowest branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too).
 - Features and deprecations must be submitted against the master branch.
-->
Implementation of feature request #26714

Finder::ignoreVCS() is great at ignoring file patterns for the files created by popular VCS systems.

However, it would be great to be able to instruct Finder to actually exclude the paths excluded by .gitignore.

So if we have .gitignore:

vendor/
cache/

Finder::create()
	->files()
    ->ignoreVCS(true) // <--- Ignores `.git`
	->ignoreVCSIgnored(true); // <--- Ignores vendor/ and cache/

Commits
-------

9491393  [Finder] Ignore paths from .gitignore #26714
ktherage pushed a commit to ktherage/symfony that referenced this issue Mar 22, 2019
eborges78 pushed a commit to eborges78/symfony that referenced this issue Mar 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests