At the time of writing, after gitsigns.show() is executed, 3 GitSignsUpdates are being triggered on the newly opened buffer.
Note that some operations (like gitsigns.diffthis()) will not work properly unless all 3 events happened beforehand.
Since gitsigns.show() accepts "then" callback for async continuation of work, I would expect the following code to work:
Unfortunately, current implementation of gitsigns.show() seems to consistently execute "then" callback between first and second GitSignsUpdate event, thus gitsigns.diffthis() doesn't work at this stage.
Possible solution - Delay "then" callback of gitsigns.show() to be invoked after opened buffer is fully functional for further operations like gitsigns.diffthis().
To see opened diff between HEAD^ and HEAD^^ snapshots of the file.
Actual behavior
gitsigns.diffthis() fails and I'm left with showed HEAD^ snapshot of the file.
Minimal config
for name, url in pairs{
gitsigns = 'https://github.com/lewis6991/gitsigns.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
}
Steps to reproduce
Create testing environment
mkdir gitsigns_test
cd gitsigns_test
git init
echo -e "aaa\nbbb\nccc" > file
git add file
git commit -m "add 3 lines"
echo -e "aaaa\nbbbb\nccc" > file
git commit -am "modify first two lines"
echo -e "aaaa\nbbbbb\ncccc" > file
git commit -am "modify last two lines"
Open test file with minimal Neovim config
nvim --clean -u minimal.lua file
Navigate to third line (cccc).
Execute chained gitsigns.show() and gitsigns.diffthis() functions.
Observe that gitsigns.show() successfully opened HEAD^ snapshot of a file, but there is no desired diff.
Note that manually executing gitsigns.diffthis() now yields the expected result (after mentioned events passed):
:lua require("gitsigns").diffthis("HEAD^^")
Gitsigns debug messages
0.45 D dprintf: Deriving GitSignsAdd from Added
0.51 D derive: Deriving GitSignsChange from Changed
0.59 D derive: Deriving GitSignsDelete from Removed
0.62 D derive: Deriving GitSignsChangedelete from GitSignsChange
0.64 D derive: Deriving GitSignsTopdelete from GitSignsDelete
0.69 D derive: Deriving GitSignsUntracked from GitSignsAdd
0.70 D derive: Deriving GitSignsAddNr from GitSignsAdd
0.72 D derive: Deriving GitSignsChangeNr from GitSignsChange
0.75 D derive: Deriving GitSignsDeleteNr from GitSignsDelete
0.76 D derive: Deriving GitSignsChangedeleteNr from GitSignsChangeNr
0.80 D derive: Deriving GitSignsTopdeleteNr from GitSignsDeleteNr
0.81 D derive: Deriving GitSignsUntrackedNr from GitSignsAddNr
0.83 D derive: Deriving GitSignsAddLn from DiffAdd
0.86 D derive: Deriving GitSignsChangeLn from DiffChange
0.91 D derive: Deriving GitSignsChangedeleteLn from GitSignsChangeLn
0.94 D derive: Deriving GitSignsUntrackedLn from GitSignsAddLn
0.95 D derive: Deriving GitSignsStagedAdd from GitSignsAdd
0.97 D derive: Deriving GitSignsStagedChange from GitSignsChange
1.00 D derive: Deriving GitSignsStagedDelete from GitSignsDelete
1.01 D derive: Deriving GitSignsStagedChangedelete from GitSignsChangedelete
1.03 D derive: Deriving GitSignsStagedTopdelete from GitSignsTopdelete
1.04 D derive: Deriving GitSignsStagedAddNr from GitSignsAddNr
1.05 D derive: Deriving GitSignsStagedChangeNr from GitSignsChangeNr
1.08 D derive: Deriving GitSignsStagedDeleteNr from GitSignsDeleteNr
1.11 D derive: Deriving GitSignsStagedChangedeleteNr from GitSignsChangedeleteNr
1.13 D derive: Deriving GitSignsStagedTopdeleteNr from GitSignsTopdeleteNr
1.17 D derive: Deriving GitSignsStagedAddLn from GitSignsAddLn
1.18 D derive: Deriving GitSignsStagedChangeLn from GitSignsChangeLn
1.19 D derive: Could not derive GitSignsStagedDeleteLn
1.21 D derive: Deriving GitSignsStagedChangedeleteLn from GitSignsChangedeleteLn
1.22 D derive: Could not derive GitSignsStagedTopdeleteLn
1.25 D derive: Deriving GitSignsAddPreview from DiffAdd
1.26 D derive: Deriving GitSignsDeletePreview from DiffDelete
1.28 D derive: Deriving GitSignsCurrentLineBlame from NonText
1.30 D derive: Deriving GitSignsAddInline from TermCursor
1.31 D derive: Deriving GitSignsDeleteInline from TermCursor
1.34 D derive: Deriving GitSignsChangeInline from TermCursor
1.36 D derive: Deriving GitSignsAddLnInline from GitSignsAddInline
1.37 D derive: Deriving GitSignsChangeLnInline from GitSignsChangeInline
1.38 D derive: Deriving GitSignsDeleteLnInline from GitSignsDeleteInline
1.40 D derive: Deriving GitSignsDeleteVirtLn from DiffDelete
1.41 D derive: Deriving GitSignsDeleteVirtLnInLine from GitSignsDeleteLnInline
1.42 D derive: Deriving GitSignsVirtLnum from GitSignsDeleteVirtLn
5.23 D attach(1): Attaching (trigger=BufReadPost)
5.30 D run_job: git --version
9.49 D run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 rev-parse --show-toplevel --absolute-git-dir --abbrev-ref HEAD
10.65 D run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir /tmp/gitsigns_test/.git config user.name
11.68 D run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir /tmp/gitsigns_test/.git -c core.quotepath=off ls-files --stage --others --exclude-standard --eol /tmp/gitsigns_test/file
13.02 D watch_gitdir(1): Watching git dir
13.09 D run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir /tmp/gitsigns_test/.git show d70b101fd3f815557f68eff872bf0f8373f17314
15.10 D run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir /tmp/gitsigns_test/.git show HEAD:file
16715.68 D show(3): Detached
16715.68 D show(3): Cache was nil
16715.73 D attach(3): Attaching (trigger=BufFilePost)
16715.76 D show(3): Gitsigns buffer for file '/tmp/gitsigns_test/file' from path 'gitsigns:///tmp/gitsigns_test/.git/HEAD^:file' on commit 'HEAD^'
16715.88 D run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir /tmp/gitsigns_test/.git show HEAD^:file
16717.25 D run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 rev-parse --show-toplevel --absolute-git-dir --abbrev-ref HEAD
16718.17 D show(1): bufname gitsigns:///tmp/gitsigns_test/.git/HEAD^:file
16718.59 D run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir /tmp/gitsigns_test/.git -c core.quotepath=off ls-tree HEAD^ /tmp/gitsigns_test/file
16719.90 D show(3): Watching git dir
16719.96 D run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir /tmp/gitsigns_test/.git show 70db9132fdf518d67a66179a79647f6eaebbd9f3
16721.68 D run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir /tmp/gitsigns_test/.git show HEAD^^:file
25290.61 D cli.run: Running action 'debug_messages' with arguments {}
Description
At the time of writing, after
gitsigns.show()
is executed, 3GitSignsUpdate
s are being triggered on the newly opened buffer. Note that some operations (likegitsigns.diffthis()
) will not work properly unless all 3 events happened beforehand. Sincegitsigns.show()
accepts "then" callback for async continuation of work, I would expect the following code to work:Unfortunately, current implementation of
gitsigns.show()
seems to consistently execute "then" callback between first and secondGitSignsUpdate
event, thusgitsigns.diffthis()
doesn't work at this stage.Possible solution - Delay "then" callback of
gitsigns.show()
to be invoked after opened buffer is fully functional for further operations likegitsigns.diffthis()
.Neovim version
NVIM v0.10.0
Operating system and version
Arch Linux (x86_64) Kernel: 6.9.9-arch1-1
Expected behavior
To see opened diff between
HEAD^
andHEAD^^
snapshots of the file.Actual behavior
gitsigns.diffthis()
fails and I'm left withshow
edHEAD^
snapshot of the file.Minimal config
Steps to reproduce
cccc
).gitsigns.show()
andgitsigns.diffthis()
functions.gitsigns.show()
successfully openedHEAD^
snapshot of a file, but there is no desired diff.gitsigns.diffthis()
now yields the expected result (after mentioned events passed):Gitsigns debug messages
Gitsigns cache