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
3 changed files with 39 additions and 10 deletions

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