tjdevries / express_line.nvim

WIP: Statusline written in pure lua. Supports co-routines, functions and jobs.
MIT License
298 stars 18 forks source link

Discrepancy with GitGutter #10

Open ghost opened 4 years ago

ghost commented 4 years ago

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?

smartding commented 3 years ago

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.

ghost commented 3 years ago

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.

smartding commented 3 years ago

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 commented 3 years ago

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