File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -164,6 +164,15 @@ class GitIgnoreMatcher {
164164 }
165165
166166 #matches( relativePath : string , isDirectory : boolean ) : boolean {
167+ // Most repositories only use a root `.gitignore`. Avoid checking every path
168+ // segment when no nested matcher can override its result.
169+ const rootMatcher = this . #matchers. size === 1 ? this . #matchers. get ( this . #rootPath) : undefined ;
170+ if ( rootMatcher ) {
171+ // `ignore` expects POSIX separators and uses a trailing slash to distinguish directories.
172+ const pathFromMatcher = toPosixPath ( relativePath ) ;
173+ return rootMatcher . test ( isDirectory ? `${ pathFromMatcher } /` : pathFromMatcher ) . ignored ;
174+ }
175+
167176 const segments = relativePath . split ( path . sep ) ;
168177 let directoryPath = this . #rootPath;
169178 let pathFromMatcher = segments . join ( '/' ) ;
You can’t perform that action at this time.
0 commit comments