Skip to content

Commit 5851dec

Browse files
committed
git.git_status_file takes an array
1 parent b5b3095 commit 5851dec

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

lua/nvim-tree/git/init.lua

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,28 @@ function M.git_status_dir(parent_ignored, status, absolute_path)
303303
end
304304
end
305305

306+
---Git file status for an absolute path
306307
---@param parent_ignored boolean
307308
---@param status table|nil
308-
---@param absolute_path string
309+
---@param absolute_paths string[] status for first match is returned
309310
---@return GitStatus
310-
function M.git_status_file(parent_ignored, status, absolute_path)
311-
local file_status = parent_ignored and "!!" or (status and status.files and status.files[absolute_path])
312-
return { file = file_status }
311+
function M.git_status_file(parent_ignored, status, absolute_paths)
312+
if parent_ignored then
313+
return { file = "!!" }
314+
end
315+
316+
if not status or not status.files then
317+
return {}
318+
end
319+
320+
for _, p in ipairs(absolute_paths) do
321+
local s = status.files[p]
322+
if s then
323+
return { file = s }
324+
end
325+
end
326+
327+
return {}
313328
end
314329

315330
function M.purge_state()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ function FileLinkNode:create(explorer, parent, absolute_path, link_to, name, fs_
2828
return o
2929
end
3030

31-
-----Update the GitStatus of link target
31+
-----Update the GitStatus of the target otherwise the link itself
3232
-----@param parent_ignored boolean
3333
-----@param status table|nil
3434
function FileLinkNode:update_git_status(parent_ignored, status)
35-
self.git_status = git.git_status_file(parent_ignored, status, self.link_to)
35+
self.git_status = git.git_status_file(parent_ignored, status, { self.link_to, self.absolute_path, })
3636
end
3737

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

lua/nvim-tree/node/file.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ function FileNode:create(explorer, parent, absolute_path, name, fs_stat)
3737
return o
3838
end
3939

40-
---Update the GitStatus of absolute path of the file
40+
---Update the GitStatus of the file
4141
---@param parent_ignored boolean
4242
---@param status table|nil
4343
function FileNode:update_git_status(parent_ignored, status)
44-
self.git_status = git.git_status_file(parent_ignored, status, self.absolute_path)
44+
self.git_status = git.git_status_file(parent_ignored, status, { self.absolute_path })
4545
end
4646

4747
---@return GitStatus|nil

0 commit comments

Comments
 (0)