Open cseickel opened 1 year ago
I think this problem only applies if your root is higher up the tree than the repo of the file you are working with. If the root of neo-tree is the same as the repo, this works as expected.
Can you confirm that this is the case for you as well?
It should still work regardless of what your root is, I just want to confirm we are talking about the same problem.
Hmm no, I open nvim /a/b/c and the git root is at /a/b/c/.git, and that doesn't work
Actually that's a problem too..
Doesn't seem to work for me even with async disabled.
require("neo-tree").setup({
git_status_async = false,
filesystem = {
use_libuv_file_watcher = true,
},
})
I'm using Neogit so I suppose I could try working around it with the events it publishes.
Same problem here, I generally use Fugitive to commit stuff, and it's really annoying that the colors in neo-tree are always out of date. I have to force refresh with R
to fix it.
I just updated from 2.x to 3.x and it made no difference.
My workaround:
local refresh_neotree_aug = vim.api.nvim_create_augroup("RefreshNeoTree", { clear = true })
local refresh_neotree_git_status = function()
pcall(function()
require("neo-tree.sources.git_status").refresh()
end)
end
vim.api.nvim_create_autocmd("User", {
group = refresh_neotree_aug,
pattern = "FugitiveChanged",
callback = refresh_neotree_git_status,
})
vim.api.nvim_create_autocmd("TabEnter", {
group = refresh_neotree_aug,
callback = refresh_neotree_git_status,
})
This refreshes git_status in Neotree any time Fugitive does anything. Unfortunately, the call to .refresh()
only applies to any Neotree instance on the current tab, so I also call it any time I switch tabs. Otherwise it doesn't refresh when I work with Fugitive in a separate tab.
@Hubro the git_status
source of neo-tree is already subscribing to that Fugitive event and refreshing on its own. If you are using Fugitive to commit, it should work without you having to do anything.
This is really a separate issue and you should open a new issue with a minimal init script and instructions on how to recreate your issue.
This issue is specifically for the filesystem
source and NOT for when using Fugitive, which AFAIK works perfectly for the git_status
source. The only situation where the Fugitive event is not handled for the filesystem
source is if you have an older style before_render
event handler in your filesystem
config.
@cseickel You're right, the git_status source actually updates fine when I'm running Fugitive commands in the same tab as neo-tree, so I don't actually need the FugitiveChanged
autocommand.
The problem seems to be that I always run Fugitive in its own tab (:tab G
), so any FugitiveChanged
events that happens are ignored by neo-tree, since the refresh function only applies to neo-tree instances in the current tab. Refreshing on TabEnter
fixes that.
the refresh function only applies to neo-tree instances in the current tab
Ah yes, there's the problem. That's a tricky one because some people would want all trees in other tabs to refresh and some won't. The best thing to do might be to refresh all trees whose root is equal to or a parent of the git repo that was changed.
I encountered this issue too with Neogit. Here's my working config that checks the tab page, and refreshes neo-tree after committing with Neogit:
config = function(_, opts)
-- Update status on a *Neogit* file update event
local is_git_file_event = false
local prev_filetype = ''
vim.api.nvim_create_autocmd('User', {
pattern = {
'NeogitCommitComplete',
'NeogitPullComplete',
'NeogitBranchCheckout',
'NeogitBranchReset',
'NeogitRebase',
'NeogitReset',
'NeogitCherryPick',
'NeogitMerge',
},
callback = function() is_git_file_event = true end,
})
vim.api.nvim_create_autocmd('TabLeave', {
callback = function() prev_filetype = vim.api.nvim_get_option_value('filetype', {}) end,
})
vim.api.nvim_create_autocmd('TabEnter', {
callback = function()
if vim.startswith(prev_filetype, 'Neogit') and is_git_file_event then
require('neo-tree.events').fire_event('git_event')
is_git_file_event = false
end
end,
})
require('neo-tree').setup(opts)
end,
That does not seem to work for me. I've put the log level to trace and I can see the git watcher has started, but after that, nothing happens when I commit my files from a terminal.
Originally posted by @primalmotion in https://github.com/nvim-neo-tree/neo-tree.nvim/issues/337#issuecomment-1411257704
https://github.com/nvim-neo-tree/neo-tree.nvim/issues/337#issuecomment-1412501982