@@ -2,6 +2,7 @@ local log = require "nvim-tree.log"
2
2
local utils = require " nvim-tree.utils"
3
3
local git_utils = require " nvim-tree.git.utils"
4
4
local Runner = require " nvim-tree.git.runner"
5
+ local Watch = require " nvim-tree.explorer.watch"
5
6
local Watcher = require (" nvim-tree.watcher" ).Watcher
6
7
local Iterator = require " nvim-tree.iterators.node-iterator"
7
8
local explorer_node = require " nvim-tree.explorer.node"
@@ -164,22 +165,34 @@ function M.load_project_status(cwd)
164
165
}
165
166
166
167
local watcher = nil
168
+
167
169
if M .config .filesystem_watchers .enable then
168
170
log .line (" watcher" , " git start" )
169
171
170
- local callback = function (w )
171
- log .line (" watcher" , " git event scheduled '%s'" , w .project_root )
172
- utils .debounce (" git:watcher:" .. w .project_root , M .config .filesystem_watchers .debounce_delay , function ()
173
- if w .destroyed then
174
- return
175
- end
176
- reload_tree_at (w .project_root )
177
- end )
178
- end
172
+ local git_directory = git_utils .get_git_directory (project_root )
173
+
174
+ if git_directory == nil then
175
+ log .line (" watcher" , " could not found the location of .git folder" )
176
+ else
177
+ local callback = function (w )
178
+ log .line (" watcher" , " git event scheduled '%s'" , w .project_root )
179
+ utils .debounce (" git:watcher:" .. w .project_root , M .config .filesystem_watchers .debounce_delay , function ()
180
+ if w .destroyed then
181
+ return
182
+ end
183
+ reload_tree_at (w .project_root )
184
+ end )
185
+ end
186
+
187
+ -- Add GIT_DIR to the list of directory to ignore
188
+ -- local base_gitdir = utils.path_basename(git_directory)
189
+ -- Watch.ignore_dir(base_gitdir)
190
+ Watch .ignore_dir (git_directory )
179
191
180
- watcher = Watcher :new (utils .path_join { project_root , " .git" }, WATCHED_FILES , callback , {
181
- project_root = project_root ,
182
- })
192
+ watcher = Watcher :new (git_directory , WATCHED_FILES , callback , {
193
+ project_root = project_root ,
194
+ })
195
+ end
183
196
end
184
197
185
198
M .projects [project_root ] = {
0 commit comments