142142
143143local function parseGitignore (filepath : path .path ): GitignoreData
144144 local contents = fs .readfiletostring (path .format (filepath ))
145- return parseGitignoreContents (assert (path .dirname (filepath )), contents )
145+ local parentDirectory = if # filepath .parts > 0 then path .dirname (filepath ) else nil
146+ assert (parentDirectory )
147+ return parseGitignoreContents (parentDirectory , contents )
146148end
147149
148150local function matchesGlob (glob : Glob , filepath : string , isDirectory : boolean ): boolean
196198
197199--- Checks whether the given file matches an ignore
198200function IgnoreResolver .isIgnoredFile (self : IgnoreResolver , filepath : path .path )
199- local directory = path .dirname (filepath )
201+ local directory = if # filepath . parts > 0 then path .dirname (filepath ) else nil
200202 assert (directory ~= nil , "filepath has no directory!" )
201203
202204 local ignoreData = self :_readIgnoreRecursive (directory )
@@ -205,11 +207,12 @@ end
205207
206208function IgnoreResolver .isIgnoredDirectory (self : IgnoreResolver , directorypath : path .path )
207209 -- Hardcode: skip the .git directory
208- if path .basename (directorypath ) == ".git" then
210+ local basename = path .basename (directorypath )
211+ if basename == ".git" then
209212 return true
210213 end
211214
212- local parentDirectory = path .dirname (directorypath )
215+ local parentDirectory = if basename then path .dirname (directorypath ) else nil
213216 if parentDirectory then
214217 local ignoreData = self :_readIgnoreRecursive (parentDirectory )
215218 return isIgnored (ignoreData , path .format (directorypath ), true )
@@ -223,7 +226,7 @@ function IgnoreResolver._readIgnoreRecursive(self: IgnoreResolver, directory: st
223226 return self ._ignoreCache [directory ]
224227 end
225228
226- local parentPath = path .dirname (directory )
229+ local parentPath = if path .basename ( directory ) then path . dirname (directory ) else nil
227230 local baseIgnores = if parentPath then self :_readIgnoreRecursive (parentPath ) else nil
228231 local gitignorePath = path .join (directory , ".gitignore" )
229232
0 commit comments