feat(git): replace vim-fugitive with custom git module
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
local log = require("log")
|
||||
local repo = require("git.repo")
|
||||
|
||||
local M = {}
|
||||
|
||||
local LOG_FORMAT = "%h %ad {%an}%d %s"
|
||||
|
||||
function M.show()
|
||||
local path = vim.api.nvim_buf_get_name(0)
|
||||
if path == "" then
|
||||
path = vim.fn.getcwd()
|
||||
end
|
||||
local _, worktree = repo.resolve(path)
|
||||
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 = vim.split(
|
||||
result.stdout or "",
|
||||
"\n",
|
||||
{ plain = true, trimempty = false }
|
||||
)
|
||||
if #lines > 0 and lines[#lines] == "" then
|
||||
table.remove(lines)
|
||||
end
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user