Skip to content

Commit 4f98891

Browse files
authored
Fix infinite recursion in ignore (#540)
1 parent bc466b0 commit 4f98891

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lute/cli/commands/transform/lib/ignore.luau

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ end
142142

143143
local 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)
146148
end
147149

148150
local function matchesGlob(glob: Glob, filepath: string, isDirectory: boolean): boolean
@@ -196,7 +198,7 @@ end
196198

197199
--- Checks whether the given file matches an ignore
198200
function 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

206208
function 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

Comments
 (0)