@@ -2,6 +2,7 @@ local log = require "nvim-tree.log"
22local  utils  =  require  " nvim-tree.utils" 
33local  git_utils  =  require  " nvim-tree.git.utils" 
44local  Runner  =  require  " nvim-tree.git.runner" 
5+ local  Watch  =  require  " nvim-tree.explorer.watch" 
56local  Watcher  =  require (" nvim-tree.watcher"  ).Watcher 
67local  Iterator  =  require  " nvim-tree.iterators.node-iterator" 
78local  explorer_node  =  require  " nvim-tree.explorer.node" 
@@ -164,22 +165,34 @@ function M.load_project_status(cwd)
164165  }
165166
166167  local  watcher  =  nil 
168+ 
167169  if  M .config .filesystem_watchers .enable  then 
168170    log .line (" watcher"  , " git start"  )
169171
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 )
179191
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 
183196  end 
184197
185198  M .projects [project_root ] =  {
0 commit comments