-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlog.lua
More file actions
36 lines (31 loc) · 813 Bytes
/
log.lua
File metadata and controls
36 lines (31 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
local M = {}
function M.get_commits(cb)
local cfg = require("gitlogdiff").config or {}
local max_count = tonumber(cfg.max_count)
local args = {
"git",
"log",
string.format("--max-count=%d", max_count),
"--pretty=format:%h %ad %s",
"--date=short",
"--color=never",
}
vim.system(args, { text = true }, function(res)
if res.code ~= 0 then
local err = (res.stderr or ""):gsub("\n$", "")
vim.schedule(function()
vim.notify(
(#err > 0) and ("git log failed: " .. err) or "git log failed (are you in a git repo?)",
vim.log.levels.WARN
)
cb({})
end)
return
end
local commits = vim.split(res.stdout, "\n", { trimempty = true })
vim.schedule(function()
cb(commits)
end)
end)
end
return M