@@ -34,7 +34,7 @@ protected function tearDown(): void
3434 *
3535 * @dataProvider getAcceptData
3636 */
37- public function testAccept (array $ gitIgnoreFiles , array $ otherFileNames , array $ expectedResult )
37+ public function testAccept (array $ gitIgnoreFiles , array $ otherFileNames , array $ expectedResult, string $ baseDir = '' )
3838 {
3939 $ otherFileNames = $ this ->toAbsolute ($ otherFileNames );
4040 foreach ($ otherFileNames as $ path ) {
@@ -51,7 +51,8 @@ public function testAccept(array $gitIgnoreFiles, array $otherFileNames, array $
5151
5252 $ inner = new InnerNameIterator ($ otherFileNames );
5353
54- $ iterator = new VcsIgnoredFilterIterator ($ inner , $ this ->tmpDir );
54+ $ baseDir = $ this ->tmpDir .('' !== $ baseDir ? '/ ' .$ baseDir : '' );
55+ $ iterator = new VcsIgnoredFilterIterator ($ inner , $ baseDir );
5556
5657 $ this ->assertIterator ($ this ->toAbsolute ($ expectedResult ), $ iterator );
5758 }
@@ -74,6 +75,55 @@ public static function getAcceptData(): iterable
7475 ],
7576 ];
7677
78+ yield 'simple file - .gitignore and in() from repository root ' => [
79+ [
80+ '.gitignore ' => 'a.txt ' ,
81+ ],
82+ [
83+ '.git ' ,
84+ 'a.txt ' ,
85+ 'b.txt ' ,
86+ 'dir/ ' ,
87+ 'dir/a.txt ' ,
88+ ],
89+ [
90+ '.git ' ,
91+ 'b.txt ' ,
92+ 'dir ' ,
93+ ],
94+ ];
95+
96+ yield 'nested git repositories only consider .gitignore files of the most inner repository ' => [
97+ [
98+ '.gitignore ' => "nested/* \na.txt " ,
99+ 'nested/.gitignore ' => 'c.txt ' ,
100+ 'nested/dir/.gitignore ' => 'f.txt ' ,
101+ ],
102+ [
103+ '.git ' ,
104+ 'a.txt ' ,
105+ 'b.txt ' ,
106+ 'nested/ ' ,
107+ 'nested/.git ' ,
108+ 'nested/c.txt ' ,
109+ 'nested/d.txt ' ,
110+ 'nested/dir/ ' ,
111+ 'nested/dir/e.txt ' ,
112+ 'nested/dir/f.txt ' ,
113+ ],
114+ [
115+ '.git ' ,
116+ 'a.txt ' ,
117+ 'b.txt ' ,
118+ 'nested ' ,
119+ 'nested/.git ' ,
120+ 'nested/d.txt ' ,
121+ 'nested/dir ' ,
122+ 'nested/dir/e.txt ' ,
123+ ],
124+ 'nested ' ,
125+ ];
126+
77127 yield 'simple file at root ' => [
78128 [
79129 '.gitignore ' => '/a.txt ' ,
0 commit comments