chore(git): get_project_root cache cwd_to_project_root after checking existence (#1457)

This commit is contained in:
Alexander Courtis 2022-07-25 19:27:12 +10:00 committed by GitHub
parent e7832785d2
commit 86b9da5ca5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,3 +1,5 @@
local uv = vim.loop
local log = require "nvim-tree.log"
local utils = require "nvim-tree.utils"
local git_utils = require "nvim-tree.git.utils"
@ -60,6 +62,10 @@ function M.get_project(project_root)
end
function M.get_project_root(cwd)
if not M.config.git.enable then
return nil
end
if M.cwd_to_project_root[cwd] then
return M.cwd_to_project_root[cwd]
end
@ -68,11 +74,13 @@ function M.get_project_root(cwd)
return nil
end
if M.config.git.enable then
return git_utils.get_toplevel(cwd)
local stat, _ = uv.fs_stat(cwd)
if not stat or stat.type ~= "directory" then
return nil
end
return nil
M.cwd_to_project_root[cwd] = git_utils.get_toplevel(cwd)
return M.cwd_to_project_root[cwd]
end
local function reload_tree_at(project_root)