* 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
|
end
|
||||||
|
|
||||||
M.uid = M.uid + 1
|
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,
|
context = "explorer:watch:" .. absolute_path .. ":" .. M.uid,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|||||||
@ -11,6 +11,16 @@ local M = {
|
|||||||
cwd_to_project_root = {},
|
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()
|
function M.reload()
|
||||||
if not M.config.git.enable then
|
if not M.config.git.enable then
|
||||||
return {}
|
return {}
|
||||||
@ -149,7 +159,7 @@ function M.load_project_status(cwd)
|
|||||||
end)
|
end)
|
||||||
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,
|
project_root = project_root,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|||||||
@ -58,7 +58,7 @@ function Event:start()
|
|||||||
else
|
else
|
||||||
log.line("watcher", "event_cb '%s' '%s'", self._path, filename)
|
log.line("watcher", "event_cb '%s' '%s'", self._path, filename)
|
||||||
for _, listener in ipairs(self._listeners) do
|
for _, listener in ipairs(self._listeners) do
|
||||||
listener()
|
listener(filename)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
@ -101,14 +101,15 @@ function Event:destroy(message)
|
|||||||
Event._events[self._path] = nil
|
Event._events[self._path] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function Watcher:new(path, callback, data)
|
function Watcher:new(path, files, callback, data)
|
||||||
log.line("watcher", "Watcher:new '%s'", path)
|
log.line("watcher", "Watcher:new '%s' %s", path, vim.inspect(files))
|
||||||
|
|
||||||
local w = setmetatable(data, Watcher)
|
local w = setmetatable(data, Watcher)
|
||||||
|
|
||||||
w._event = Event._events[path] or Event:new(path)
|
w._event = Event._events[path] or Event:new(path)
|
||||||
w._listener = nil
|
w._listener = nil
|
||||||
w._path = path
|
w._path = path
|
||||||
|
w._files = files
|
||||||
w._callback = callback
|
w._callback = callback
|
||||||
|
|
||||||
if not w._event then
|
if not w._event then
|
||||||
@ -123,8 +124,10 @@ function Watcher:new(path, callback, data)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Watcher:start()
|
function Watcher:start()
|
||||||
self._listener = function()
|
self._listener = function(filename)
|
||||||
self._callback(self)
|
if not self._files or vim.tbl_contains(self._files, filename) then
|
||||||
|
self._callback(self)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self._event:add(self._listener)
|
self._event:add(self._listener)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user