lewis6991 / gitsigns.nvim

Git integration for buffers
MIT License
4.91k stars 187 forks source link

After discarding changes outside of neovim Gitsigns are updated only in one buffer #1028

Closed metziger23 closed 2 months ago

metziger23 commented 3 months ago

Description

I often discard changes using lazygit from toggleterm. I use neovim with window splits, so I have one buffer open in one window and the second buffer in the second window. If I discard all the changes using lazygit from toggleterm then gitsings are updated only in one window (in the second window gitsigns remain not updated). As a workaround I added autocommand to run "Gitsigns refresh" on such events as TermClose, TermLeave (the commented chunk of code in the minimal config) and it works. However, if I do so then all the visible gitsings flicker every time TermClose or TermLeave are triggered. I would like gitsigns not to flicker in this case. When I looked at the code of gitsings I found the comment " -- Don't use refresh() to avoid flicker" in actions.lua line 117 so I suppose that it's possible to update gitsigns without flickering somehow.

Neovim version

NVIM v0.10.0

Operating system and version

Macos 14.4.1 (23E224) but I also reproduced this issue on Fedora 40 and Kubuntu 23.10

Expected behavior

Gitsigns are updated in the first window for the first file and in the second window for the second file

Actual behavior

Gitsigns are only updated for one of the files. For the second file (that is in the second window) the gitsings are not updated. In order to update them, I have to reload the file (:e) or use ":Gitsigns refresh".

Minimal config

for name, url in pairs{
  gitsigns = 'https://github.com/lewis6991/gitsigns.nvim',
  -- ADD OTHER PLUGINS _NECESSARY_ TO REPRODUCE THE ISSUE
  toggleterm = 'https://github.com/akinsho/toggleterm.nvim',
} do
  local install_path = vim.fn.fnamemodify('gitsigns_issue/'..name, ':p')
  if vim.fn.isdirectory(install_path) == 0 then
    vim.fn.system { 'git', 'clone', '--depth=1', url, install_path }
  end
  vim.opt.runtimepath:append(install_path)
end

require('gitsigns').setup{
  debug_mode = true, -- You must add this to enable debug messages
  -- ADD GITSIGNS CONFIG THAT IS _NECESSARY_ FOR REPRODUCING THE ISSUE
  on_attach = function(buffer)
    local gitsigns = require("gitsigns")
    -- my workaround to update gitsigns signcolumn after deleting hunks with lazygit invoked from toggleterm
    -- vim.api.nvim_create_autocmd({ "TermClose", "TermLeave" }, {
    --  callback = function()
    --      gitsigns.refresh()
    --  end,
    -- })
  end,
}

require('toggleterm').setup({})
local Terminal = require("toggleterm.terminal").Terminal

local lazygit = Terminal:new({
  cmd = "lazygit",
  dir = "git_dir",
  direction = "float",
})

vim.keymap.set({ "n", "t", "x" }, "<A-g>", function()
  lazygit:toggle()
  end, { desc = "toggleterm: toggle lazygit" })

-- ADD INIT.LUA SETTINGS THAT IS _NECESSARY_ FOR REPRODUCING THE ISSUE

-- this is used to "update" buffers after modifying them with lazygit invoked from toggleterm
vim.api.nvim_create_autocmd({ "TermClose", "TermLeave" }, { command = "checktime" })

Steps to reproduce

  1. nvim --clean -u minimal.lua
  2. Open a git-tracked file.
  3. Split window vertically (ctrl+w v)
  4. In second window open another git-tracked file.
  5. Add any change to the first file in the first window and any change to the second file in the second window.
  6. Save all the changes (:wa)
  7. Open lazygit from toggleterm (Alt+g if you're using the attached config) (floaterm or kdheepak/lazygit.nvim can be used as well)
  8. Using lazygit discard all the changes. (Files panes, press "d" to discard changes and confirm pressing "return/enter" when lazygit asks "Discard all changes"). The changes should be discarded for both files.
  9. Return from lazygit to neovim. (Press "q" to quit lazygit and the floating window will close automatically or press alt+g (if you're using the attached config) to toggle the floating window.)

Gitsigns debug messages

:Gitsigns debug_messages                                                                                                                                                                                                                
dprintf: Deriving GitSignsAdd from Added                                                                                                                                                                                                
dprintf: Deriving GitSignsChange from Changed                                                                                                                                                                                           
dprintf: Deriving GitSignsDelete from Removed                                                                                                                                                                                           
dprintf: Deriving GitSignsChangedelete from GitSignsChange                                                                                                                                                                              
dprintf: Deriving GitSignsTopdelete from GitSignsDelete                                                                                                                                                                                 
dprintf: Deriving GitSignsUntracked from GitSignsAdd                                                                                                                                                                                    
dprintf: Deriving GitSignsAddNr from GitSignsAdd                                                                                                                                                                                        
dprintf: Deriving GitSignsChangeNr from GitSignsChange                                                                                                                                                                                  
dprintf: Deriving GitSignsDeleteNr from GitSignsDelete                                                                                                                                                                                  
dprintf: Deriving GitSignsChangedeleteNr from GitSignsChangeNr                                                                                                                                                                          
dprintf: Deriving GitSignsTopdeleteNr from GitSignsDeleteNr                                                                                                                                                                             
dprintf: Deriving GitSignsUntrackedNr from GitSignsAddNr                                                                                                                                                                                
dprintf: Deriving GitSignsAddLn from DiffAdd                                                                                                                                                                                            
dprintf: Deriving GitSignsChangeLn from DiffChange                                                                                                                                                                                      
dprintf: Deriving GitSignsChangedeleteLn from GitSignsChangeLn                                                                                                                                                                          
dprintf: Deriving GitSignsUntrackedLn from GitSignsAddLn                                                                                                                                                                                
dprintf: Deriving GitSignsStagedAdd from GitSignsAdd                                                                                                                                                                                    
dprintf: Deriving GitSignsStagedChange from GitSignsChange                                                                                                                                                                              
dprintf: Deriving GitSignsStagedDelete from GitSignsDelete                                                                                                                                                                              
dprintf: Deriving GitSignsStagedChangedelete from GitSignsChangedelete                                                                                                                                                                  
dprintf: Deriving GitSignsStagedTopdelete from GitSignsTopdelete                                                                                                                                                                        
dprintf: Deriving GitSignsStagedAddNr from GitSignsAddNr                                                                                                                                                                                
dprintf: Deriving GitSignsStagedChangeNr from GitSignsChangeNr                                                                                                                                                                          
dprintf: Deriving GitSignsStagedDeleteNr from GitSignsDeleteNr                                                                                                                                                                          
dprintf: Deriving GitSignsStagedChangedeleteNr from GitSignsChangedeleteNr                                                                                                                                                              
dprintf: Deriving GitSignsStagedTopdeleteNr from GitSignsTopdeleteNr                                                                                                                                                                    
dprintf: Deriving GitSignsStagedAddLn from GitSignsAddLn                                                                                                                                                                                
dprintf: Deriving GitSignsStagedChangeLn from GitSignsChangeLn                                                                                                                                                                          
dprintf: Could not derive GitSignsStagedDeleteLn                                                                                                                                                                                        
dprintf: Deriving GitSignsStagedChangedeleteLn from GitSignsChangedeleteLn                                                                                                                                                              
dprintf: Could not derive GitSignsStagedTopdeleteLn                                                                                                                                                                                     
dprintf: Deriving GitSignsAddPreview from DiffAdd                                                                                                                                                                                       
dprintf: Deriving GitSignsDeletePreview from DiffDelete                                                                                                                                                                                 
dprintf: Deriving GitSignsCurrentLineBlame from NonText                                                                                                                                                                                 
dprintf: Deriving GitSignsAddInline from TermCursor                                                                                                                                                                                     
dprintf: Deriving GitSignsDeleteInline from TermCursor                                                                                                                                                                                  
dprintf: Deriving GitSignsChangeInline from TermCursor                                                                                                                                                                                  
dprintf: Deriving GitSignsAddLnInline from GitSignsAddInline                                                                                                                                                                            
dprintf: Deriving GitSignsChangeLnInline from GitSignsChangeInline                                                                                                                                                                      
dprintf: Deriving GitSignsDeleteLnInline from GitSignsDeleteInline                                                                                                                                                                      
dprintf: Deriving GitSignsDeleteVirtLn from DiffDelete                                                                                                                                                                                  
dprintf: Deriving GitSignsDeleteVirtLnInLine from GitSignsDeleteLnInline                                                                                                                                                                
dprintf: Deriving GitSignsVirtLnum from GitSignsDeleteVirtLn                                                                                                                                                                            
attach(1): Attaching (trigger=BufReadPost)                                                                                                                                                                                              
run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 config user.name                                                                                                                                           
run_job: git --version                                                                                                                                                                                                                  
run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 rev-parse --show-toplevel --absolute-git-dir --abbrev-ref HEAD                                                                                             
run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 rev-parse --short HEAD                                                                                                                                     
run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir /Volumes/k/Misc/gitsigns-bug-report/git-tracked-dir/.git -c core.quotepath=off ls-files --stage --others --exclude-standard --eol /Volumes/k/Misc
/gitsigns-bug-report/git-tracked-dir/testFile1.txt                                                                                                                                                                                      
watch_gitdir(1): Watching git dir                                                                                                                                                                                                       
run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir /Volumes/k/Misc/gitsigns-bug-report/git-tracked-dir/.git show bfebabf6bfbf2e6072b50b30a1dab801f1157777                                           
detach(3): Detached                                                                                                                                                                                                                     
detach(3): Cache was nil                                                                                                                                                                                                                
attach(3): Attaching (trigger=BufFilePost)                                                                                                                                                                                              
run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 config user.name                                                                                                                                           
run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 rev-parse --show-toplevel --absolute-git-dir --abbrev-ref HEAD                                                                                             
new: Not in git repo                                                                                                                                                                                                                    
attach(3): Empty git obj                                                                                                                                                                                                                
attach(2): Attaching (trigger=BufReadPost)                                                                                                                                                                                              
run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 config user.name                                                                                                                                           
run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 rev-parse --show-toplevel --absolute-git-dir --abbrev-ref HEAD                                                                                             
run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 rev-parse --short HEAD                                                                                                                                     
run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir /Volumes/k/Misc/gitsigns-bug-report/git-tracked-dir/.git -c core.quotepath=off ls-files --stage --others --exclude-standard --eol /Volumes/k/Misc
/gitsigns-bug-report/git-tracked-dir/testFile2.txt                                                                                                                                                                                      
watch_gitdir(2): Watching git dir                                                                                                                                                                                                       
run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir /Volumes/k/Misc/gitsigns-bug-report/git-tracked-dir/.git show d61e4068d31be1aaefd3f8a241d0ee913f64c197                                           
attach(1): Already attached                                                                                                                                                                                                             
attach(2): Already attached                                                                                                                                                                                                             
detach(4): Detached                                                                                                                                                                                                                     
detach(4): Cache was nil                                                                                                                                                                                                                
attach(4): Attaching (trigger=BufFilePost)                                                                                                                                                                                              
attach(4): Not a path                                                                                                                                                                                                                   
watcher_cb(1): Git dir update: 'index.lock' { rename = true } (ignoring)                                                                                                                                                                
watcher_cb(1): Git dir update: 'index' { rename = true }                                                                                                                                                                                
watcher_cb(1): Git dir update: 'index' { rename = true }                                                                                                                                                                                
watcher_cb(2): Git dir update: 'index.lock' { rename = true } (ignoring)                                                                                                                                                                
watcher_cb(2): Git dir update: 'index' { rename = true }                                                                                                                                                                                
watcher_cb(2): Git dir update: 'index' { rename = true }                                                                                                                                                                                
watcher_cb(1): Git dir update: 'index.lock' { rename = true } (ignoring)                                                                                                                                                                
watcher_cb(1): Git dir update: 'index' { rename = true }                                                                                                                                                                                
watcher_cb(1): Git dir update: 'index' { rename = true }                                                                                                                                                                                
watcher_cb(2): Git dir update: 'index.lock' { rename = true } (ignoring)                                                                                                                                                                
watcher_cb(2): Git dir update: 'index' { rename = true }                                                                                                                                                                                
watcher_cb(2): Git dir update: 'index' { rename = true }                                                                                                                                                                                
run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 rev-parse --show-toplevel --absolute-git-dir --abbrev-ref HEAD                                                                                             
run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 rev-parse --show-toplevel --absolute-git-dir --abbrev-ref HEAD                                                                                             
run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 rev-parse --short HEAD                                                                                                                                     
run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 rev-parse --short HEAD                                                                                                                                     
run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir /Volumes/k/Misc/gitsigns-bug-report/git-tracked-dir/.git -c core.quotepath=off ls-files --stage --others --exclude-standard --eol /Volumes/k/Misc
/gitsigns-bug-report/git-tracked-dir/testFile2.txt                                                                                                                                                                                      
run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir /Volumes/k/Misc/gitsigns-bug-report/git-tracked-dir/.git -c core.quotepath=off ls-files --stage --others --exclude-standard --eol /Volumes/k/Misc
/gitsigns-bug-report/git-tracked-dir/testFile1.txt                                                                                                                                                                                      
run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir /Volumes/k/Misc/gitsigns-bug-report/git-tracked-dir/.git show d61e4068d31be1aaefd3f8a241d0ee913f64c197                                           
run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir /Volumes/k/Misc/gitsigns-bug-report/git-tracked-dir/.git show bfebabf6bfbf2e6072b50b30a1dab801f1157777                                           
attach(1): Already attached                                                                                                                                                                                                             
on_reload(1): Reload                                                                                                                                                                                                                    
attach(2): Already attached                                                                                                                                                                                                             
on_reload(2): Reload                                                                                                                                                                                                                    
cli.run: Running action 'debug_messages' with arguments {}                                                                                                                                                                              
cli.run: Running action 'debug_messages' with arguments {}                                                                                                                                                                              
Press ENTER or type command to continue          
lewis6991 commented 3 months ago

Please remove lazy.nvim from the repro steps.

metziger23 commented 3 months ago

Please remove lazy.nvim from the repro steps.

I updated the minimal config

lewis6991 commented 2 months ago

Should be fixed in #1047. Let me know if it isn't.