fix(lockfile): keep cond=false and enabed=false in lockfile. Fixes #1535. Fixes #1606

This commit is contained in:
Folke Lemaitre 2024-07-05 09:01:01 +02:00
parent 407e65c792
commit baac551777
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
1 changed files with 28 additions and 27 deletions

View File

@ -3,50 +3,53 @@ local Git = require("lazy.manage.git")
local M = {} local M = {}
---@type table<string, {commit:string, branch:string}> ---@alias LazyLockfile table<string, {commit:string, branch:string}>
---@type LazyLockfile
M.lock = {} M.lock = {}
M._loaded = false M._loaded = false
function M.update() function M.update()
M.load()
vim.fn.mkdir(vim.fn.fnamemodify(Config.options.lockfile, ":p:h"), "p") vim.fn.mkdir(vim.fn.fnamemodify(Config.options.lockfile, ":p:h"), "p")
local f = assert(io.open(Config.options.lockfile, "wb")) local f = assert(io.open(Config.options.lockfile, "wb"))
f:write("{\n") f:write("{\n")
M.lock = {}
---@param plugin LazyPlugin -- keep disabled and cond plugins
local plugins = vim.tbl_filter(function(plugin) for name in pairs(M.lock) do
return not plugin._.is_local and plugin._.installed if not (Config.spec.disabled[name] or Config.spec.ignore_installed[name]) then
end, Config.plugins) M.lock[name] = nil
end
end
for _, plugin in pairs(Config.plugins) do
if not plugin._.is_local and plugin._.installed then
local info = assert(Git.info(plugin.dir))
M.lock[plugin.name] = {
branch = info.branch or assert(Git.get_branch(plugin)),
commit = assert(info.commit, "commit is nil"),
}
end
end
---@param plugin LazyPlugin
---@type string[] ---@type string[]
local names = vim.tbl_map(function(plugin) local names = vim.tbl_keys(M.lock)
return plugin.name
end, plugins)
table.sort(names) table.sort(names)
for n, name in ipairs(names) do for n, name in ipairs(names) do
local plugin = Config.plugins[name] local info = M.lock[name]
if not plugin._.is_local and plugin._.installed then
local info = assert(Git.info(plugin.dir))
if not info.branch then
info.branch = assert(Git.get_branch(plugin))
end
info.commit = info.commit
-- f:write(([[ [%q] = { branch = %q, commit = %q },]]):format(name, info.branch, info.commit) .. "\n")
f:write(([[ %q: { "branch": %q, "commit": %q }]]):format(name, info.branch, info.commit)) f:write(([[ %q: { "branch": %q, "commit": %q }]]):format(name, info.branch, info.commit))
if n ~= #names then if n ~= #names then
f:write(",\n") f:write(",\n")
end end
---@diagnostic disable-next-line: assign-type-mismatch
M.lock[plugin.name] = info
end
end end
f:write("\n}") f:write("\n}")
f:close() f:close()
end end
function M.load() function M.load()
if M._loaded then
return
end
M.lock = {} M.lock = {}
M._loaded = true M._loaded = true
local f = io.open(Config.options.lockfile, "r") local f = io.open(Config.options.lockfile, "r")
@ -64,9 +67,7 @@ end
---@param plugin LazyPlugin ---@param plugin LazyPlugin
---@return {commit:string, branch:string} ---@return {commit:string, branch:string}
function M.get(plugin) function M.get(plugin)
if not M._loaded then
M.load() M.load()
end
return M.lock[plugin.name] return M.lock[plugin.name]
end end