45 lines
1.1 KiB
Lua
45 lines
1.1 KiB
Lua
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 result = vim.system({
|
|
"git",
|
|
"log",
|
|
"--graph",
|
|
"--all",
|
|
"--decorate",
|
|
"--date=short",
|
|
"--format=format:" .. LOG_FORMAT,
|
|
}, { cwd = worktree, text = true }):wait()
|
|
if result.code ~= 0 then
|
|
log.error("git log failed: %s", result.stderr or "")
|
|
return
|
|
end
|
|
|
|
local lines = util.split_lines(result.stdout or "")
|
|
|
|
vim.cmd("new")
|
|
local buf = vim.api.nvim_get_current_buf()
|
|
vim.bo[buf].buftype = "nofile"
|
|
vim.bo[buf].bufhidden = "hide"
|
|
vim.bo[buf].swapfile = false
|
|
vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines)
|
|
vim.bo[buf].modifiable = false
|
|
vim.bo[buf].modified = false
|
|
vim.b[buf].git_worktree = worktree
|
|
vim.bo[buf].filetype = "gitlog"
|
|
end
|
|
|
|
return M
|