8000 [Finder] Fix finding VCS re-included files in excluded directory by julienfalque · Pull Request #45095 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Finder] Fix finding VCS re-included files in excluded directory #45095

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

Merged
merged 1 commit into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Finder] Fix finding VCS re-included files in excluded directory
  • Loading branch information
julienfalque authored and nicolas-grekas committed Jan 26, 2022
commit d108ac54a525bd3f2390eb0cdef2b10e4b0b4c67
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ private function isIgnored(string $fileRealPath): bool

foreach ($this->parentsDirectoryDownward($fileRealPath) as $parentDirectory) {
if ($this->isIgnored($parentDirectory)) {
$ignored = true;

// rules in ignored directories are ignored, no need to check further.
break;
}
Expand Down
< 8000 td id="diff-2092cdc86ef5038d03ebcc4b2b33bbe7d7123423b8189bb10895e1c5de06ae0eR179" data-line-number="179" class="blob-num blob-num-addition js-linkable-line-number js-blob-rnum">
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@ protected function tearDown(): void
*/
public function testAccept(array $gitIgnoreFiles, array $otherFileNames, array $expectedResult)
{
foreach ($gitIgnoreFiles as $path => $content) {
$this->createFile("{$this->tmpDir}/{$path}", $content);
}

$otherFileNames = $this->toAbsolute($otherFileNames);
foreach ($otherFileNames as $path) {
$this->createFile($path);
if (str_ends_with($path, '/')) {
mkdir($path);
} else {
touch($path);
}
}

foreach ($gitIgnoreFiles as $path => $content) {
file_put_contents("{$this->tmpDir}/{$path}", $content);
}

$inner = new InnerNameIterator($otherFileNames);
Expand All @@ -64,10 +68,12 @@ public function getAcceptData(): iterable
[
'a.txt',
'b.txt',
'dir/',
'dir/a.txt',
],
[
'b.txt',
'dir',
],
];

Expand All @@ -78,20 +84,23 @@ public function getAcceptData(): iterable
[
'a.txt',
'b.txt',
'dir/',
'dir/a.txt',
],
[
'b.txt',
'dir',
'dir/a.txt',
],
];

yield 'directy' => [
yield 'directory' => [
[
'.gitignore' => 'dir/',
],
[
'a.txt',
'dir/',
'dir/a.txt',
'dir/b.txt',
],
Expand All @@ -100,7 +109,7 @@ public function getAcceptData(): iterable
],
];

yield 'directy matching a file' => [
yield 'directory matching a file' => [
[
'.gitignore' => 'dir.txt/',
],
Expand All @@ -112,15 +121,20 @@ public function getAcceptData(): iterable
],
];

yield 'directy at root' => [
yield 'directory at root' => [
[
'.gitignore' => '/dir/',
],
[
'dir/',
'dir/a.txt',
'other/',
'other/dir/',
'other/dir/b.txt',
],
[
'other',
'other/dir',
'other/dir/b.txt',
],
];
Expand All @@ -131,11 +145,15 @@ public function getAcceptData(): iterable
],
[
'a.txt',
'nested/',
'nested/a.txt',
'nested/nested/',
'nested/nested/a.txt',
],
[
'a.txt',
'nested',
'nested/nested',
],
];

Expand All @@ -145,58 +163,81 @@ public function getAcceptData(): iterable
],
[
'a.txt',
'nested/',
'nested/a.txt',
'nested/nested/',
'nested/nested/a.txt',
],
[
'a.txt',
'nested',
'nested/nested',
'nested/nested/a.txt',
],
];

yield 'directy in nested .gitignore' => [
yield 'directory in nested .gitignore' => [
[
'nested/.gitignore' => 'dir/',
],
[
'a.txt',
'dir/',
'dir/a.txt',
'nested/',
'nested/dir/',
'nested/dir/a.txt',
'nested/nested/',
'nested/nested/dir/',
'nested/nested/dir/a.txt',
],
[
'a.txt',
'dir',
'dir/a.txt',
'nested',
'nested/nested',
],
];

yield 'directy matching a file in nested .gitignore' => [
yield 'directory matching a file in nested .gitignore' => [
[
'nested/.gitignore' => 'dir.txt/',
],
[
'dir.txt',
'nested/',
'nested/dir.txt',
],
[
'dir.txt',
'nested',
'nested/dir.txt',
],
];

yield 'directy at root of nested .gitignore' => [
yield 'directory at root of nested .gitignore' => [
[
'nested/.gitignore' => '/dir/',
],
[
'a.txt',
'dir/',
'dir/a.txt',
'nested/',
'nested/dir/',
'nested/dir/a.txt',
'nested/nested/',
'nested/nested/dir/',
'nested/nested/dir/a.txt',
],
[
'a.txt',
'dir',
'dir/a.txt',
'nested',
'nested/nested',
'nested/nested/dir',
'nested/nested/dir/a.txt',
],
];
Expand All @@ -209,12 +250,15 @@ public function getAcceptData(): iterable
[
'a.txt',
'b.txt',
'nested/',
'nested/a.txt',
'nested/b.txt',
'nested/dir/',
'nested/dir/a.txt',
'nested/dir/b.txt',
],
[
'nested',
'nested/a.txt',
],
];
Expand All @@ -227,8 +271,10 @@ public function getAcceptData(): iterable
[
'a.txt',
'b.txt',
'nested/',
'nested/a.txt',
'nested/b.txt',
'nested/dir/',
'nested/dir/a.txt',
'nested/dir/b.txt',
],
Expand All @@ -241,12 +287,33 @@ public function getAcceptData(): iterable
'a/.gitignore' => &# 6D40 39;!c/',
],
[
'a/',
'a/b/',
'a/b/c/',
'a/b/c/d.txt',
],
[
'a',
'a/b',
'a/b/c',
'a/b/c/d.txt',
],
];

yield 'file included from subdirectory with everything excluded' => [
[
'.gitignore' => "/a/**\n!/a/b.txt",
],
[
'a/',
'a/a.txt',
'a/b.txt',
'a/c.txt',
],
[
'a/b.txt',
],
];
}

public function testAcceptAtRootDirectory()
Expand All @@ -267,20 +334,6 @@ private function toAbsolute(array $files): array
return $files;
}

private function createFile(string $path, string $content = null): void
{
$dir = \dirname($path);
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}

if (null !== $content) {
file_put_contents($path, $content);
} else {
touch($path);
}
}

private function removeDirectory(string $dir): void
{
foreach ((new Finder())->in($dir)->ignoreDotFiles(false)->depth('< 1') as $file) {
Expand Down
0