File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -77,12 +77,14 @@ const findGitRoot = async (cwd: string): Promise<string> => {
7777
7878class GitIgnoreMatcher {
7979 readonly #rootPath: string ;
80+ readonly #rootPrefix: string ;
8081 readonly #matchers = new Map < string , ReturnType < typeof ignore > > ( ) ;
8182 readonly #loads = new Map < string , Promise < void > > ( ) ;
8283 readonly #ignoredDirectories = new Map < string , boolean > ( ) ;
8384
8485 private constructor ( rootPath : string ) {
8586 this . #rootPath = rootPath ;
87+ this . #rootPrefix = rootPath . endsWith ( path . sep ) ? rootPath : `${ rootPath } ${ path . sep } ` ;
8688 }
8789
8890 static async create ( cwd : string ) : Promise < GitIgnoreMatcher > {
@@ -120,7 +122,12 @@ class GitIgnoreMatcher {
120122 return false ;
121123 }
122124
123- const relativePath = path . relative ( this . #rootPath, filePath ) ;
125+ const relativePath =
126+ filePath === this . #rootPath
127+ ? ''
128+ : filePath . startsWith ( this . #rootPrefix)
129+ ? filePath . slice ( this . #rootPrefix. length )
130+ : path . relative ( this . #rootPath, filePath ) ;
124131 if ( relativePath === '' || ! isRelativePathInside ( relativePath ) ) {
125132 return false ;
126133 }
You can’t perform that action at this time.
0 commit comments