Skip to content

Commit 8c117bf

Browse files
authored
chore(git): get_project_root cache cwd_to_project_root after checking existence (nvim-tree#1457)
1 parent 0f2c9a3 commit 8c117bf

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lua/nvim-tree/git/init.lua

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
local uv = vim.loop
2+
13
local log = require "nvim-tree.log"
24
local utils = require "nvim-tree.utils"
35
local git_utils = require "nvim-tree.git.utils"
@@ -60,6 +62,10 @@ function M.get_project(project_root)
6062
end
6163

6264
function M.get_project_root(cwd)
65+
if not M.config.git.enable then
66+
return nil
67+
end
68+
6369
if M.cwd_to_project_root[cwd] then
6470
return M.cwd_to_project_root[cwd]
6571
end
@@ -68,11 +74,13 @@ function M.get_project_root(cwd)
6874
return nil
6975
end
7076

71-
if M.config.git.enable then
72-
return git_utils.get_toplevel(cwd)
77+
local stat, _ = uv.fs_stat(cwd)
78+
if not stat or stat.type ~= "directory" then
79+
return nil
7380
end
7481

75-
return nil
82+
M.cwd_to_project_root[cwd] = git_utils.get_toplevel(cwd)
83+
return M.cwd_to_project_root[cwd]
7684
end
7785

7886
local function reload_tree_at(project_root)

0 commit comments

Comments
 (0)