express_line.nvim icon indicating copy to clipboard operation
express_line.nvim copied to clipboard

Discrepancy with GitGutter

Open ghost opened this issue 4 years ago • 4 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?

ghost avatar Sep 12 '20 18:09 ghost

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.

smartding avatar Dec 04 '20 01:12 smartding

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.

ghost avatar Dec 04 '20 08:12 ghost

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

smartding avatar Dec 04 '20 12:12 smartding

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 : https://github.com/tjdevries/express_line.nvim/issues/12#issuecomment-738763790

smartding avatar Dec 04 '20 12:12 smartding