Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitf1862d0

Browse files
committed
Implement recursive Finder::ignoreVCSIgnored filter
1 parent5dbd951 commitf1862d0

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

‎src/Symfony/Component/Finder/Finder.php‎

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,34 @@ public function count()
707707
returniterator_count($this->getIterator());
708708
}
709709

710+
privatefunctionsearchGitignoreFiles(string$dir):self
711+
{
712+
$finder =self::create()
713+
->in($dir)
714+
->ignoreDotFiles(false)
715+
->name('.gitignore');
716+
if ($this->followLinks) {
717+
$finder->followLinks();
718+
}
719+
720+
return$finder;
721+
}
722+
723+
privatefunctionbuildGitignoreRegexes(string$dir):array
724+
{
725+
returnarray_map(function (SplFileInfo$file) {
726+
try {
727+
$data =$file->getContents();
728+
}catch (\RuntimeException$e) {
729+
thrownew \RuntimeException(sprintf('Failed to read ".gitignore" "%s" file.',$file->getPathname()),0,$e);
730+
}
731+
732+
$dataRelativized = Gitignore::relativize($data,$file->getRelativePath());
733+
734+
return Gitignore::toRegex($dataRelativized);
735+
},iterator_to_array($this->searchGitignoreFiles($dir)));
736+
}
737+
710738
privatefunctionsearchInDirectory(string$dir):\Iterator
711739
{
712740
$exclude =$this->exclude;
@@ -721,11 +749,7 @@ private function searchInDirectory(string $dir): \Iterator
721749
}
722750

723751
if (static::IGNORE_VCS_IGNORED_FILES === (static::IGNORE_VCS_IGNORED_FILES &$this->ignore)) {
724-
$gitignoreFilePath =sprintf('%s/.gitignore',$dir);
725-
if (!is_readable($gitignoreFilePath)) {
726-
thrownew \RuntimeException(sprintf('The "ignoreVCSIgnored" option cannot be used by the Finder as the "%s" file is not readable.',$gitignoreFilePath));
727-
}
728-
$notPaths =array_merge($notPaths, [Gitignore::toRegex(file_get_contents($gitignoreFilePath))]);
752+
$notPaths =array_merge($notPaths,$this->buildGitignoreRegexes($dir));
729753
}
730754

731755
$minDepth =0;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp