Skip to content

Commit 936fb13

Browse files
authored
fix(git): fix 'git check-ignore' option (#153)
1 parent 2b43d10 commit 936fb13

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

lua/neo-tree/git/ignored.lua

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ M.load_ignored_per_directory = function(path)
99
log.error("load_ignored_per_directory: path must be a string")
1010
return {}
1111
end
12-
path = utils.path_join(path, "*")
13-
local cmd = 'git check-ignore "' .. path .. '"'
12+
path = vim.fn.shellescape(path) .. utils.path_separator .. "*"
13+
local cmd = "git check-ignore " .. path
1414
local result = vim.fn.systemlist(cmd)
1515
if vim.v.shell_error == 128 then
1616
if utils.truthy(result) and vim.startswith(result[1], "fatal: not a git repository") then
@@ -19,6 +19,15 @@ M.load_ignored_per_directory = function(path)
1919
log.error("Failed to load ignored files for ", path, ": ", result)
2020
return {}
2121
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
2231
return result
2332
end
2433

lua/neo-tree/sources/common/commands.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ end
173173
local open_with_cmd = function(state, open_cmd, toggle_directory)
174174
local tree = state.tree
175175
local success, node = pcall(tree.get_node, tree)
176-
if not success and node then
176+
if not (success and node) then
177177
log.debug("Could not get node.")
178178
return
179179
end

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ M.show_filter = function(state, search_as_you_type, fuzzy_finder_mode)
2525
vim.api.nvim_win_set_height(winid, row)
2626
popup_options = popups.popup_options("Enter Filter Pattern:", width, {
2727
relative = "win",
28+
winid = winid,
2829
position = {
2930
row = row,
3031
col = 0,
@@ -36,6 +37,7 @@ M.show_filter = function(state, search_as_you_type, fuzzy_finder_mode)
3637
local row = height - 3
3738
popup_options = popups.popup_options("Enter Filter Pattern:", width, {
3839
relative = "win",
40+
winid = winid,
3941
position = {
4042
row = row,
4143
col = 0,

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)