2022-11-28 10:04:32 +00:00
|
|
|
local Util = require("lazy.util")
|
2022-11-28 10:36:12 +00:00
|
|
|
local Git = require("lazy.manage.git")
|
2022-11-28 10:04:32 +00:00
|
|
|
|
|
|
|
---@type table<string, LazyTaskDef>
|
|
|
|
local M = {}
|
|
|
|
|
|
|
|
M.log = {
|
2022-11-28 12:10:52 +00:00
|
|
|
skip = function(plugin, opts)
|
|
|
|
if not (opts.interactive and Util.file_exists(plugin.dir .. "/.git")) then
|
2022-11-28 10:04:32 +00:00
|
|
|
return false
|
|
|
|
end
|
2022-11-28 12:10:52 +00:00
|
|
|
return plugin._.updated and plugin._.updated.from == plugin._.updated.to
|
2022-11-28 10:04:32 +00:00
|
|
|
end,
|
|
|
|
run = function(self)
|
|
|
|
local args = {
|
|
|
|
"log",
|
|
|
|
"--pretty=format:%h %s (%cr)",
|
|
|
|
"--abbrev-commit",
|
|
|
|
"--decorate",
|
|
|
|
"--date=short",
|
|
|
|
"--color=never",
|
|
|
|
}
|
|
|
|
|
2022-11-28 10:19:50 +00:00
|
|
|
if self.plugin._.updated then
|
|
|
|
table.insert(args, self.plugin._.updated.from .. ".." .. (self.plugin._.updated.to or "HEAD"))
|
2022-11-28 10:04:32 +00:00
|
|
|
else
|
|
|
|
table.insert(args, "--since=7 days ago")
|
|
|
|
end
|
|
|
|
|
|
|
|
self:spawn("git", {
|
|
|
|
args = args,
|
|
|
|
cwd = self.plugin.dir,
|
|
|
|
})
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
|
|
|
|
M.update = {
|
|
|
|
run = function(self)
|
2022-11-28 12:10:52 +00:00
|
|
|
if self.plugin._.is_local ~= self.plugin._.is_symlink then
|
|
|
|
-- FIXME: should change here and in install
|
|
|
|
error("incorrect local")
|
|
|
|
end
|
|
|
|
if self.plugin._.is_local then
|
2022-11-28 10:04:32 +00:00
|
|
|
if vim.loop.fs_realpath(self.plugin.uri) ~= vim.loop.fs_realpath(self.plugin.dir) then
|
|
|
|
vim.loop.fs_unlink(self.plugin.dir)
|
|
|
|
vim.loop.fs_symlink(self.plugin.uri, self.plugin.dir, {
|
|
|
|
dir = true,
|
|
|
|
})
|
|
|
|
vim.opt.runtimepath:append(self.plugin.uri)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
local args = {
|
|
|
|
"pull",
|
|
|
|
"--recurse-submodules",
|
|
|
|
"--update-shallow",
|
|
|
|
"--progress",
|
|
|
|
}
|
2022-11-28 10:36:12 +00:00
|
|
|
local git = assert(Git.info(self.plugin.dir))
|
2022-11-28 10:04:32 +00:00
|
|
|
|
|
|
|
self:spawn("git", {
|
|
|
|
args = args,
|
|
|
|
cwd = self.plugin.dir,
|
|
|
|
on_exit = function(ok)
|
|
|
|
if ok then
|
2022-11-28 10:36:12 +00:00
|
|
|
local git_new = assert(Git.info(self.plugin.dir))
|
2022-11-28 10:19:50 +00:00
|
|
|
self.plugin._.updated = {
|
2022-11-28 10:36:12 +00:00
|
|
|
from = git.commit,
|
|
|
|
to = git_new.commit,
|
2022-11-28 10:04:32 +00:00
|
|
|
}
|
2022-11-28 10:19:50 +00:00
|
|
|
self.plugin._.dirty = not vim.deep_equal(git, git_new)
|
2022-11-28 10:04:32 +00:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
|
|
|
|
M.install = {
|
|
|
|
run = function(self)
|
2022-11-28 12:10:52 +00:00
|
|
|
if self.plugin._.is_local then
|
|
|
|
vim.loop.fs_symlink(self.plugin.uri, self.plugin.dir, { dir = true })
|
2022-11-28 10:04:32 +00:00
|
|
|
vim.opt.runtimepath:append(self.plugin.uri)
|
|
|
|
else
|
|
|
|
local args = {
|
|
|
|
"clone",
|
|
|
|
self.plugin.uri,
|
|
|
|
"--filter=blob:none",
|
|
|
|
"--recurse-submodules",
|
|
|
|
"--single-branch",
|
|
|
|
"--shallow-submodules",
|
2022-11-28 12:10:52 +00:00
|
|
|
"--no-checkout",
|
2022-11-28 10:04:32 +00:00
|
|
|
"--progress",
|
|
|
|
}
|
|
|
|
|
|
|
|
if self.plugin.branch then
|
2022-11-28 12:10:52 +00:00
|
|
|
vim.list_extend(args, { "-b", self.plugin.branch })
|
2022-11-28 10:04:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
table.insert(args, self.plugin.dir)
|
|
|
|
self:spawn("git", {
|
|
|
|
args = args,
|
|
|
|
on_exit = function(ok)
|
|
|
|
if ok then
|
2022-11-28 10:19:50 +00:00
|
|
|
self.plugin._.installed = true
|
|
|
|
self.plugin._.dirty = true
|
2022-11-28 10:04:32 +00:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
return M
|