lewis6991 / gitsigns.nvim

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

Error when opening a file revision with blame enabled #1093

Open stv17 opened 1 month ago

stv17 commented 1 month ago

Description

First of all, thanks for your work on this plugin. I mostly use it for signs but I appreciate the new features and hope it continues to evolve. This is my first issue report.

When viewing the revision of a file (like with :Gedit @^:% from vim-fugitive or :Gitsigns show @^ if you have option current_line_blame enabled then an error pops up. I think this started happening not long ago, but I can't say which version of gitsigns I was using at the time.

Do note that the option in question is given disabled by the README config.

Neovim version

NVIM v0.10.1-dev-55+g9c6efd0a6

Operating system and version

Debian stable (Bookworm)

Expected behavior

From the README comment on integration with fugitive I take the revision should show the signs relative to it's parent (as I think it always did).

Actual behavior

This error pops up: image

The --contents flag is probably added by file "lua/gitsigns/git/blame.lua".

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,
    current_line_blame = true,
})

vim.opt.relativenumber = true

Steps to reproduce

A simple setup:

mkdir gitsigns_issue
touch minimal.lua
# -> copy the minimal config from above into the file
git init .
git add minimal.lua
git commit -m "first"
echo "-- a change" >> minimal.lua
git add minimal.lua
git commit -m "second"
nvim --clean -u minimal.lua minimal.lua

And now in neovim do :Gitsigns show @

Gitsigns debug messages

0.45 D dprintf: Deriving GitSignsAdd from Added
0.48 D derive: Deriving GitSignsChange from Changed
0.53 D derive: Deriving GitSignsDelete from Removed
0.57 D derive: Deriving GitSignsChangedelete from GitSignsChange
0.61 D derive: Deriving GitSignsTopdelete from GitSignsDelete
0.65 D derive: Deriving GitSignsUntracked from GitSignsAdd
0.68 D derive: Deriving GitSignsAddNr from GitSignsAdd
0.70 D derive: Deriving GitSignsChangeNr from GitSignsChange
0.75 D derive: Deriving GitSignsDeleteNr from GitSignsDelete
0.80 D derive: Deriving GitSignsChangedeleteNr from GitSignsChangeNr
0.83 D derive: Deriving GitSignsTopdeleteNr from GitSignsDeleteNr
0.85 D derive: Deriving GitSignsUntrackedNr from GitSignsAddNr
0.88 D derive: Deriving GitSignsAddLn from DiffAdd
0.90 D derive: Deriving GitSignsChangeLn from DiffChange
0.92 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
0.99 D derive: Deriving GitSignsStagedDelete from GitSignsDelete
1.01 D derive: Deriving GitSignsStagedChangedelete from GitSignsChangedelete
1.02 D derive: Deriving GitSignsStagedTopdelete from GitSignsTopdelete
1.04 D derive: Deriving GitSignsStagedAddNr from GitSignsAddNr
1.07 D derive: Deriving GitSignsStagedChangeNr from GitSignsChangeNr
1.09 D derive: Deriving GitSignsStagedDeleteNr from GitSignsDeleteNr
1.12 D derive: Deriving GitSignsStagedChangedeleteNr from GitSignsChangedeleteNr
1.14 D derive: Deriving GitSignsStagedTopdeleteNr from GitSignsTopdeleteNr
1.15 D derive: Deriving GitSignsStagedAddLn from GitSignsAddLn
1.17 D derive: Deriving GitSignsStagedChangeLn from GitSignsChangeLn
1.19 D derive: Could not derive GitSignsStagedDeleteLn
1.20 D derive: Deriving GitSignsStagedChangedeleteLn from GitSignsChangedeleteLn
1.22 D derive: Could not derive GitSignsStagedTopdeleteLn
1.23 D derive: Deriving GitSignsAddPreview from DiffAdd
1.27 D derive: Deriving GitSignsDeletePreview from DiffDelete
1.30 D derive: Deriving GitSignsCurrentLineBlame from NonText
1.32 D derive: Deriving GitSignsAddInline from TermCursor
1.35 D derive: Deriving GitSignsDeleteInline from TermCursor
1.36 D derive: Deriving GitSignsChangeInline from TermCursor
1.38 D derive: Deriving GitSignsAddLnInline from GitSignsAddInline
1.39 D derive: Deriving GitSignsChangeLnInline from GitSignsChangeInline
1.42 D derive: Deriving GitSignsDeleteLnInline from GitSignsDeleteInline
1.44 D derive: Deriving GitSignsDeleteVirtLn from DiffDelete
1.46 D derive: Deriving GitSignsDeleteVirtLnInLine from GitSignsDeleteLnInline
1.47 D derive: Deriving GitSignsVirtLnum from GitSignsDeleteVirtLn
7.04 D attach(1): Attaching (trigger=BufReadPost)
7.11 D run_job: git --version
20.86 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
23.27 D run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir /home/stv/dotfiles/gitsigns-minimal-blame/.git config user.name
25.44 D run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir /home/stv/dotfiles/gitsigns-minimal-blame/.git -c core.quotepath=off ls-files --stage --others --exclude-standard --eol /home/stv/dotfiles/gitsigns-minimal-blame/minimal.lua
28.12 D watch_gitdir(1): Watching git dir
28.26 D run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir /home/stv/dotfiles/gitsigns-minimal-blame/.git show 218dc52fdb7d9f1c587dd375520641e44b77565d
31.86 D run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir /home/stv/dotfiles/gitsigns-minimal-blame/.git show HEAD:minimal.lua
1036.21 D run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir /home/stv/dotfiles/gitsigns-minimal-blame/.git blame --contents - --incremental -- /home/stv/dotfiles/gitsigns-minimal-blame/minimal.lua
11195.60 D cli.run: Running action 'show' with arguments { "@" }
11195.99 D show(2): Detached
11196.00 D show(2): Cache was nil
11196.05 D attach(2): Attaching (trigger=BufFilePost)
11196.09 D show(2): Gitsigns buffer for file '/home/stv/dotfiles/gitsigns-minimal-blame/minimal.lua' from path 'gitsigns:///home/stv/dotfiles/gitsigns-minimal-blame/.git/@:minimal.lua' on commit '@'
11196.33 D run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir /home/stv/dotfiles/gitsigns-minimal-blame/.git show @:minimal.lua
11198.10 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
11201.02 D show(1): bufname gitsigns:///home/stv/dotfiles/gitsigns-minimal-blame/.git/@:minimal.lua
11201.79 D run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir /home/stv/dotfiles/gitsigns-minimal-blame/.git -c core.quotepath=off ls-tree @ /home/stv/dotfiles/gitsigns-minimal-blame/minimal.lua
11207.72 D show(2): Watching git dir
11207.75 D run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir /home/stv/dotfiles/gitsigns-minimal-blame/.git show 218dc52fdb7d9f1c587dd375520641e44b77565d
11211.08 D run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir /home/stv/dotfiles/gitsigns-minimal-blame/.git show @^:minimal.lua
12216.27 D run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir /home/stv/dotfiles/gitsigns-minimal-blame/.git blame --contents - --incremental @ -- /home/stv/dotfiles/gitsigns-minimal-blame/minimal.lua
24402.27 D show(2): Detached
24402.67 D attach(3): Attaching (trigger=BufNewFile)
24405.21 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
24407.77 D run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir /home/stv/dotfiles/gitsigns-minimal-blame/.git config user.name
24410.02 D run_job: git --no-pager --no-optional-locks --literal-pathspecs -c gc.auto=0 --git-dir /home/stv/dotfiles/gitsigns-minimal-blame/.git -c core.quotepath=off ls-files --stage --others --exclude-standard --eol /home/stv/dotfiles/gitsigns-minimal-blame/asdf.log
24412.45 D attach(3): Not a file
45778.68 D cli.run: Running action 'debug_messages' with arguments {}

Gitsigns cache

No response

lewis6991 commented 1 month ago

Works for me

https://github.com/user-attachments/assets/cf571836-22f5-4ca6-9304-2ac816a9ab82

Is it perhaps your version of git?

lewis6991 commented 1 month ago

Can you run:

cat minimal.lua | git blame --contents - --incremental @ -- minimal.lua
stv17 commented 1 month ago

Hello, indeed it'd appear to be the git version. The command you suggested (cat minimal.lua | git blame --contents - --incremental @ -- minimal.lua) throws the same error I see in neovim:

fatal: cannot use --contents with final commit object name

My git version is:

git version 2.39.2

Further, looking at git-blame docs:

So I bet you have git v2.41 or greater. Thanks for your feedback, in my case this will be solved by the next git update from Debian.

lewis6991 commented 1 month ago

Hmm I might be able to workaround this. If revision is specified, then most of the time --contents shouldn't be needed.