Skip to content

fix(#2301): various git folder status fixes #2373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 20, 2023
Merged
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
20 changes: 12 additions & 8 deletions lua/nvim-tree/actions/reloaders/reloaders.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ local renderer = require "nvim-tree.renderer"
local explorer_module = require "nvim-tree.explorer"
local core = require "nvim-tree.core"
local explorer_node = require "nvim-tree.explorer.node"
local Iterator = require "nvim-tree.iterators.node-iterator"

local M = {}

local function refresh_nodes(node, projects, unloaded_bufnr)
local cwd = node.cwd or node.link_to or node.absolute_path
local project_root = git.get_project_root(cwd)
explorer_module.reload(node, projects[project_root] or {}, unloaded_bufnr)
for _, _node in ipairs(node.nodes) do
if _node.nodes and _node.open then
refresh_nodes(_node, projects, unloaded_bufnr)
end
end
Iterator.builder({ node })
:applier(function(n)
if n.open and n.nodes then
local project_root = git.get_project_root(n.cwd or n.link_to or n.absolute_path)
explorer_module.reload(n, projects[project_root] or {}, unloaded_bufnr)
end
end)
:recursor(function(n)
return n.group_next and { n.group_next } or (n.open and n.nodes)
end)
:iterate()
end

function M.reload_node_status(parent_node, projects)
Expand Down
5 changes: 4 additions & 1 deletion lua/nvim-tree/explorer/explore.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local utils = require "nvim-tree.utils"
local builders = require "nvim-tree.explorer.node-builders"
local explorer_node = require "nvim-tree.explorer.node"
local git = require "nvim-tree.git"
local sorters = require "nvim-tree.explorer.sorters"
local filters = require "nvim-tree.explorer.filters"
local live_filter = require "nvim-tree.live-filter"
Expand Down Expand Up @@ -70,8 +71,10 @@ function M.explore(node, status)
local is_root = not node.parent
local child_folder_only = explorer_node.has_one_child_folder(node) and node.nodes[1]
if M.config.group_empty and not is_root and child_folder_only then
local child_cwd = child_folder_only.link_to or child_folder_only.absolute_path
local child_status = git.load_project_status(child_cwd)
node.group_next = child_folder_only
local ns = M.explore(child_folder_only, status)
local ns = M.explore(child_folder_only, child_status)
node.nodes = ns or {}

log.profile_end(profile)
Expand Down
24 changes: 23 additions & 1 deletion lua/nvim-tree/explorer/reload.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,30 @@ local function reload_and_get_git_project(path, callback)
end

local function update_parent_statuses(node, project, root)
while project and node and node.absolute_path ~= root do
while project and node do
-- step up to the containing project
if node.absolute_path == root then
-- stop at the top of the tree
if not node.parent then
break
end

root = git.get_project_root(node.parent.absolute_path)

-- stop when no more projects
if not root then
break
end

-- update the containing project
project = git.get_project(root)
git.reload_project(root, node.absolute_path, nil)
end

-- update status
explorer_node.update_git_status(node, explorer_node.is_git_ignored(node.parent), project)

-- maybe parent
node = node.parent
end
end
Expand Down