Skip to content

Commit a16e67f

Browse files
committed
Revert "chore: resolve undefined-field"
This reverts commit e82db1c.
1 parent e82db1c commit a16e67f

File tree

5 files changed

+62
-46
lines changed

5 files changed

+62
-46
lines changed

lua/nvim-tree/git/utils.lua

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,51 @@ function M.file_status_to_dir_status(status, cwd)
127127
return r
128128
end
129129

130+
---Git file status for an absolute path with optional fallback
131+
---@param parent_ignored boolean
132+
---@param status table?
133+
---@param path string
134+
---@param path_fallback string?
135+
---@return GitStatus
136+
function M.git_status_file(parent_ignored, status, path, path_fallback)
137+
---@type GitStatus
138+
local st = {}
139+
140+
if parent_ignored then
141+
st.file = "!!"
142+
elseif status and status.files then
143+
st.file = status.files[path] or status.files[path_fallback]
144+
end
145+
146+
return st
147+
end
148+
149+
---Git file and directory status for an absolute path with optional file fallback
150+
---@param parent_ignored boolean
151+
---@param status table?
152+
---@param path string
153+
---@param path_file string? alternative file path when no other file status
154+
---@return GitStatus?
155+
function M.git_status_dir(parent_ignored, status, path, path_file)
156+
---@type GitStatus?
157+
local st
158+
159+
if parent_ignored then
160+
st = {}
161+
st.file = "!!"
162+
elseif status then
163+
st = {}
164+
st.file = status.files and (status.files[path] or status.files[path_file])
165+
if status.dirs then
166+
st.dir = {}
167+
st.dir.direct = status.dirs.direct and status.dirs.direct[path]
168+
st.dir.indirect = status.dirs.indirect and status.dirs.indirect[path]
169+
end
170+
end
171+
172+
return st
173+
end
174+
130175
function M.setup(opts)
131176
if opts.git.cygwin_support then
132177
M.use_cygpath = vim.fn.executable("cygpath") == 1

lua/nvim-tree/node/directory-link.lua

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
local git_utils = require("nvim-tree.git.utils")
2+
13
local DirectoryNode = require("nvim-tree.node.directory")
24

35
---@class (exact) DirectoryLinkNode: DirectoryNode
@@ -34,24 +36,11 @@ function DirectoryLinkNode:destroy()
3436
DirectoryNode.destroy(self)
3537
end
3638

37-
---Update the directory GitStatus of link target and the file status of the link itself
38-
---@param parent_ignored boolean
39-
---@param status table|nil
39+
-----Update the directory GitStatus of link target and the file status of the link itself
40+
-----@param parent_ignored boolean
41+
-----@param status table|nil
4042
function DirectoryLinkNode:update_git_status(parent_ignored, status)
41-
if parent_ignored then
42-
self.git_status = {}
43-
self.git_status.file = "!!"
44-
elseif status then
45-
self.git_status = {}
46-
self.git_status.file = status.files and (status.files[self.link_to] or status.files[self.absolute_path])
47-
if status.dirs then
48-
self.git_status.dir = {}
49-
self.git_status.dir.direct = status.dirs.direct and status.dirs.direct[self.absolute_path]
50-
self.git_status.dir.indirect = status.dirs.indirect and status.dirs.indirect[self.absolute_path]
51-
end
52-
else
53-
self.git_status = nil
54-
end
43+
self.git_status = git_utils.git_status_dir(parent_ignored, status, self.link_to, self.absolute_path)
5544
end
5645

5746
---Create a sanitized partial copy of a node, populating children recursively.

lua/nvim-tree/node/directory.lua

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
local git_utils = require("nvim-tree.git.utils")
2+
13
local Node = require("nvim-tree.node")
24

35
---@class (exact) DirectoryNode: Node
@@ -67,20 +69,7 @@ end
6769
---@param parent_ignored boolean
6870
---@param status table|nil
6971
function DirectoryNode:update_git_status(parent_ignored, status)
70-
if parent_ignored then
71-
self.git_status = {}
72-
self.git_status.file = "!!"
73-
elseif status then
74-
self.git_status = {}
75-
self.git_status.file = status.files and status.files[self.absolute_path]
76-
if status.dirs then
77-
self.git_status.dir = {}
78-
self.git_status.dir.direct = status.dirs.direct and status.dirs.direct[self.absolute_path]
79-
self.git_status.dir.indirect = status.dirs.indirect and status.dirs.indirect[self.absolute_path]
80-
end
81-
else
82-
self.git_status = nil
83-
end
72+
self.git_status = git_utils.git_status_dir(parent_ignored, status, self.absolute_path, nil)
8473
end
8574

8675
---@return string[]? xy short-format statuses

lua/nvim-tree/node/file-link.lua

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
local git_utils = require("nvim-tree.git.utils")
2+
13
local FileNode = require("nvim-tree.node.file")
24

35
---@class (exact) FileLinkNode: FileNode
@@ -30,16 +32,11 @@ function FileLinkNode:destroy()
3032
FileNode.destroy(self)
3133
end
3234

33-
---Update the GitStatus of the target otherwise the link itself
34-
---@param parent_ignored boolean
35-
---@param status table|nil
35+
-----Update the GitStatus of the target otherwise the link itself
36+
-----@param parent_ignored boolean
37+
-----@param status table|nil
3638
function FileLinkNode:update_git_status(parent_ignored, status)
37-
self.git_status = {}
38-
if parent_ignored then
39-
self.git_status.file = "!!"
40-
elseif status and status.files then
41-
self.git_status.file = status.files[self.link_to] or status.files[self.absolute_path]
42-
end
39+
self.git_status = git_utils.git_status_file(parent_ignored, status, self.link_to, self.absolute_path)
4340
end
4441

4542
---Create a sanitized partial copy of a node

lua/nvim-tree/node/file.lua

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
local git_utils = require("nvim-tree.git.utils")
12
local utils = require("nvim-tree.utils")
23

34
local Node = require("nvim-tree.node")
@@ -43,12 +44,7 @@ end
4344
---@param parent_ignored boolean
4445
---@param status table|nil
4546
function FileNode:update_git_status(parent_ignored, status)
46-
self.git_status = {}
47-
if parent_ignored then
48-
self.git_status.file = "!!"
49-
elseif status and status.files then
50-
self.git_status.file = status.files[self.absolute_path]
51-
end
47+
self.git_status = git_utils.git_status_file(parent_ignored, status, self.absolute_path, nil)
5248
end
5349

5450
---@return string[]? xy short-format statuses

0 commit comments

Comments
 (0)