Skip to content

Commit 3ce0a8e

Browse files
feat(git): support DA state, fix(#1822): test directory capable of watching before presenting it (#1905)
* fix(#1822): test directory capable of watching before presenting it (#1901) * feat(git): support `DA` state Co-authored-by: Alexander Courtis <alex@courtis.org>
1 parent ccb6d8a commit 3ce0a8e

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

lua/nvim-tree/explorer/explore.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ local filters = require "nvim-tree.explorer.filters"
66
local live_filter = require "nvim-tree.live-filter"
77
local log = require "nvim-tree.log"
88

9+
local Watcher = require "nvim-tree.watcher"
10+
911
local M = {}
1012

1113
local function get_type_from(type_, cwd)
@@ -28,7 +30,11 @@ local function populate_children(handle, cwd, node, git_status)
2830
local ps = log.profile_start(pn)
2931

3032
t = get_type_from(t, abs)
31-
if not filters.should_filter(abs, filter_status) and not nodes_by_path[abs] then
33+
if
34+
not filters.should_filter(abs, filter_status)
35+
and not nodes_by_path[abs]
36+
and Watcher.is_fs_event_capable(abs)
37+
then
3238
local child = nil
3339
if t == "directory" and vim.loop.fs_access(abs, "R") then
3440
child = builders.folder(node, abs, name)

lua/nvim-tree/explorer/reload.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ local git = require "nvim-tree.git"
88
local log = require "nvim-tree.log"
99

1010
local NodeIterator = require "nvim-tree.iterators.node-iterator"
11+
local Watcher = require "nvim-tree.watcher"
1112

1213
local M = {}
1314

@@ -86,7 +87,7 @@ function M.reload(node, git_status, unloaded_bufnr)
8687
end
8788

8889
if not nodes_by_path[abs] then
89-
if t == "directory" and vim.loop.fs_access(abs, "R") then
90+
if t == "directory" and vim.loop.fs_access(abs, "R") and Watcher.is_fs_event_capable(abs) then
9091
local folder = builders.folder(node, abs, name)
9192
nodes_by_path[abs] = folder
9293
table.insert(node.nodes, folder)

lua/nvim-tree/renderer/components/git.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ local function build_icons_table(i)
3939
["UA"] = { icons.unmerged },
4040
[" D"] = { icons.deleted },
4141
["D "] = { icons.deleted },
42+
["DA"] = { icons.unstaged },
4243
["RD"] = { icons.deleted },
4344
["DD"] = { icons.deleted },
4445
["DU"] = { icons.deleted, icons.unmerged },

lua/nvim-tree/watcher.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,29 @@ function M.purge_watchers()
159159
end
160160
end
161161

162+
--- Windows NT will present directories that cannot be enumerated.
163+
--- Detect these by attempting to start an event monitor.
164+
--- @param path string
165+
--- @return boolean
166+
function M.is_fs_event_capable(path)
167+
if not utils.is_windows then
168+
return true
169+
end
170+
171+
local fs_event = vim.loop.new_fs_event()
172+
if not fs_event then
173+
return false
174+
end
175+
176+
if fs_event:start(path, FS_EVENT_FLAGS, function() end) ~= 0 then
177+
return false
178+
end
179+
180+
if fs_event:stop() ~= 0 then
181+
return false
182+
end
183+
184+
return true
185+
end
186+
162187
return M

0 commit comments

Comments
 (0)