feat/chore: rewrite git with job and some other fixes (#743)
* feat/chore: rewrite git with job and some other fixes * fix: fs clear window, rename echo_warning -> warn also fix renaming and add an event blocker to avoid running many events at the same time
This commit is contained in:
54
lua/nvim-tree/git/utils.lua
Normal file
54
lua/nvim-tree/git/utils.lua
Normal file
@@ -0,0 +1,54 @@
|
||||
local M = {}
|
||||
|
||||
function M.get_toplevel(cwd)
|
||||
local cmd = "git -C " .. vim.fn.shellescape(cwd) .. " rev-parse --show-toplevel"
|
||||
local toplevel = vim.fn.system(cmd)
|
||||
|
||||
if not toplevel or #toplevel == 0 or toplevel:match('fatal') then
|
||||
return nil
|
||||
end
|
||||
|
||||
-- git always returns path with forward slashes
|
||||
if vim.fn.has('win32') == 1 then
|
||||
toplevel = toplevel:gsub("/", "\\")
|
||||
end
|
||||
|
||||
-- remove newline
|
||||
return toplevel:sub(0, -2)
|
||||
end
|
||||
|
||||
local untracked = {}
|
||||
|
||||
function M.should_show_untracked(cwd)
|
||||
if untracked[cwd] ~= nil then
|
||||
return untracked[cwd]
|
||||
end
|
||||
|
||||
local cmd = "git -C "..cwd.." config --type=bool status.showUntrackedFiles"
|
||||
local has_untracked = vim.fn.system(cmd)
|
||||
untracked[cwd] = vim.trim(has_untracked) ~= 'false'
|
||||
return untracked[cwd]
|
||||
end
|
||||
|
||||
function M.file_status_to_dir_status(status, cwd)
|
||||
local dirs = {}
|
||||
for p, s in pairs(status) do
|
||||
if s ~= '!!' then
|
||||
local modified = vim.fn.fnamemodify(p, ':h')
|
||||
dirs[modified] = 'dirty'
|
||||
end
|
||||
end
|
||||
|
||||
for dirname, _ in pairs(dirs) do
|
||||
local modified = dirname
|
||||
while modified ~= cwd and modified ~= '/' do
|
||||
modified = vim.fn.fnamemodify(modified, ':h')
|
||||
dirs[modified] = 'dirty'
|
||||
end
|
||||
end
|
||||
|
||||
return dirs
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user