Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/lazy.nvim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lua/lazy/core/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 21 additions & 2 deletions lua/lazy/manage/git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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, ...)
Expand Down
2 changes: 1 addition & 1 deletion lua/lazy/manage/task/git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lua/lazy/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
Loading