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

Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public function __construct(\Iterator $iterator, string $baseDir)
{
$this->baseDir = $this->normalizePath($baseDir);

foreach ($this->parentDirectoriesUpwards($this->baseDir) as $parentDirectory) {
if (@is_dir("{$parentDirectory}/.git")) {
$this->baseDir = $parentDirectory;
foreach ([$this->baseDir, ...$this->parentDirectoriesUpwards($this->baseDir)] as $directory) {
if (@is_dir("{$directory}/.git")) {
$this->baseDir = $directory;
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected function tearDown(): void
*
* @dataProvider getAcceptData
*/
public function testAccept(array $gitIgnoreFiles, array $otherFileNames, array $expectedResult)
public function testAccept(array $gitIgnoreFiles, array $otherFileNames, array $expectedResult, string $baseDir = '')
{
$otherFileNames = $this->toAbsolute($otherFileNames);
foreach ($otherFileNames as $path) {
Expand All @@ -51,7 +51,8 @@ public function testAccept(array $gitIgnoreFiles, array $otherFileNames, array $

$inner = new InnerNameIterator($otherFileNames);

$iterator = new VcsIgnoredFilterIterator($inner, $this->tmpDir);
$baseDir = $this->tmpDir.('' !== $baseDir ? '/'.$baseDir : '');
$iterator = new VcsIgnoredFilterIterator($inner, $baseDir);

$this->assertIterator($this->toAbsolute($expectedResult), $iterator);
}
Expand All @@ -74,6 +75,55 @@ public static function getAcceptData(): iterable
],
];

yield 'simple file - .gitignore and in() from repository root' => [
[
'.gitignore' => 'a.txt',
],
[
'.git',
'a.txt',
'b.txt',
'dir/',
'dir/a.txt',
],
[
'.git',
'b.txt',
'dir',
],
];

yield 'nested git repositories only consider .gitignore files of the most inner repository' => [
[
'.gitignore' => "nested/*\na.txt",
'nested/.gitignore' => 'c.txt',
'nested/dir/.gitignore' => 'f.txt',
],
[
'.git',
'a.txt',
'b.txt',
'nested/',
'nested/.git',
'nested/c.txt',
'nested/d.txt',
'nested/dir/',
'nested/dir/e.txt',
'nested/dir/f.txt',
],
[
'.git',
'a.txt',
'b.txt',
'nested',
'nested/.git',
'nested/d.txt',
'nested/dir',
'nested/dir/e.txt',
],
'nested',
];

yield 'simple file at root' => [
[
'.gitignore' => '/a.txt',
Expand Down