Skip to content

Commit 0724190

Browse files
committed
fix(git): fix "git check-ignore" option
1 parent e3fc3d5 commit 0724190

File tree

2 files changed

+25
-28
lines changed

2 files changed

+25
-28
lines changed

lua/neo-tree/git/ignored.lua

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
local Job = require("plenary.job")
21
local utils = require("neo-tree.utils")
32
local log = require("neo-tree.log")
43
local git_utils = require("neo-tree.git.utils")
@@ -10,36 +9,26 @@ M.load_ignored_per_directory = function(path)
109
log.error("load_ignored_per_directory: path must be a string")
1110
return {}
1211
end
13-
14-
local result = {}
15-
local job = Job:new({
16-
cwd = path,
17-
command = "git",
18-
args = { "check-ignore", "*" },
19-
enabled_recording = false,
20-
record = true,
21-
on_exit = function(job, retval)
22-
result = job:result()
23-
log.info("load_ignored_per_directory: " .. path .. ": " .. #result .. " ignored files")
24-
if retval == 128 then
25-
if utils.truthy(result) and vim.startswith(result[1], "fatal: not a git repository") then
26-
result = {}
27-
log.error(result)
28-
else
29-
result = {}
30-
log.error("Failed to load ignored files for ", path, ": ", result)
31-
end
32-
end
12+
path = vim.fn.shellescape(path) .. utils.path_separator .. "*"
13+
local cmd = "git check-ignore " .. path
14+
local result = vim.fn.systemlist(cmd)
15+
if vim.v.shell_error == 128 then
16+
if utils.truthy(result) and vim.startswith(result[1], "fatal: not a git repository") then
17+
return {}
3318
end
34-
})
35-
36-
local success, msg = pcall(job.sync, job, 200, 5)
37-
if success then
38-
return result
39-
else
40-
log.error("Failed to load ignored files for ", path, ": ", msg)
19+
log.error("Failed to load ignored files for ", path, ": ", result)
4120
return {}
4221
end
22+
23+
--check-ignore does not indicate directories the same as 'status' so we need to
24+
--add the trailing slash to the path manually.
25+
for i, item in ipairs(result) do
26+
local stat = vim.loop.fs_stat(item)
27+
if stat and stat.type == "directory" then
28+
result[i] = item .. utils.path_separator
29+
end
30+
end
31+
return result
4332
end
4433

4534
M.load_ignored = function(path)

lua/neo-tree/sources/filesystem/lib/fs_scan.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,14 @@ M.get_items_async = function(state, parent_id, path_to_reveal, callback)
162162
end
163163
end
164164
state.git_ignored = ignored
165+
else
166+
-- just update the ignored list for this dir if we are using the per dir 'check-ignore' option
167+
if
168+
state.filters.respect_gitignore and state.filters.gitignore_source == "git check-ignore"
169+
then
170+
state.git_ignored = state.git_ignored or {}
171+
vim.list_extend(state.git_ignored, git.load_ignored_per_directory(parent_id))
172+
end
165173
end
166174
do_scan(context, parent_id or state.path)
167175
end

0 commit comments

Comments
 (0)