feat(git): add in-house git blame

This commit is contained in:
2026-05-22 16:38:49 +02:00
parent a786d8458d
commit 432682409e
4 changed files with 1561 additions and 2 deletions
+34 -2
View File
@@ -40,6 +40,9 @@ local DEFAULT_HIGHLIGHTS = {
GitHunkRemoved = "Removed",
GitHunkAddLine = "DiffAdd",
GitHunkDeleteLine = "DiffDelete",
GitBlame = "Comment",
GitBlameSha = "GitSha",
}
local STAGED_HUNK_HL = {
GitHunkStagedAdded = "GitHunkAdded",
@@ -107,6 +110,7 @@ vim.api.nvim_create_autocmd({ "BufDelete", "BufWipeout" }, {
group = group,
callback = function(args)
require("git.hunks").detach(args.buf)
require("git.blame").detach(args.buf)
require("git.core.repo").unbind(args.buf)
end,
})
@@ -220,8 +224,7 @@ end, {
vim.api.nvim_create_user_command("Gstatus", function(opts)
require("git.status_view").open({
placement = opts.fargs[1] --[[@as ow.Git.StatusView.Placement]]
or "split",
placement = opts.fargs[1] --[[@as ow.Git.StatusView.Placement]] or "split",
})
end, {
nargs = "?",
@@ -314,3 +317,32 @@ end, { silent = true, desc = "Toggle the git diff overlay" })
vim.api.nvim_create_user_command("GitDiffOverlay", function()
require("git.hunks").toggle_overlay()
end, { desc = "Toggle the git diff overlay in the current buffer" })
vim.keymap.set("n", "<Plug>(git-blame)", function()
require("git.blame").toggle_overlay()
end, { silent = true, desc = "Toggle the full-file git blame overlay" })
vim.keymap.set("n", "<Plug>(git-blame-line)", function()
require("git.blame").toggle_inline()
end, { silent = true, desc = "Toggle inline git blame" })
vim.keymap.set("n", "<Plug>(git-blame-popup)", function()
require("git.blame").line_popup()
end, { silent = true, desc = "Show git blame for the current line" })
vim.keymap.set("n", "<Plug>(git-blame-commit)", function()
require("git.blame").open_commit()
end, { silent = true, desc = "Open the commit that last touched this line" })
vim.keymap.set("n", "<Plug>(git-blame-file)", function()
require("git.blame").open_file()
end, { silent = true, desc = "Open this file at the line's commit" })
vim.keymap.set("n", "<Plug>(git-blame-file-parent)", function()
require("git.blame").open_file_parent()
end, {
silent = true,
desc = "Open this file at the parent of the line's commit",
})
vim.api.nvim_create_user_command("GitBlame", function()
require("git.blame").toggle_overlay()
end, { desc = "Toggle the full-file git blame overlay in the current buffer" })
vim.api.nvim_create_user_command("GitBlameLine", function()
require("git.blame").toggle_inline()
end, { desc = "Toggle inline git blame in the current buffer" })