Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions lute/cli/commands/transform/lib/ignore.luau
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ end

local function parseGitignore(filepath: path.path): GitignoreData
local contents = fs.readfiletostring(path.format(filepath))
return parseGitignoreContents(assert(path.dirname(filepath)), contents)
local parentDirectory = if #filepath.parts > 0 then path.dirname(filepath) else nil
assert(parentDirectory)
return parseGitignoreContents(parentDirectory, contents)
end

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

--- Checks whether the given file matches an ignore
function IgnoreResolver.isIgnoredFile(self: IgnoreResolver, filepath: path.path)
local directory = path.dirname(filepath)
local directory = if #filepath.parts > 0 then path.dirname(filepath) else nil
assert(directory ~= nil, "filepath has no directory!")

local ignoreData = self:_readIgnoreRecursive(directory)
Expand All @@ -205,11 +207,12 @@ end

function IgnoreResolver.isIgnoredDirectory(self: IgnoreResolver, directorypath: path.path)
-- Hardcode: skip the .git directory
if path.basename(directorypath) == ".git" then
local basename = path.basename(directorypath)
if basename == ".git" then
return true
end

local parentDirectory = path.dirname(directorypath)
local parentDirectory = if basename then path.dirname(directorypath) else nil
if parentDirectory then
local ignoreData = self:_readIgnoreRecursive(parentDirectory)
return isIgnored(ignoreData, path.format(directorypath), true)
Expand All @@ -223,7 +226,7 @@ function IgnoreResolver._readIgnoreRecursive(self: IgnoreResolver, directory: st
return self._ignoreCache[directory]
end

local parentPath = path.dirname(directory)
local parentPath = if path.basename(directory) then path.dirname(directory) else nil
local baseIgnores = if parentPath then self:_readIgnoreRecursive(parentPath) else nil
local gitignorePath = path.join(directory, ".gitignore")

Expand Down