fix(git): git folder fixes and improvements (#1809)
* coding style
* outlined git.show_on_open_dirs behavior
* show some icon on opendir even if show_on_open_dir=false
and show all children's status on parent
* fixed renamed icon not showing
* sorted icons
* removed DU from deleted as file will show up in tree
* fixed update_git_status in reloaders not tested
* fixed Api.git.reload()
Tested update_git_status in reloaders.lua
* sort icon only if not git signcolumn
* fixed crashing when root dir isn't git dir
* made git.show_on_dirs doc more concise
* git_statuses -> git_status for consistency
* explorer/common.lua -> explorer/node.lua
* fixed #1784 conflict
* don't order icons
* Revert "don't order icons"
This reverts commit 23f6276ef7.
This commit is contained in:
@@ -250,10 +250,17 @@ function Builder:_build_line(node, idx, num_children, unloaded_bufnr)
|
||||
local git_highlight = git.get_highlight(node)
|
||||
local git_icons_tbl = git.get_icons(node)
|
||||
|
||||
if self.is_git_sign and git_icons_tbl and #git_icons_tbl > 0 then
|
||||
local git_info = git_icons_tbl[1]
|
||||
table.insert(self.signs, { sign = git_info.hl, lnum = self.index + 1 })
|
||||
git_icons_tbl = {}
|
||||
if git_icons_tbl and #git_icons_tbl > 0 then
|
||||
if self.is_git_sign then
|
||||
local git_info = git_icons_tbl[1]
|
||||
table.insert(self.signs, { sign = git_info.hl, lnum = self.index + 1 })
|
||||
git_icons_tbl = {}
|
||||
else
|
||||
-- sort icons so it looks slightly better
|
||||
table.sort(git_icons_tbl, function(a, b)
|
||||
return a.ord < b.ord
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
local is_folder = node.nodes ~= nil
|
||||
|
||||
@@ -1,68 +1,51 @@
|
||||
local notify = require "nvim-tree.notify"
|
||||
local explorer_common = require "nvim-tree.explorer.common"
|
||||
local explorer_node = require "nvim-tree.explorer.node"
|
||||
|
||||
local M = {
|
||||
SIGN_GROUP = "NvimTreeGitSigns",
|
||||
}
|
||||
|
||||
local function build_icons_table(i)
|
||||
local icons = {
|
||||
staged = { icon = i.staged, hl = "NvimTreeGitStaged", ord = 1 },
|
||||
unstaged = { icon = i.unstaged, hl = "NvimTreeGitDirty", ord = 2 },
|
||||
renamed = { icon = i.renamed, hl = "NvimTreeGitRenamed", ord = 3 },
|
||||
deleted = { icon = i.deleted, hl = "NvimTreeGitDeleted", ord = 4 },
|
||||
unmerged = { icon = i.unmerged, hl = "NvimTreeGitMerge", ord = 5 },
|
||||
untracked = { icon = i.untracked, hl = "NvimTreeGitNew", ord = 6 },
|
||||
ignored = { icon = i.ignored, hl = "NvimTreeGitIgnored", ord = 7 },
|
||||
}
|
||||
return {
|
||||
["M "] = { { icon = i.staged, hl = "NvimTreeGitStaged" } },
|
||||
[" M"] = { { icon = i.unstaged, hl = "NvimTreeGitDirty" } },
|
||||
["C "] = { { icon = i.staged, hl = "NvimTreeGitStaged" } },
|
||||
[" C"] = { { icon = i.unstaged, hl = "NvimTreeGitDirty" } },
|
||||
["CM"] = { { icon = i.unstaged, hl = "NvimTreeGitDirty" } },
|
||||
[" T"] = { { icon = i.unstaged, hl = "NvimTreeGitDirty" } },
|
||||
["T "] = { { icon = i.staged, hl = "NvimTreeGitStaged" } },
|
||||
["MM"] = {
|
||||
{ icon = i.staged, hl = "NvimTreeGitStaged" },
|
||||
{ icon = i.unstaged, hl = "NvimTreeGitDirty" },
|
||||
},
|
||||
["MD"] = {
|
||||
{ icon = i.staged, hl = "NvimTreeGitStaged" },
|
||||
},
|
||||
["A "] = {
|
||||
{ icon = i.staged, hl = "NvimTreeGitStaged" },
|
||||
},
|
||||
["AD"] = {
|
||||
{ icon = i.staged, hl = "NvimTreeGitStaged" },
|
||||
},
|
||||
[" A"] = {
|
||||
{ icon = i.untracked, hl = "NvimTreeGitNew" },
|
||||
},
|
||||
["M "] = { icons.staged },
|
||||
[" M"] = { icons.unstaged },
|
||||
["C "] = { icons.staged },
|
||||
[" C"] = { icons.unstaged },
|
||||
["CM"] = { icons.unstaged },
|
||||
[" T"] = { icons.unstaged },
|
||||
["T "] = { icons.staged },
|
||||
["MM"] = { icons.staged, icons.unstaged },
|
||||
["MD"] = { icons.staged },
|
||||
["A "] = { icons.staged },
|
||||
["AD"] = { icons.staged },
|
||||
[" A"] = { icons.untracked },
|
||||
-- not sure about this one
|
||||
["AA"] = {
|
||||
{ icon = i.unmerged, hl = "NvimTreeGitMerge" },
|
||||
{ icon = i.untracked, hl = "NvimTreeGitNew" },
|
||||
},
|
||||
["AU"] = {
|
||||
{ icon = i.unmerged, hl = "NvimTreeGitMerge" },
|
||||
{ icon = i.untracked, hl = "NvimTreeGitNew" },
|
||||
},
|
||||
["AM"] = {
|
||||
{ icon = i.staged, hl = "NvimTreeGitStaged" },
|
||||
{ icon = i.unstaged, hl = "NvimTreeGitDirty" },
|
||||
},
|
||||
["??"] = { { icon = i.untracked, hl = "NvimTreeGitNew" } },
|
||||
["R "] = { { icon = i.renamed, hl = "NvimTreeGitRenamed" } },
|
||||
[" R"] = { { icon = i.renamed, hl = "NvimTreeGitRenamed" } },
|
||||
["RM"] = {
|
||||
{ icon = i.unstaged, hl = "NvimTreeGitDirty" },
|
||||
{ icon = i.renamed, hl = "NvimTreeGitRenamed" },
|
||||
},
|
||||
["UU"] = { { icon = i.unmerged, hl = "NvimTreeGitMerge" } },
|
||||
["UD"] = { { icon = i.unmerged, hl = "NvimTreeGitMerge" } },
|
||||
["UA"] = { { icon = i.unmerged, hl = "NvimTreeGitMerge" } },
|
||||
[" D"] = { { icon = i.deleted, hl = "NvimTreeGitDeleted" } },
|
||||
["D "] = { { icon = i.deleted, hl = "NvimTreeGitDeleted" } },
|
||||
["RD"] = { { icon = i.deleted, hl = "NvimTreeGitDeleted" } },
|
||||
["DD"] = { { icon = i.deleted, hl = "NvimTreeGitDeleted" } },
|
||||
["DU"] = {
|
||||
{ icon = i.deleted, hl = "NvimTreeGitDeleted" },
|
||||
{ icon = i.unmerged, hl = "NvimTreeGitMerge" },
|
||||
},
|
||||
["!!"] = { { icon = i.ignored, hl = "NvimTreeGitIgnored" } },
|
||||
dirty = { { icon = i.unstaged, hl = "NvimTreeGitDirty" } },
|
||||
["AA"] = { icons.unmerged, icons.untracked },
|
||||
["AU"] = { icons.unmerged, icons.untracked },
|
||||
["AM"] = { icons.staged, icons.unstaged },
|
||||
["??"] = { icons.untracked },
|
||||
["R "] = { icons.renamed },
|
||||
[" R"] = { icons.renamed },
|
||||
["RM"] = { icons.unstaged, icons.renamed },
|
||||
["UU"] = { icons.unmerged },
|
||||
["UD"] = { icons.unmerged },
|
||||
["UA"] = { icons.unmerged },
|
||||
[" D"] = { icons.deleted },
|
||||
["D "] = { icons.deleted },
|
||||
["RD"] = { icons.deleted },
|
||||
["DD"] = { icons.deleted },
|
||||
["DU"] = { icons.deleted, icons.unmerged },
|
||||
["!!"] = { icons.ignored },
|
||||
dirty = { icons.unstaged },
|
||||
}
|
||||
end
|
||||
|
||||
@@ -77,20 +60,32 @@ local function warn_status(git_status)
|
||||
end
|
||||
|
||||
local function get_icons_(node)
|
||||
if not explorer_common.shows_git_status(node) then
|
||||
local git_status = explorer_node.get_git_status(node)
|
||||
if git_status == nil then
|
||||
return nil
|
||||
end
|
||||
|
||||
local git_status = node.git_status
|
||||
local icons = M.git_icons[git_status]
|
||||
if not icons then
|
||||
if not M.config.highlight_git then
|
||||
warn_status(git_status)
|
||||
local inserted = {}
|
||||
local iconss = {}
|
||||
|
||||
for _, s in pairs(git_status) do
|
||||
local icons = M.git_icons[s]
|
||||
if not icons then
|
||||
if not M.config.highlight_git then
|
||||
warn_status(s)
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
for _, icon in pairs(icons) do
|
||||
if not inserted[icon] then
|
||||
table.insert(iconss, icon)
|
||||
inserted[icon] = true
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
return icons
|
||||
return iconss
|
||||
end
|
||||
|
||||
local git_hl = {
|
||||
@@ -137,12 +132,12 @@ function M.setup_signs(i)
|
||||
end
|
||||
|
||||
local function get_highlight_(node)
|
||||
local git_status = node.git_status
|
||||
if not explorer_common.shows_git_status(node) then
|
||||
local git_status = explorer_node.get_git_status(node)
|
||||
if git_status == nil then
|
||||
return
|
||||
end
|
||||
|
||||
return git_hl[git_status]
|
||||
return git_hl[git_status[1]]
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
|
||||
Reference in New Issue
Block a user