@@ -16,7 +16,7 @@ local git = require "nvim-tree.git"
1616--- @field diag_status DiagStatus | nil
1717local BaseNode = {}
1818
19- --- @alias Node DirectoryNode | FileNode | LinkNode
19+ --- @alias Node BaseNode | DirectoryNode | FileNode | LinkNode
2020
2121--- @param o BaseNode | nil
2222--- @return BaseNode
4646function BaseNode :update_git_status (parent_ignored , status )
4747 local get_status
4848 if self .nodes then
49- get_status = git .get_dir_git_status
49+ get_status = git .git_status_file
5050 else
51- get_status = git .get_git_status
51+ get_status = git .git_status_file
5252 end
5353
5454 -- status of the node's absolute path
@@ -60,6 +60,79 @@ function BaseNode:update_git_status(parent_ignored, status)
6060 end
6161end
6262
63+ --- @return GitStatus | nil
64+ function BaseNode :get_git_status ()
65+ if not self .git_status then
66+ -- status doesn't exist
67+ return nil
68+ end
69+
70+ if not self .nodes then
71+ -- file
72+ return self .git_status .file and { self .git_status .file }
73+ end
74+
75+ -- dir
76+ if not self .explorer .opts .git .show_on_dirs then
77+ return nil
78+ end
79+
80+ local status = {}
81+ if not require (" nvim-tree.lib" ).get_last_group_node (self ).open or self .explorer .opts .git .show_on_open_dirs then
82+ -- dir is closed or we should show on open_dirs
83+ if self .git_status .file ~= nil then
84+ table.insert (status , self .git_status .file )
85+ end
86+ if self .git_status .dir ~= nil then
87+ if self .git_status .dir .direct ~= nil then
88+ for _ , s in pairs (self .git_status .dir .direct ) do
89+ table.insert (status , s )
90+ end
91+ end
92+ if self .git_status .dir .indirect ~= nil then
93+ for _ , s in pairs (self .git_status .dir .indirect ) do
94+ table.insert (status , s )
95+ end
96+ end
97+ end
98+ else
99+ -- dir is open and we shouldn't show on open_dirs
100+ if self .git_status .file ~= nil then
101+ table.insert (status , self .git_status .file )
102+ end
103+ if self .git_status .dir ~= nil and self .git_status .dir .direct ~= nil then
104+ local deleted = {
105+ [" D" ] = true ,
106+ [" D " ] = true ,
107+ [" RD" ] = true ,
108+ [" DD" ] = true ,
109+ }
110+ for _ , s in pairs (self .git_status .dir .direct ) do
111+ if deleted [s ] then
112+ table.insert (status , s )
113+ end
114+ end
115+ end
116+ end
117+ if # status == 0 then
118+ return nil
119+ else
120+ return status
121+ end
122+ end
123+
124+ --- @param projects table
125+ function BaseNode :reload_node_status (projects )
126+ local toplevel = git .get_toplevel (self .absolute_path )
127+ local status = projects [toplevel ] or {}
128+ for _ , node in ipairs (self .nodes ) do
129+ node :update_git_status (self :is_git_ignored (), status )
130+ if node .nodes and # node .nodes > 0 then
131+ self :reload_node_status (projects )
132+ end
133+ end
134+ end
135+
63136--- @return boolean
64137function BaseNode :is_git_ignored ()
65138 return self .git_status ~= nil and self .git_status .file == " !!"
0 commit comments