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 21:03:44 +00:00
|
|
|
---@param opts {since?: string, updated?:boolean}
|
2022-11-28 12:10:52 +00:00
|
|
|
skip = function(plugin, opts)
|
2022-11-28 21:03:44 +00:00
|
|
|
if opts.updated and not (plugin._.updated and plugin._.updated.from ~= plugin._.updated.to) then
|
|
|
|
return true
|
2022-11-28 10:04:32 +00:00
|
|
|
end
|
2022-11-28 21:03:44 +00:00
|
|
|
return not Util.file_exists(plugin.dir .. "/.git")
|
2022-11-28 10:04:32 +00:00
|
|
|
end,
|
2022-11-28 21:03:44 +00:00
|
|
|
---@param opts {since?: string, updated?:boolean}
|
|
|
|
run = function(self, opts)
|
2022-11-28 10:04:32 +00:00
|
|
|
local args = {
|
|
|
|
"log",
|
|
|
|
"--pretty=format:%h %s (%cr)",
|
|
|
|
"--abbrev-commit",
|
|
|
|
"--decorate",
|
|
|
|
"--date=short",
|
|
|
|
"--color=never",
|
|
|
|
}
|
|
|
|
|
2022-11-28 21:03:44 +00:00
|
|
|
if opts.updated then
|
2022-11-28 10:19:50 +00:00
|
|
|
table.insert(args, self.plugin._.updated.from .. ".." .. (self.plugin._.updated.to or "HEAD"))
|
2022-11-28 10:04:32 +00:00
|
|
|
else
|
2022-11-28 21:03:44 +00:00
|
|
|
table.insert(args, "--since=" .. (opts.since or "7 days ago"))
|
2022-11-28 10:04:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
self:spawn("git", {
|
|
|
|
args = args,
|
|
|
|
cwd = self.plugin.dir,
|
|
|
|
})
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
|
2022-11-28 21:03:44 +00:00
|
|
|
M.clone = {
|
|
|
|
skip = function(plugin)
|
|
|
|
return plugin._.installed or plugin._.is_local
|
|
|
|
end,
|
2022-11-28 10:04:32 +00:00
|
|
|
run = function(self)
|
2022-11-28 21:03:44 +00:00
|
|
|
local args = {
|
|
|
|
"clone",
|
|
|
|
self.plugin.uri,
|
|
|
|
"--filter=blob:none",
|
|
|
|
"--recurse-submodules",
|
|
|
|
"--single-branch",
|
|
|
|
"--shallow-submodules",
|
|
|
|
"--no-checkout",
|
|
|
|
"--progress",
|
|
|
|
}
|
|
|
|
|
|
|
|
if self.plugin.branch then
|
|
|
|
vim.list_extend(args, { "-b", self.plugin.branch })
|
2022-11-28 12:10:52 +00:00
|
|
|
end
|
2022-11-28 21:03:44 +00:00
|
|
|
|
|
|
|
table.insert(args, self.plugin.dir)
|
|
|
|
self:spawn("git", {
|
|
|
|
args = args,
|
|
|
|
on_exit = function(ok)
|
|
|
|
if ok then
|
|
|
|
self.plugin._.cloned = true
|
|
|
|
self.plugin._.installed = true
|
|
|
|
self.plugin._.dirty = true
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
|
|
|
|
M.branch = {
|
|
|
|
skip = function(plugin)
|
|
|
|
if not plugin._.installed or plugin._.is_local then
|
|
|
|
return true
|
2022-11-28 10:04:32 +00:00
|
|
|
end
|
2022-11-28 21:03:44 +00:00
|
|
|
local branch = assert(Git.get_branch(plugin))
|
|
|
|
return branch and branch.commit
|
|
|
|
end,
|
|
|
|
run = function(self)
|
|
|
|
local branch = assert(Git.get_branch(self.plugin))
|
|
|
|
local args = {
|
|
|
|
"remote",
|
|
|
|
"set-branches",
|
|
|
|
"--add",
|
|
|
|
"origin",
|
|
|
|
branch.branch,
|
|
|
|
}
|
|
|
|
|
|
|
|
self:spawn("git", {
|
|
|
|
args = args,
|
|
|
|
cwd = self.plugin.dir,
|
|
|
|
})
|
2022-11-28 10:04:32 +00:00
|
|
|
end,
|
|
|
|
}
|
|
|
|
|
2022-11-28 21:03:44 +00:00
|
|
|
M.fetch = {
|
|
|
|
skip = function(plugin)
|
|
|
|
return not plugin._.installed or plugin._.is_local
|
|
|
|
end,
|
2022-11-28 10:04:32 +00:00
|
|
|
run = function(self)
|
2022-11-28 21:03:44 +00:00
|
|
|
local args = {
|
|
|
|
"fetch",
|
|
|
|
"--recurse-submodules",
|
|
|
|
"--update-shallow",
|
|
|
|
"--progress",
|
|
|
|
}
|
|
|
|
|
|
|
|
self:spawn("git", {
|
|
|
|
args = args,
|
|
|
|
cwd = self.plugin.dir,
|
|
|
|
})
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
|
|
|
|
M.checkout = {
|
|
|
|
skip = function(plugin)
|
|
|
|
return not plugin._.installed or plugin._.is_local
|
|
|
|
end,
|
|
|
|
run = function(self)
|
|
|
|
local info = assert(Git.info(self.plugin.dir))
|
|
|
|
local target = assert(Git.get_target(self.plugin))
|
|
|
|
|
|
|
|
if not self.plugin._.cloned and info.commit == target.commit then
|
|
|
|
return
|
2022-11-28 10:04:32 +00:00
|
|
|
end
|
2022-11-28 21:03:44 +00:00
|
|
|
|
|
|
|
local args = {
|
|
|
|
"checkout",
|
|
|
|
"--progress",
|
|
|
|
}
|
|
|
|
|
|
|
|
if target.tag then
|
|
|
|
table.insert(args, "tags/" .. target.tag)
|
|
|
|
elseif self.plugin.commit then
|
|
|
|
table.insert(args, self.plugin.commit)
|
|
|
|
elseif target.branch then
|
|
|
|
table.insert(args, target.branch)
|
|
|
|
end
|
|
|
|
|
|
|
|
self:spawn("git", {
|
|
|
|
args = args,
|
|
|
|
cwd = self.plugin.dir,
|
|
|
|
on_exit = function(ok)
|
|
|
|
if ok then
|
|
|
|
local new_info = assert(Git.info(self.plugin.dir))
|
|
|
|
if not self.plugin._.cloned then
|
|
|
|
self.plugin._.updated = {
|
|
|
|
from = info.commit,
|
|
|
|
to = new_info.commit,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
self.plugin._.dirty = true
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
2022-11-28 10:04:32 +00:00
|
|
|
end,
|
|
|
|
}
|
|
|
|
return M
|