feat: added "Lazy check" to check for updates without updating

This commit is contained in:
Folke Lemaitre 2022-11-29 08:23:23 +01:00
parent d486bc586b
commit 63cf2a52bd
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
4 changed files with 25 additions and 4 deletions

View File

@ -12,8 +12,8 @@
- [x] Config in multiple files - [x] Config in multiple files
- [x] Patterns for local packages - [x] Patterns for local packages
- [x] Profiling - [x] Profiling
- [ ] lockfile - [x] lockfile
- [ ] check for updates - [x] check for updates
- [ ] package.lua - [ ] package.lua
- [ ] package-lock.lua - [ ] package-lock.lua
- [x] tag/version support `git tag --sort version:refname` - [x] tag/version support `git tag --sort version:refname`

View File

@ -83,6 +83,20 @@ function M.update(opts)
end) end)
end end
function M.check(opts)
opts = opts or {}
M.run({
pipeline = {
"git.fetch",
"wait",
{ "git.log", check = true },
},
plugins = function(plugin)
return plugin.uri and plugin._.installed
end,
}, opts)
end
---@param opts? ManagerOpts ---@param opts? ManagerOpts
function M.log(opts) function M.log(opts)
M.run({ M.run({

View File

@ -6,14 +6,14 @@ local Lock = require("lazy.manage.lock")
local M = {} local M = {}
M.log = { M.log = {
---@param opts {since?: string, updated?:boolean} ---@param opts {since?: string, updated?:boolean, check?: boolean}
skip = function(plugin, opts) skip = function(plugin, opts)
if opts.updated and not (plugin._.updated and plugin._.updated.from ~= plugin._.updated.to) then if opts.updated and not (plugin._.updated and plugin._.updated.from ~= plugin._.updated.to) then
return true return true
end end
return not Util.file_exists(plugin.dir .. "/.git") return not Util.file_exists(plugin.dir .. "/.git")
end, end,
---@param opts {since?: string, updated?:boolean} ---@param opts {since?: string, updated?:boolean, check?:boolean}
run = function(self, opts) run = function(self, opts)
local args = { local args = {
"log", "log",
@ -26,6 +26,10 @@ M.log = {
if opts.updated then if opts.updated then
table.insert(args, self.plugin._.updated.from .. ".." .. (self.plugin._.updated.to or "HEAD")) table.insert(args, self.plugin._.updated.from .. ".." .. (self.plugin._.updated.to or "HEAD"))
elseif opts.check then
local info = assert(Git.info(self.plugin.dir))
local target = assert(Git.get_target(self.plugin))
table.insert(args, info.commit .. ".." .. target.commit)
else else
table.insert(args, "--since=" .. (opts.since or "7 days ago")) table.insert(args, "--since=" .. (opts.since or "7 days ago"))
end end

View File

@ -40,6 +40,9 @@ M.commands = {
update = function() update = function()
Manage.update({ clear = true, interactive = true }) Manage.update({ clear = true, interactive = true })
end, end,
check = function()
Manage.check({ clear = true, interactive = true })
end,
restore = function() restore = function()
Manage.update({ clear = true, interactive = true, lockfile = true }) Manage.update({ clear = true, interactive = true, lockfile = true })
end, end,