tjdevries / express_line.nvim

WIP: Statusline written in pure lua. Supports co-routines, functions and jobs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Discrepancy with GitGutter

opened this issue · comments

For an example file el returns following hunks info: [+1, ~8, -6] while GitGutterGetHunkSummary() returns [7, 1, 5].

Do you know where this difference might be coming from?

commented

git builtin git_changes function calls git diff --shortstat buffer.name to get the changes, so it's only able to see changes already written to disk. gitgutter can see changes in the buffer that's not written to disk yet.
Not sure if there's more differences.

Yes, indeed. That was discussed with @tjdevries. git diff --shortstat <file> returns slightly different information than users expect for new, changed and deleted lines and most likely is not the right source of that information here.

Perhaps a better approach here would be to read that information from various plugins (vim-gitgutter, gitsigns, vim-signify) if they are available.

commented

Yes, indeed. That was discussed with @tjdevries. git diff --shortstat <file> returns slightly different information than users expect for new, changed and deleted lines and most likely is not the right source of that information here.

Perhaps a better approach here would be to read that information from various plugins (vim-gitgutter, gitsigns, vim-signify) if they are available.

gitgutter and gitsigns both have a buffer variable for this (not sure about signify), you can use a function like this to read the it:

local gitgutter_summary = function(_, buffer)
  local ok, res = pcall(vim.api.nvim_buf_get_var, buffer.bufnr, 'gitgutter')
  if ok then
    -- summary format: { added, modified, removed }
    local summary = res.summary
    return summary and string.format("[+%d ~%d -%d]", summary[1], summary[2], summary[3]) or ''
  else
    return ''
  end
end
commented

Yes, indeed. That was discussed with @tjdevries. git diff --shortstat <file> returns slightly different information than users expect for new, changed and deleted lines and most likely is not the right source of that information here.

Perhaps a better approach here would be to read that information from various plugins (vim-gitgutter, gitsigns, vim-signify) if they are available.

or if you use gitsigns, here's an example by @Katsika :
#12 (comment)