Skip to content
Open
Show file tree
Hide file tree
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
18 changes: 10 additions & 8 deletions lua/plenary/scandir.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,17 @@ local make_gitignore = function(basepath)
for _, v in ipairs(bp) do
if entry:find(v, 1, true) then
local negated = false
for _, w in ipairs(patterns[v].ignored) do
if not negated and entry:match(w) then
for _, inverse in ipairs(patterns[v].negated) do
if not negated and entry:match(inverse) then
negated = true
if patterns[v] then
for _, w in ipairs(patterns[v].ignored) do
if not negated and entry:match(w) then
for _, inverse in ipairs(patterns[v].negated) do
if not negated and entry:match(inverse) then
negated = true
end
end
if not negated then
return false
end
end
if not negated then
return false
end
end
end
Expand Down
32 changes: 32 additions & 0 deletions tests/plenary/scandir_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,38 @@ describe("scandir", function()
eq(false, contains(dirs, "./asdf/asdf/adsf.lua"))
end)

it("with respect_gitignore on mixed paths", function()
vim.cmd ":silent !mkdir -p test_path_root/projectdir"
vim.cmd(
":silent !touch "
.. "test_path_root/projectdir/README.md "
.. "test_path_root/projectdir/LICENSE "
.. "test_path_root/projectdir/test.so "
.. "test_path_root/external_file.txt"
)
vim.cmd ":silent !cp .gitignore test_path_root/projectdir/"
vim.cmd ":cd test_path_root/projectdir/"

local dirs = scan.scan_dir({ ".", ".." }, { respect_gitignore = true })

vim.cmd ":cd ../../"
vim.cmd(
":silent !rm "
.. "test_path_root/projectdir/README.md "
.. "test_path_root/projectdir/LICENSE "
.. "test_path_root/projectdir/test.so "
.. "test_path_root/external_file.txt "
.. "test_path_root/projectdir/.gitignore"
)
vim.cmd ":silent !rmdir test_path_root/projectdir test_path_root"

eq("table", type(dirs))
eq(true, contains(dirs, "./README.md"))
eq(true, contains(dirs, "./LICENSE"))
eq(true, contains(dirs, "../external_file.txt"))
eq(false, contains(dirs, "./test.so"))
end)

it("with search pattern", function()
local dirs = scan.scan_dir(".", { search_pattern = "filetype" })
eq("table", type(dirs))
Expand Down