Skip to content

Commit aae35cc

Browse files
committed
WIP
1 parent f466ab0 commit aae35cc

File tree

5 files changed

+51
-21
lines changed

5 files changed

+51
-21
lines changed

lua/neo-tree/sources/filesystem/init.lua

+1-15
Original file line numberDiff line numberDiff line change
@@ -285,23 +285,9 @@ M.setup = function(config, global_config)
285285
if config.follow_current_file then
286286
manager.subscribe(M.name, {
287287
event = events.VIM_BUFFER_ENTER,
288-
handler = wrap(manager.follow),
288+
handler = M.follow,
289289
})
290290
end
291-
292-
--Dispose ourselves if the tab closes
293-
manager.subscribe(M.name, {
294-
event = events.VIM_TAB_CLOSED,
295-
handler = function(args)
296-
local tabnr = tonumber(args.afile)
297-
if tabnr then
298-
log.debug("VIM_TAB_CLOSED: disposing state for tab", tabnr)
299-
manager.dispose(M.name, tabnr)
300-
else
301-
log.error("VIM_TAB_CLOSED: no tab number found in args.afile")
302-
end
303-
end,
304-
})
305291
end
306292

307293
---Expands or collapses the current node.

lua/neo-tree/sources/git_status/commands.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ M.open = cc.open
122122
M.open_split = cc.open_split
123123
M.open_vsplit = cc.open_vsplit
124124

125-
M.refresh = gs.refresh
125+
M.refresh = refresh
126126

127127
M.rename = function(state)
128128
cc.rename(state, refresh)

lua/neo-tree/sources/git_status/init.lua

+12-3
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ end
2222
---@param path string Path to navigate to. If empty, will navigate to the cwd.
2323
M.navigate = function(path)
2424
local state = get_state()
25+
state.path = path or vim.fn.getcwd()
2526
state.dirty = false
2627
items.get_git_status(state)
28+
manager.watch_git_project(M.name, state.path)
2729
end
2830

2931
---Configures the plugin, should be called before the plugin is used.
@@ -44,14 +46,21 @@ M.setup = function(config, global_config)
4446
end
4547

4648
manager.subscribe(M.name, {
47-
event = events.VIM_BUFFER_CHANGED,
48-
handler = wrap(manager.refresh),
49+
event = events.FS_EVENT,
50+
handler = function(args)
51+
local state = get_state()
52+
if args.path == state.git_folder then
53+
M.navigate()
54+
else
55+
log.debug("Ignoring fs event for " .. args.path)
56+
end
57+
end,
4958
})
5059

5160
if config.bind_to_cwd then
5261
manager.subscribe(M.name, {
5362
event = events.VIM_DIR_CHANGED,
54-
handler = wrap(manager.refresh),
63+
handler = wrap(manager.dir_changed),
5564
})
5665
end
5766

lua/neo-tree/sources/manager.lua

+31
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ local renderer = require("neo-tree.ui.renderer")
88
local inputs = require("neo-tree.ui.inputs")
99
local events = require("neo-tree.events")
1010
local log = require("neo-tree.log")
11+
local fs_watch = require("neo-tree.sources.filesystem.lib.fs_watch")
1112

1213
local M = {}
1314
local source_data = {}
@@ -324,4 +325,34 @@ M.show = function(source_name)
324325
end
325326
end
326327

328+
local known_dot_git_folders = {}
329+
M.watch_git_project = function (source_name, path)
330+
local state = M.get_state(source_name)
331+
local root = utils.get_git_project_root(path)
332+
if not utils.truthy(root) then
333+
return
334+
end
335+
dot_git = root .. utils.path_separator .. ".git"
336+
if dot_git ~= state.git_folder then
337+
log.debug("Watching .git folder: ", dot_git)
338+
if utils.truthy(state.git_folder) then
339+
fs_watch.unwatch_folder(state.git_folder)
340+
end
341+
fs_watch.watch_folder(dot_git)
342+
state.git_folder = dot_git
343+
if #known_dot_git_folders == 0 then
344+
events.subscribe({
345+
event = events.FS_EVENT,
346+
handler = function(args)
347+
local is_git_root = known_dot_git_folders[args.path]
348+
if is_git_root then
349+
events.fire_event(events.GIT_EVENT, args)
350+
end
351+
end,
352+
})
353+
end
354+
known_dot_git_folders[dot_git] = true
355+
end
356+
end
357+
327358
return M

lua/neo-tree/utils.lua

+6-2
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,12 @@ M.get_diagnostic_counts = function()
168168
return lookup
169169
end
170170

171-
M.get_git_project_root = function()
172-
return vim.fn.systemlist("git rev-parse --show-toplevel")[1]
171+
M.get_git_project_root = function(path)
172+
local cmd = "git rev-parse --show-toplevel"
173+
if M.truthy(path) then
174+
cmd = 'cd ' .. vim.fn.shellescape(path) .. " && " .. cmd
175+
end
176+
return vim.fn.systemlist(cmd)[1]
173177
end
174178

175179
---Parse "git status" output for the current working directory.

0 commit comments

Comments
 (0)