* fix(#1720): .git watch only HEAD, config and index * fix(#1720): .git watch only FETCH_HEAD, HEAD, HEAD.lock, config, index
This commit is contained in:
parent
7e892767bd
commit
bcb2a5a80d
@ -77,7 +77,7 @@ function M.create_watcher(absolute_path)
|
||||
end
|
||||
|
||||
M.uid = M.uid + 1
|
||||
return Watcher:new(absolute_path, callback, {
|
||||
return Watcher:new(absolute_path, nil, callback, {
|
||||
context = "explorer:watch:" .. absolute_path .. ":" .. M.uid,
|
||||
})
|
||||
end
|
||||
|
||||
@ -11,6 +11,16 @@ local M = {
|
||||
cwd_to_project_root = {},
|
||||
}
|
||||
|
||||
-- Files under .git that should result in a reload when changed.
|
||||
-- Utilities (like watchman) can also write to this directory (often) and aren't useful for us.
|
||||
local WATCHED_FILES = {
|
||||
"FETCH_HEAD", -- remote ref
|
||||
"HEAD", -- local ref
|
||||
"HEAD.lock", -- HEAD will not always be updated e.g. revert
|
||||
"config", -- user config
|
||||
"index", -- staging area
|
||||
}
|
||||
|
||||
function M.reload()
|
||||
if not M.config.git.enable then
|
||||
return {}
|
||||
@ -149,7 +159,7 @@ function M.load_project_status(cwd)
|
||||
end)
|
||||
end
|
||||
|
||||
watcher = Watcher:new(utils.path_join { project_root, ".git" }, callback, {
|
||||
watcher = Watcher:new(utils.path_join { project_root, ".git" }, WATCHED_FILES, callback, {
|
||||
project_root = project_root,
|
||||
})
|
||||
end
|
||||
|
||||
@ -58,7 +58,7 @@ function Event:start()
|
||||
else
|
||||
log.line("watcher", "event_cb '%s' '%s'", self._path, filename)
|
||||
for _, listener in ipairs(self._listeners) do
|
||||
listener()
|
||||
listener(filename)
|
||||
end
|
||||
end
|
||||
end)
|
||||
@ -101,14 +101,15 @@ function Event:destroy(message)
|
||||
Event._events[self._path] = nil
|
||||
end
|
||||
|
||||
function Watcher:new(path, callback, data)
|
||||
log.line("watcher", "Watcher:new '%s'", path)
|
||||
function Watcher:new(path, files, callback, data)
|
||||
log.line("watcher", "Watcher:new '%s' %s", path, vim.inspect(files))
|
||||
|
||||
local w = setmetatable(data, Watcher)
|
||||
|
||||
w._event = Event._events[path] or Event:new(path)
|
||||
w._listener = nil
|
||||
w._path = path
|
||||
w._files = files
|
||||
w._callback = callback
|
||||
|
||||
if not w._event then
|
||||
@ -123,8 +124,10 @@ function Watcher:new(path, callback, data)
|
||||
end
|
||||
|
||||
function Watcher:start()
|
||||
self._listener = function()
|
||||
self._callback(self)
|
||||
self._listener = function(filename)
|
||||
if not self._files or vim.tbl_contains(self._files, filename) then
|
||||
self._callback(self)
|
||||
end
|
||||
end
|
||||
|
||||
self._event:add(self._listener)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user