@@ -7,7 +7,7 @@ import { GLOBAL_IGNORE_PATTERNS, ROOT_WORKSPACE_NAME } from '../constants.js';
77import { timerify } from './Performance.js' ;
88import { compact } from './array.js' ;
99import { debugLogObject } from './debug.js' ;
10- import { isFile } from './fs.js' ;
10+ import { isDirectory , isFile } from './fs.js' ;
1111import { parseAndConvertGitignorePatterns } from './parse-and-convert-gitignores.js' ;
1212import { dirname , join , relative , toPosix } from './path.js' ;
1313
@@ -33,11 +33,13 @@ const cachedGlobIgnores = new Map<string, string[]>();
3333
3434const findAncestorGitignoreFiles = ( cwd : string ) : string [ ] => {
3535 const gitignorePaths : string [ ] = [ ] ;
36+ if ( isDirectory ( join ( cwd , '.git' ) ) ) return gitignorePaths ;
3637 let dir = dirname ( cwd ) ;
3738 let prev : string ;
3839 while ( dir ) {
3940 const filePath = join ( dir , '.gitignore' ) ;
4041 if ( isFile ( filePath ) ) gitignorePaths . push ( filePath ) ;
42+ if ( isDirectory ( join ( dir , '.git' ) ) ) break ;
4143 // biome-ignore lint/suspicious/noAssignInExpressions: deal with it
4244 dir = dirname ( ( prev = dir ) ) ;
4345 if ( prev === dir || dir === '.' ) break ;
@@ -124,7 +126,7 @@ export const findAndParseGitignores = async (cwd: string) => {
124126 for ( const pattern of ignoresForDir ) matchers . add ( _picomatch ( pattern , pmOptions ) ) ;
125127 } ;
126128
127- findAncestorGitignoreFiles ( cwd ) . forEach ( addFile ) ;
129+ for ( const filePath of findAncestorGitignoreFiles ( cwd ) ) addFile ( filePath ) ;
128130
129131 if ( isFile ( '.git/info/exclude' ) ) addFile ( '.git/info/exclude' , cwd ) ;
130132
0 commit comments