mirror of
https://github.com/folke/lazy.nvim.git
synced 2025-04-19 04:46:45 +00:00
feat: lots of improvements to pipeline runner and converted all tasks to new system
This commit is contained in:
parent
4de10f9578
commit
fb84c081b0
13 changed files with 381 additions and 200 deletions
|
@ -5,13 +5,15 @@ local Git = require("lazy.manage.git")
|
|||
local M = {}
|
||||
|
||||
M.log = {
|
||||
---@param opts {since?: string, updated?:boolean}
|
||||
skip = function(plugin, opts)
|
||||
if not (opts.interactive and Util.file_exists(plugin.dir .. "/.git")) then
|
||||
return false
|
||||
if opts.updated and not (plugin._.updated and plugin._.updated.from ~= plugin._.updated.to) then
|
||||
return true
|
||||
end
|
||||
return plugin._.updated and plugin._.updated.from == plugin._.updated.to
|
||||
return not Util.file_exists(plugin.dir .. "/.git")
|
||||
end,
|
||||
run = function(self)
|
||||
---@param opts {since?: string, updated?:boolean}
|
||||
run = function(self, opts)
|
||||
local args = {
|
||||
"log",
|
||||
"--pretty=format:%h %s (%cr)",
|
||||
|
@ -21,10 +23,10 @@ M.log = {
|
|||
"--color=never",
|
||||
}
|
||||
|
||||
if self.plugin._.updated then
|
||||
if opts.updated then
|
||||
table.insert(args, self.plugin._.updated.from .. ".." .. (self.plugin._.updated.to or "HEAD"))
|
||||
else
|
||||
table.insert(args, "--since=7 days ago")
|
||||
table.insert(args, "--since=" .. (opts.since or "7 days ago"))
|
||||
end
|
||||
|
||||
self:spawn("git", {
|
||||
|
@ -34,79 +36,125 @@ M.log = {
|
|||
end,
|
||||
}
|
||||
|
||||
M.update = {
|
||||
M.clone = {
|
||||
skip = function(plugin)
|
||||
return plugin._.installed or plugin._.is_local
|
||||
end,
|
||||
run = function(self)
|
||||
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
|
||||
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",
|
||||
}
|
||||
local git = assert(Git.info(self.plugin.dir))
|
||||
local args = {
|
||||
"clone",
|
||||
self.plugin.uri,
|
||||
"--filter=blob:none",
|
||||
"--recurse-submodules",
|
||||
"--single-branch",
|
||||
"--shallow-submodules",
|
||||
"--no-checkout",
|
||||
"--progress",
|
||||
}
|
||||
|
||||
self:spawn("git", {
|
||||
args = args,
|
||||
cwd = self.plugin.dir,
|
||||
on_exit = function(ok)
|
||||
if ok then
|
||||
local git_new = assert(Git.info(self.plugin.dir))
|
||||
self.plugin._.updated = {
|
||||
from = git.commit,
|
||||
to = git_new.commit,
|
||||
}
|
||||
self.plugin._.dirty = not vim.deep_equal(git, git_new)
|
||||
end
|
||||
end,
|
||||
})
|
||||
if self.plugin.branch then
|
||||
vim.list_extend(args, { "-b", self.plugin.branch })
|
||||
end
|
||||
|
||||
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.install = {
|
||||
run = function(self)
|
||||
if self.plugin._.is_local then
|
||||
vim.loop.fs_symlink(self.plugin.uri, self.plugin.dir, { dir = true })
|
||||
vim.opt.runtimepath:append(self.plugin.uri)
|
||||
else
|
||||
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 })
|
||||
end
|
||||
|
||||
table.insert(args, self.plugin.dir)
|
||||
self:spawn("git", {
|
||||
args = args,
|
||||
on_exit = function(ok)
|
||||
if ok then
|
||||
self.plugin._.installed = true
|
||||
self.plugin._.dirty = true
|
||||
end
|
||||
end,
|
||||
})
|
||||
M.branch = {
|
||||
skip = function(plugin)
|
||||
if not plugin._.installed or plugin._.is_local then
|
||||
return true
|
||||
end
|
||||
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,
|
||||
})
|
||||
end,
|
||||
}
|
||||
|
||||
M.fetch = {
|
||||
skip = function(plugin)
|
||||
return not plugin._.installed or plugin._.is_local
|
||||
end,
|
||||
run = function(self)
|
||||
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
|
||||
end
|
||||
|
||||
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,
|
||||
})
|
||||
end,
|
||||
}
|
||||
return M
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue