mirror of https://github.com/folke/lazy.nvim.git
feat: git log
This commit is contained in:
parent
54d5ff18f5
commit
3218c2d9ec
|
@ -0,0 +1 @@
|
|||
tt.lua
|
|
@ -53,6 +53,9 @@ function M.run(operation, opts, filter)
|
|||
runner:add(Task.new(plugin, "run"))
|
||||
end
|
||||
plugin.dirty = false
|
||||
if operation == "update" then
|
||||
runner:add(Task.new(plugin, "log"))
|
||||
end
|
||||
end
|
||||
-- wait for post-install to finish
|
||||
runner:wait(on_done)
|
||||
|
@ -85,6 +88,14 @@ function M.update(opts)
|
|||
end)
|
||||
end
|
||||
|
||||
---@param opts? ManagerOpts
|
||||
function M.log(opts)
|
||||
---@param plugin LazyPlugin
|
||||
M.run("log", opts, function(plugin)
|
||||
return plugin.uri and plugin.installed
|
||||
end)
|
||||
end
|
||||
|
||||
---@param opts? ManagerOpts
|
||||
function M.clean(opts)
|
||||
opts = opts or {}
|
||||
|
|
|
@ -8,7 +8,7 @@ local Util = require("lazy.util")
|
|||
---@field running boolean
|
||||
local Task = {}
|
||||
|
||||
---@alias TaskType "update"|"install"|"run"|"clean"
|
||||
---@alias TaskType "update"|"install"|"run"|"clean"|"log"
|
||||
|
||||
---@param plugin LazyPlugin
|
||||
---@param type TaskType
|
||||
|
@ -27,7 +27,6 @@ end
|
|||
|
||||
function Task:_done()
|
||||
self.running = false
|
||||
|
||||
vim.cmd("do User LazyRender")
|
||||
end
|
||||
|
||||
|
@ -54,7 +53,7 @@ function Task:clean()
|
|||
end
|
||||
|
||||
self.plugin.installed = false
|
||||
self.running = false
|
||||
self:_done()
|
||||
end
|
||||
|
||||
function Task:install()
|
||||
|
@ -161,16 +160,38 @@ function Task:start()
|
|||
self:run()
|
||||
elseif self.type == "clean" then
|
||||
self:clean()
|
||||
elseif self.type == "log" then
|
||||
self:log()
|
||||
end
|
||||
end)
|
||||
|
||||
if not ok then
|
||||
self.error = err or "failed"
|
||||
|
||||
self:_done()
|
||||
end
|
||||
end
|
||||
|
||||
function Task:log()
|
||||
if not Util.file_exists(self.plugin.dir .. "/.git") then
|
||||
self:_done()
|
||||
return
|
||||
end
|
||||
|
||||
local args = {
|
||||
"log",
|
||||
"--pretty=format:%h %s (%cr)",
|
||||
"--abbrev-commit",
|
||||
"--decorate",
|
||||
"--date=short",
|
||||
"--color=never",
|
||||
"--since='7 days ago'",
|
||||
}
|
||||
self:spawn("git", {
|
||||
args = args,
|
||||
cwd = self.plugin.dir,
|
||||
})
|
||||
end
|
||||
|
||||
function Task:update()
|
||||
if Util.file_exists(self.plugin.uri) then
|
||||
if vim.loop.fs_realpath(self.plugin.uri) ~= vim.loop.fs_realpath(self.plugin.dir) then
|
||||
|
@ -180,7 +201,6 @@ function Task:update()
|
|||
})
|
||||
vim.opt.runtimepath:append(self.plugin.uri)
|
||||
end
|
||||
|
||||
self:_done()
|
||||
else
|
||||
local args = {
|
||||
|
|
|
@ -21,6 +21,9 @@ M.commands = {
|
|||
install = function()
|
||||
Manager.install({ clear = true, show = true })
|
||||
end,
|
||||
log = function()
|
||||
Manager.log({ clear = true, show = true })
|
||||
end,
|
||||
show = function()
|
||||
View.show()
|
||||
end,
|
||||
|
|
|
@ -119,6 +119,25 @@ function M:plugin(plugin)
|
|||
self:nl()
|
||||
end
|
||||
end
|
||||
elseif task.type == "log" then
|
||||
local log = vim.trim(task.output)
|
||||
if log ~= "" then
|
||||
local lines = vim.split(log, "\n")
|
||||
for l, line in ipairs(lines) do
|
||||
if l == 1 then
|
||||
self:nl()
|
||||
end
|
||||
local ref, msg, time = line:match("^(%w+) (.*) (%(.*%))$")
|
||||
self:append(" " .. ref .. " ", "@variable.builtin")
|
||||
local col = self:col()
|
||||
self:append(msg)
|
||||
-- string.gsub
|
||||
self:append(" " .. time, "Comment")
|
||||
if l ~= #lines then
|
||||
self:nl()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -51,6 +51,14 @@ return {
|
|||
end,
|
||||
title = "Running",
|
||||
},
|
||||
{
|
||||
filter = function(plugin)
|
||||
return has_task(plugin, function(task)
|
||||
return task.type == "log" and vim.trim(task.output) ~= ""
|
||||
end)
|
||||
end,
|
||||
title = "Log",
|
||||
},
|
||||
{
|
||||
filter = function(plugin)
|
||||
return plugin.installed and not plugin.uri
|
||||
|
|
|
@ -16,7 +16,7 @@ function Text.new()
|
|||
end
|
||||
|
||||
---@param str string
|
||||
---@param hl string|table
|
||||
---@param hl? string|table
|
||||
function Text:append(str, hl)
|
||||
if #self._lines == 0 then
|
||||
self:nl()
|
||||
|
@ -84,4 +84,19 @@ function Text:trim()
|
|||
end
|
||||
end
|
||||
|
||||
function Text:row()
|
||||
return #self._lines == 0 and 1 or #self._lines
|
||||
end
|
||||
|
||||
function Text:col()
|
||||
if #self._lines == 0 then
|
||||
return 0
|
||||
end
|
||||
local width = 0
|
||||
for _, segment in ipairs(self._lines[#self._lines]) do
|
||||
width = width + vim.fn.strlen(segment.str)
|
||||
end
|
||||
return width
|
||||
end
|
||||
|
||||
return Text
|
||||
|
|
Loading…
Reference in New Issue