Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: get commit hash for the current line #944

Closed
andrhua opened this issue Feb 3, 2024 · 1 comment
Closed

Feature request: get commit hash for the current line #944

andrhua opened this issue Feb 3, 2024 · 1 comment

Comments

@andrhua
Copy link

andrhua commented Feb 3, 2024

I want to be able to jump to the commit, where current line was added/changed. I tried to quickly come up with solution based on blame_line function:

-- lua/gitsigns/actions.lua
M.commit_hash_line = function()
  local bufnr = current_buf()
  local bcache = cache[bufnr]
  if not bcache then
    return
  end

  local lnum = api.nvim_win_get_cursor(0)[1]
  local blame_info = bcache:get_blame(lnum, {})
  assert(blame_info)

  return blame_info.commit.sha
end

But it didn't work

gitsigns.nvim/lua/gitsigns/actions.lua:889: assertion failed!
stack traceback:
        [C]: in function 'assert'
        .../gitsigns.nvim/lua/gitsigns/actions.lua:889: in function 'commit_hash_line'

My best guess is that there are some intricacies in the flow of updating blame cache, if it wasn't my first time grokking at lua code other than my nvim config, I'd probably had more insights :)

This function would neatly integrate with :DiffviewOpen <commit> command

@andrhua
Copy link
Author

andrhua commented Feb 3, 2024

Nevermind, I found you can do it via diffview means sindrets/diffview.nvim#307 (comment)

@andrhua andrhua closed this as completed Feb 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant