Files
nvim-tree.lua/lua/nvim-tree/git/init.lua
kiyan f977e5c05a refacto: make git module interface to wait for job to finish
allows simplify the explore/reload/find/initialization by making the
whole code synchronous. No more callback needed.
2022-02-21 19:12:16 +01:00

79 lines
1.6 KiB
Lua

local git_utils = require'nvim-tree.git.utils'
local Runner = require'nvim-tree.git.runner'
local M = {
config = nil,
projects = {},
cwd_to_project_root = {}
}
function M.reload()
if not M.config.enable then
return {}
end
for project_root in pairs(M.projects) do
M.projects[project_root] = {}
local git_status = Runner.run {
project_root = project_root,
list_untracked = git_utils.should_show_untracked(project_root),
list_ignored = true,
timeout = M.config.timeout,
}
M.projects[project_root] = {
files = git_status,
dirs = git_utils.file_status_to_dir_status(git_status, project_root)
}
end
return M.projects
end
function M.get_project_root(cwd)
if M.cwd_to_project_root[cwd] then
return M.cwd_to_project_root[cwd]
end
if M.cwd_to_project_root[cwd] == false then
return nil
end
local project_root = git_utils.get_toplevel(cwd)
return project_root
end
function M.load_project_status(cwd)
if not M.config.enable then
return {}
end
local project_root = M.get_project_root(cwd)
if not project_root then
M.cwd_to_project_root[cwd] = false
return {}
end
local status = M.projects[project_root]
if status then
return status
end
local git_status = Runner.run {
project_root = project_root,
list_untracked = git_utils.should_show_untracked(project_root),
list_ignored = true,
timeout = M.config.timeout
}
M.projects[project_root] = {
files = git_status,
dirs = git_utils.file_status_to_dir_status(git_status, project_root)
}
return M.projects[project_root]
end
function M.setup(opts)
M.config = opts.git
end
return M