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
This commit is contained in:
Alexander Courtis 2023-08-20 12:53:41 +10:00 committed by GitHub
parent dea82ae207
commit 4e36850811
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 10 deletions

View File

@ -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)

View File

@ -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"
@ -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)

View File

@ -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