diff --git a/lua/nvim-tree/explorer/watch.lua b/lua/nvim-tree/explorer/watch.lua index dad1738c4f5..cbebe3b144b 100644 --- a/lua/nvim-tree/explorer/watch.lua +++ b/lua/nvim-tree/explorer/watch.lua @@ -8,7 +8,17 @@ local M = { } local function is_git(path) - return vim.fn.fnamemodify(path, ":t") == ".git" + -- If $GIT_DIR is set, consider its value to be equivalent to '.git'. + -- Expand $GIT_DIR (and `path`) to a full path (see :help filename-modifiers), since + -- it's possible to set it to a relative path. We want to make our best + -- effort to expand that to a valid absolute path. + if vim.fn.fnamemodify(path, ":p") == vim.fn.fnamemodify(vim.env.GIT_DIR, ":p") then + return true + elseif vim.fn.fnamemodify(path, ":t") == ".git" then + return true + else + return false + end end local IGNORED_PATHS = { diff --git a/lua/nvim-tree/git/init.lua b/lua/nvim-tree/git/init.lua index 2714e39ee57..4a7277798b5 100644 --- a/lua/nvim-tree/git/init.lua +++ b/lua/nvim-tree/git/init.lua @@ -186,7 +186,8 @@ function M.load_project_status(cwd) end) end - watcher = Watcher:new(utils.path_join { project_root, ".git" }, WATCHED_FILES, callback, { + local git_dir = vim.env.GIT_DIR or utils.path_join { project_root, ".git" } + watcher = Watcher:new(git_dir, WATCHED_FILES, callback, { project_root = project_root, }) end