@@ -175,6 +175,51 @@ describe("GitIgnoreController", () => {
175175 expect ( controller . validateAccess ( "src/temp.tmp" ) ) . toBe ( false ) // Nested .gitignore
176176 expect ( controller . validateAccess ( "src/index.ts" ) ) . toBe ( true ) // Should be allowed
177177 } )
178+
179+ it ( "should filter deeply nested files from nested .gitignore patterns" , async ( ) => {
180+ // Setup mocks to simulate nested .gitignore file
181+ mockFileExists . mockImplementation ( ( filePath : string ) => {
182+ return Promise . resolve (
183+ filePath === path . join ( TEST_CWD , ".gitignore" ) ||
184+ filePath === path . join ( TEST_CWD , "src" , ".gitignore" ) ,
185+ )
186+ } )
187+
188+ // Mock different content for each file
189+ mockReadFile . mockImplementation ( ( filePath : any ) => {
190+ // Normalize path separators for cross-platform compatibility
191+ const normalizedPath = filePath . toString ( ) . replace ( / \\ / g, "/" )
192+ if ( normalizedPath . endsWith ( "src/.gitignore" ) ) {
193+ // Pattern that should match files at any depth within src/
194+ return Promise . resolve ( "*.tmp\n*.cache\n" )
195+ }
196+ return Promise . resolve ( "node_modules/\n" )
197+ } )
198+
199+ await controller . initialize ( )
200+
201+ // Test direct children of src/
202+ expect ( controller . validateAccess ( "src/temp.tmp" ) ) . toBe ( false )
203+ expect ( controller . validateAccess ( "src/data.cache" ) ) . toBe ( false )
204+
205+ // Test deeply nested files (2 levels deep)
206+ expect ( controller . validateAccess ( "src/utils/temp.tmp" ) ) . toBe ( false )
207+ expect ( controller . validateAccess ( "src/components/data.cache" ) ) . toBe ( false )
208+
209+ // Test very deeply nested files (3+ levels deep)
210+ expect ( controller . validateAccess ( "src/utils/helpers/temp.tmp" ) ) . toBe ( false )
211+ expect ( controller . validateAccess ( "src/components/ui/buttons/data.cache" ) ) . toBe ( false )
212+
213+ // Test that non-matching files are allowed at all depths
214+ expect ( controller . validateAccess ( "src/index.ts" ) ) . toBe ( true )
215+ expect ( controller . validateAccess ( "src/utils/helper.ts" ) ) . toBe ( true )
216+ expect ( controller . validateAccess ( "src/components/ui/Button.tsx" ) ) . toBe ( true )
217+
218+ // Test that patterns don't leak outside src/
219+ expect ( controller . validateAccess ( "temp.tmp" ) ) . toBe ( true )
220+ expect ( controller . validateAccess ( "lib/temp.tmp" ) ) . toBe ( true )
221+ expect ( controller . validateAccess ( "test/data.cache" ) ) . toBe ( true )
222+ } )
178223 } )
179224
180225 describe ( "filterPaths" , ( ) => {
0 commit comments