chore(git): get_project_root cache cwd_to_project_root after checking existence (#1457)
This commit is contained in:
committed by
GitHub
parent
e7832785d2
commit
86b9da5ca5
@@ -1,3 +1,5 @@
|
|||||||
|
local uv = vim.loop
|
||||||
|
|
||||||
local log = require "nvim-tree.log"
|
local log = require "nvim-tree.log"
|
||||||
local utils = require "nvim-tree.utils"
|
local utils = require "nvim-tree.utils"
|
||||||
local git_utils = require "nvim-tree.git.utils"
|
local git_utils = require "nvim-tree.git.utils"
|
||||||
@@ -60,6 +62,10 @@ function M.get_project(project_root)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.get_project_root(cwd)
|
function M.get_project_root(cwd)
|
||||||
|
if not M.config.git.enable then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
if M.cwd_to_project_root[cwd] then
|
if M.cwd_to_project_root[cwd] then
|
||||||
return M.cwd_to_project_root[cwd]
|
return M.cwd_to_project_root[cwd]
|
||||||
end
|
end
|
||||||
@@ -68,11 +74,13 @@ function M.get_project_root(cwd)
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
if M.config.git.enable then
|
local stat, _ = uv.fs_stat(cwd)
|
||||||
return git_utils.get_toplevel(cwd)
|
if not stat or stat.type ~= "directory" then
|
||||||
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
return nil
|
M.cwd_to_project_root[cwd] = git_utils.get_toplevel(cwd)
|
||||||
|
return M.cwd_to_project_root[cwd]
|
||||||
end
|
end
|
||||||
|
|
||||||
local function reload_tree_at(project_root)
|
local function reload_tree_at(project_root)
|
||||||
|
|||||||
Reference in New Issue
Block a user