Skip to content

Commit 4e36850

Browse files
authored
fix(#2301): various git folder status fixes (#2373)
* fix(#2301): reloader handles grouped * fix(#2301): explore uses correct git project for grouped * fix(#2301): update parent status correctly across repositories * fix(#2301): missing require
1 parent dea82ae commit 4e36850

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed

lua/nvim-tree/actions/reloaders/reloaders.lua

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,22 @@ local renderer = require "nvim-tree.renderer"
44
local explorer_module = require "nvim-tree.explorer"
55
local core = require "nvim-tree.core"
66
local explorer_node = require "nvim-tree.explorer.node"
7+
local Iterator = require "nvim-tree.iterators.node-iterator"
78

89
local M = {}
910

1011
local function refresh_nodes(node, projects, unloaded_bufnr)
11-
local cwd = node.cwd or node.link_to or node.absolute_path
12-
local project_root = git.get_project_root(cwd)
13-
explorer_module.reload(node, projects[project_root] or {}, unloaded_bufnr)
14-
for _, _node in ipairs(node.nodes) do
15-
if _node.nodes and _node.open then
16-
refresh_nodes(_node, projects, unloaded_bufnr)
17-
end
18-
end
12+
Iterator.builder({ node })
13+
:applier(function(n)
14+
if n.open and n.nodes then
15+
local project_root = git.get_project_root(n.cwd or n.link_to or n.absolute_path)
16+
explorer_module.reload(n, projects[project_root] or {}, unloaded_bufnr)
17+
end
18+
end)
19+
:recursor(function(n)
20+
return n.group_next and { n.group_next } or (n.open and n.nodes)
21+
end)
22+
:iterate()
1923
end
2024

2125
function M.reload_node_status(parent_node, projects)

lua/nvim-tree/explorer/explore.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local utils = require "nvim-tree.utils"
22
local builders = require "nvim-tree.explorer.node-builders"
33
local explorer_node = require "nvim-tree.explorer.node"
4+
local git = require "nvim-tree.git"
45
local sorters = require "nvim-tree.explorer.sorters"
56
local filters = require "nvim-tree.explorer.filters"
67
local live_filter = require "nvim-tree.live-filter"
@@ -70,8 +71,10 @@ function M.explore(node, status)
7071
local is_root = not node.parent
7172
local child_folder_only = explorer_node.has_one_child_folder(node) and node.nodes[1]
7273
if M.config.group_empty and not is_root and child_folder_only then
74+
local child_cwd = child_folder_only.link_to or child_folder_only.absolute_path
75+
local child_status = git.load_project_status(child_cwd)
7376
node.group_next = child_folder_only
74-
local ns = M.explore(child_folder_only, status)
77+
local ns = M.explore(child_folder_only, child_status)
7578
node.nodes = ns or {}
7679

7780
log.profile_end(profile)

lua/nvim-tree/explorer/reload.lua

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,30 @@ local function reload_and_get_git_project(path, callback)
3030
end
3131

3232
local function update_parent_statuses(node, project, root)
33-
while project and node and node.absolute_path ~= root do
33+
while project and node do
34+
-- step up to the containing project
35+
if node.absolute_path == root then
36+
-- stop at the top of the tree
37+
if not node.parent then
38+
break
39+
end
40+
41+
root = git.get_project_root(node.parent.absolute_path)
42+
43+
-- stop when no more projects
44+
if not root then
45+
break
46+
end
47+
48+
-- update the containing project
49+
project = git.get_project(root)
50+
git.reload_project(root, node.absolute_path, nil)
51+
end
52+
53+
-- update status
3454
explorer_node.update_git_status(node, explorer_node.is_git_ignored(node.parent), project)
55+
56+
-- maybe parent
3557
node = node.parent
3658
end
3759
end

0 commit comments

Comments
 (0)