Skip to content

Commit 5c46c9c

Browse files
committed
chore: resolve undefined-field
1 parent c684104 commit 5c46c9c

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

Diff for: lua/nvim-tree/git/init.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ local Watcher = require("nvim-tree.watcher").Watcher
77
local Iterator = require("nvim-tree.iterators.node-iterator")
88
local DirectoryNode = require("nvim-tree.node.directory")
99

10-
---@class GitStatus -- xy short-format statuses
10+
---@class (exact) GitStatus -- xy short-format statuses
1111
---@field file string?
1212
---@field dir table<"direct" | "indirect", string[]>?
1313

Diff for: lua/nvim-tree/git/utils.lua

+24-21
Original file line numberDiff line numberDiff line change
@@ -129,44 +129,47 @@ end
129129

130130
---Git file status for an absolute path with optional fallback
131131
---@param parent_ignored boolean
132-
---@param status table|nil
132+
---@param status table?
133133
---@param path string
134134
---@param path_fallback string?
135135
---@return GitStatus
136136
function M.git_status_file(parent_ignored, status, path, path_fallback)
137-
if parent_ignored then
138-
return { file = "!!" }
139-
end
137+
---@type GitStatus
138+
local st = {}
140139

141-
if not status or not status.files then
142-
return {}
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]
143144
end
144145

145-
return {
146-
file = status.files[path] or status.files[path_fallback]
147-
}
146+
return st
148147
end
149148

150149
---Git file and directory status for an absolute path with optional file fallback
151150
---@param parent_ignored boolean
152-
---@param status table|nil
151+
---@param status table?
153152
---@param path string
154153
---@param path_file string? alternative file path when no other file status
155-
---@return GitStatus|nil
154+
---@return GitStatus?
156155
function M.git_status_dir(parent_ignored, status, path, path_file)
156+
---@type GitStatus?
157+
local st
158+
157159
if parent_ignored then
158-
return { file = "!!" }
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
159170
end
160171

161-
if status then
162-
return {
163-
file = status.files and (status.files[path] or status.files[path_file]),
164-
dir = status.dirs and {
165-
direct = status.dirs.direct and status.dirs.direct[path],
166-
indirect = status.dirs.indirect and status.dirs.indirect[path],
167-
},
168-
}
169-
end
172+
return st
170173
end
171174

172175
function M.setup(opts)

0 commit comments

Comments
 (0)