diff --git a/doc/lazy.nvim.txt b/doc/lazy.nvim.txt index 5441ca56..1bb4ccd8 100644 --- a/doc/lazy.nvim.txt +++ b/doc/lazy.nvim.txt @@ -371,6 +371,9 @@ SPEC VERSIONING *lazy.nvim-🔌-plugin-spec-spec-versioning* submodules boolean? When false, git submodules will not be fetched. Defaults to true + + older_than number? When non-zero, only checkout plugin to + a commit older than the number of days. ------------------------------------------------------------------------------ Refer to the Versioning <./versioning.md> section for more information. @@ -627,6 +630,10 @@ will be added to the plugin’s spec. -- default `cond` you can use to globally disable a lot of plugins -- when running inside vscode for example cond = nil, ---@type boolean|fun(self:LazyPlugin):boolean|nil + -- Only pull commits which are older that this in number of days + -- (default 0 always pulls latest while still respecting version etc) + -- can overridden per plugin as well. + older_than = 0, }, -- leave nil when passing the spec as the first argument to setup() spec = nil, ---@type LazySpec diff --git a/lua/lazy/core/config.lua b/lua/lazy/core/config.lua index b35a389b..44626947 100644 --- a/lua/lazy/core/config.lua +++ b/lua/lazy/core/config.lua @@ -17,6 +17,10 @@ M.defaults = { -- default `cond` you can use to globally disable a lot of plugins -- when running inside vscode for example cond = nil, ---@type boolean|fun(self:LazyPlugin):boolean|nil + -- Only pull commits which are older that this in number of days + -- (default 0 always pulls latest while still respecting version etc) + -- can overridden per plugin as well. + older_than = 0, }, -- leave nil when passing the spec as the first argument to setup() spec = nil, ---@type LazySpec diff --git a/lua/lazy/manage/git.lua b/lua/lazy/manage/git.lua index ef68cc72..d689d7a7 100644 --- a/lua/lazy/manage/git.lua +++ b/lua/lazy/manage/git.lua @@ -113,9 +113,20 @@ function M.get_commit(repo, branch, origin) end end +-- Return the last commit for the given branch which is older than `older_than` days +---@param repo string +---@param branch string +---@param older_than number +---@return string? +function M.get_commit_older_than(repo, branch, older_than) + local lines = Process.exec({ "git", "rev-list", branch, "-1", string.format([[--before="%d days ago"]], older_than) }, { cwd = repo }) + return lines[1] +end + ---@param plugin LazyPlugin +---@param to_update bool ---@return GitInfo? -function M.get_target(plugin) +function M.get_target(plugin, to_update) if plugin._.is_local then local info = M.info(plugin.dir) local branch = assert(info and info.branch or M.get_branch(plugin)) @@ -150,7 +161,15 @@ function M.get_target(plugin) } end end - return { branch = branch, commit = M.get_commit(plugin.dir, branch, true) } + + local older_than = Config.options.defaults.older_than or plugin.older_than + local commit + if older_than and to_update then + commit = M.get_commit_older_than(plugin.dir, branch, older_than) + else + commit = M.get_commit(plugin.dir, branch, true) + end + return { branch = branch, commit = commit } end function M.ref(repo, ...) diff --git a/lua/lazy/manage/task/git.lua b/lua/lazy/manage/task/git.lua index ef848f9c..20af91e8 100644 --- a/lua/lazy/manage/task/git.lua +++ b/lua/lazy/manage/task/git.lua @@ -317,7 +317,7 @@ M.checkout = { run = function(self, opts) throttle.wait() local info = assert(Git.info(self.plugin.dir)) - local target = assert(Git.get_target(self.plugin)) + local target = assert(Git.get_target(self.plugin, true)) -- if the plugin is pinned and we did not just clone it, -- then don't update diff --git a/lua/lazy/types.lua b/lua/lazy/types.lua index 7700229e..263c05a2 100644 --- a/lua/lazy/types.lua +++ b/lua/lazy/types.lua @@ -47,6 +47,7 @@ ---@field version? string|boolean ---@field pin? boolean ---@field submodules? boolean Defaults to true +---@field older_than? number ---@class LazyPluginBase ---@field [1] string?