@@ -638,6 +638,58 @@ test('nested gitignore with negation applies recursively to globby results (issu
638638 t . false ( result . includes ( 'y/z/a1.txt' ) ) ;
639639} ) ;
640640
641+ test . serial ( 'parent directory patterns work with gitignore option (issue #133)' , async t => {
642+ const temporaryParent = temporaryDirectory ( ) ;
643+ const temporarySrc = path . join ( temporaryParent , 'src' ) ;
644+ const temporaryChild = path . join ( temporaryParent , 'child' ) ;
645+
646+ fs . mkdirSync ( temporarySrc , { recursive : true } ) ;
647+ fs . mkdirSync ( temporaryChild , { recursive : true } ) ;
648+
649+ const srcFile1 = path . join ( temporarySrc , 'test1.ts' ) ;
650+ const srcFile2 = path . join ( temporarySrc , 'test2.ts' ) ;
651+
652+ fs . writeFileSync ( srcFile1 , 'content1' , 'utf8' ) ;
653+ fs . writeFileSync ( srcFile2 , 'content2' , 'utf8' ) ;
654+
655+ // Add a .gitignore to ensure gitignore processing is active
656+ fs . writeFileSync ( path . join ( temporaryParent , '.gitignore' ) , 'node_modules\n' , 'utf8' ) ;
657+
658+ try {
659+ // Test relative parent directory pattern with gitignore:true
660+ const relativeResult = await runGlobby ( t , '../src/*.ts' , {
661+ cwd : temporaryChild ,
662+ gitignore : true ,
663+ absolute : false ,
664+ } ) ;
665+
666+ t . deepEqual ( relativeResult . sort ( ) , [ '../src/test1.ts' , '../src/test2.ts' ] ) ;
667+
668+ // Test absolute paths with gitignore:true
669+ const absoluteResult = await runGlobby ( t , '../src/*.ts' , {
670+ cwd : temporaryChild ,
671+ gitignore : true ,
672+ absolute : true ,
673+ } ) ;
674+
675+ t . is ( absoluteResult . length , 2 ) ;
676+ t . true ( absoluteResult . every ( p => path . isAbsolute ( p ) ) ) ;
677+ t . true ( absoluteResult . some ( p => p . endsWith ( 'test1.ts' ) ) ) ;
678+ t . true ( absoluteResult . some ( p => p . endsWith ( 'test2.ts' ) ) ) ;
679+
680+ // Verify it still works with gitignore:false for consistency
681+ const withoutGitignoreResult = await runGlobby ( t , '../src/*.ts' , {
682+ cwd : temporaryChild ,
683+ gitignore : false ,
684+ absolute : false ,
685+ } ) ;
686+
687+ t . deepEqual ( withoutGitignoreResult . sort ( ) , [ '../src/test1.ts' , '../src/test2.ts' ] ) ;
688+ } finally {
689+ fs . rmSync ( temporaryParent , { recursive : true , force : true } ) ;
690+ }
691+ } ) ;
692+
641693test . serial ( 'gitignore directory patterns stop fast-glob traversal' , async t => {
642694 const temporaryCwd = temporaryDirectory ( ) ;
643695 const gitignorePath = path . join ( temporaryCwd , '.gitignore' ) ;
0 commit comments