Files
nvim/lua/git/log.lua
T
2026-04-27 16:34:16 +02:00

50 lines
1.3 KiB
Lua

local git = require("git")
local log = require("log")
local repo = require("git.repo")
local util = require("util")
local M = {}
local LOG_FORMAT = "%h %ad {%an}%d %s"
function M.show()
local _, worktree = repo.resolve_cwd()
if not worktree then
log.warning("not in a git repository")
return
end
local buf = git.new_scratch()
vim.b[buf].git_worktree = worktree
vim.system(
{
"git",
"log",
"--graph",
"--all",
"--decorate",
"--date=short",
"--format=format:" .. LOG_FORMAT,
},
{ cwd = worktree, text = true },
vim.schedule_wrap(function(result)
if not vim.api.nvim_buf_is_valid(buf) then
return
end
if result.code ~= 0 then
log.error("git log failed: %s", vim.trim(result.stderr or ""))
return
end
local lines = util.split_lines(result.stdout or "")
vim.bo[buf].modifiable = true
vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines)
vim.bo[buf].modifiable = false
vim.bo[buf].modified = false
vim.bo[buf].filetype = "gitlog"
end)
)
end
return M