commit cfbc03a9549017984a2ca9c139553aac1c016a42
parent a31f63f661a0c05bdec678facfc4a5fdc4630435
Author: Evgeni Chasnovski <evgeni.chasnovski@gmail.com>
Date: Sat, 4 Oct 2025 16:13:39 +0300
feat(pack)!: make `update()` include not active plugins by default
Problem: Running `update()` by default doesn't include not active
plugins, because there was no way to get relevant `version` to get
updates from. This might be a problem in presence of lazy loaded
plugins, i.e. ones that can be "not *yet* active" but still needed to
be updated.
Solution: Include not active plugins by default since their `version` is
tracked via lockfile.
Diffstat:
3 files changed, 21 insertions(+), 22 deletions(-)
diff --git a/runtime/doc/pack.txt b/runtime/doc/pack.txt
@@ -410,8 +410,7 @@ update({names}, {opts}) *vim.pack.update()*
Parameters: ~
• {names} (`string[]?`) List of plugin names to update. Must be managed
by |vim.pack|, not necessarily already added to current
- session. Default: names of all plugins added to current
- session via |vim.pack.add()|.
+ session. Default: names of all plugins managed by |vim.pack|.
• {opts} (`table?`) A table with the following fields:
• {force}? (`boolean`) Whether to skip confirmation and make
updates immediately. Default `false`.
diff --git a/runtime/lua/vim/pack.lua b/runtime/lua/vim/pack.lua
@@ -401,15 +401,8 @@ local function plug_list_from_names(names)
local plug_dir = get_plug_dir()
local plugs = {} --- @type vim.pack.Plug[]
for _, p_data in ipairs(p_data_list) do
- -- NOTE: By default include only active plugins (and not all on disk). Using
- -- not active plugins might lead to a confusion as default `version` and
- -- user's desired one might mismatch.
- -- TODO(echasnovski): Change this when there is lockfile.
- if names ~= nil or p_data.active then
- plugs[#plugs + 1] = new_plug(p_data.spec, plug_dir)
- end
+ plugs[#plugs + 1] = new_plug(p_data.spec, plug_dir)
end
-
return plugs
end
@@ -975,7 +968,7 @@ end
---
--- @param names? string[] List of plugin names to update. Must be managed
--- by |vim.pack|, not necessarily already added to current session.
---- Default: names of all plugins added to current session via |vim.pack.add()|.
+--- Default: names of all plugins managed by |vim.pack|.
--- @param opts? vim.pack.keyset.update
function M.update(names, opts)
vim.validate('names', names, vim.islist, true, 'list')
diff --git a/test/functional/plugin/pack_spec.lua b/test/functional/plugin/pack_spec.lua
@@ -847,7 +847,7 @@ describe('vim.pack', function()
-- Install initial versions of tested plugins
exec_lua(function()
vim.pack.add({
- repos_src.fetch,
+ { src = repos_src.fetch, version = 'main' },
{ src = repos_src.semver, version = 'v0.3.0' },
repos_src.defbranch,
})
@@ -865,6 +865,11 @@ describe('vim.pack', function()
repo_write_file('fetch', 'lua/fetch.lua', 'return "fetch new 2"')
git_add_commit('Commit to be added 2', 'fetch')
+
+ -- Make `dev` default remote branch to check that `version` is respected
+ git_cmd({ 'checkout', '-b', 'dev' }, 'fetch')
+ repo_write_file('fetch', 'lua/fetch.lua', 'return "fetch dev"')
+ git_add_commit('Commit from default `dev` branch', 'fetch')
end)
after_each(function()
@@ -942,8 +947,8 @@ describe('vim.pack', function()
local screen
screen = Screen.new(85, 35)
- hashes.fetch_new = git_get_hash('HEAD', 'fetch')
- hashes.fetch_new_prev = git_get_hash('HEAD~', 'fetch')
+ hashes.fetch_new = git_get_hash('main', 'fetch')
+ hashes.fetch_new_prev = git_get_hash('main~', 'fetch')
hashes.semver_head = git_get_hash('v0.3.0', 'semver')
local tab_name = 'n' .. (t.is_os('win') and ':' or '') .. '//2/confirm-update'
@@ -1186,15 +1191,16 @@ describe('vim.pack', function()
exec_lua('vim.pack.update()')
n.exec('write')
- ref_fetch_lock.rev = git_get_hash('HEAD', 'fetch')
+ ref_fetch_lock.rev = git_get_hash('main', 'fetch')
eq(ref_fetch_lock, get_lock_tbl().plugins.fetch)
end)
end)
it('works with not active plugins', function()
+ -- No plugins are added, but they are installed in `before_each()`
exec_lua(function()
- -- No plugins are added, but they are installed in `before_each()`
- vim.pack.update({ 'fetch' })
+ -- By default should also include not active plugins
+ vim.pack.update()
end)
eq({ 'return "fetch main"' }, fn.readfile(fetch_lua_file))
n.exec('write')
@@ -1218,8 +1224,8 @@ describe('vim.pack', function()
eq('', api.nvim_get_option_value('filetype', {}))
-- Write to log file
- hashes.fetch_new = git_get_hash('HEAD', 'fetch')
- hashes.fetch_new_prev = git_get_hash('HEAD~', 'fetch')
+ hashes.fetch_new = git_get_hash('main', 'fetch')
+ hashes.fetch_new_prev = git_get_hash('main~', 'fetch')
local log_path = vim.fs.joinpath(fn.stdpath('log'), 'nvim-pack.log')
local log_lines = fn.readfile(log_path)
@@ -1242,18 +1248,19 @@ describe('vim.pack', function()
eq(ref_log_lines, vim.list_slice(log_lines, 2))
-- Should update lockfile
- eq(git_get_hash('HEAD', 'fetch'), get_lock_tbl().plugins.fetch.rev)
+ eq(hashes.fetch_new, get_lock_tbl().plugins.fetch.rev)
end)
it('shows progress report', function()
track_nvim_echo()
exec_lua(function()
vim.pack.add({ repos_src.fetch, repos_src.defbranch })
+ -- Should also include updates from not active plugins
vim.pack.update()
end)
-- During initial download
- validate_progress_report('Downloading updates', { 'fetch', 'defbranch' })
+ validate_progress_report('Downloading updates', { 'fetch', 'defbranch', 'semver' })
exec_lua('_G.echo_log = {}')
-- During application (only for plugins that have updates)
@@ -1270,7 +1277,7 @@ describe('vim.pack', function()
vim.pack.add({ repos_src.fetch, repos_src.defbranch })
vim.pack.update(nil, { force = true })
end)
- validate_progress_report('Updating', { 'fetch', 'defbranch' })
+ validate_progress_report('Updating', { 'fetch', 'defbranch', 'semver' })
end)
it('triggers relevant events', function()