mirror of
https://github.com/neovim/neovim.git
synced 2025-10-06 09:56:31 +00:00
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.
This commit is contained in:
@@ -410,8 +410,7 @@ update({names}, {opts}) *vim.pack.update()*
|
|||||||
Parameters: ~
|
Parameters: ~
|
||||||
• {names} (`string[]?`) List of plugin names to update. Must be managed
|
• {names} (`string[]?`) List of plugin names to update. Must be managed
|
||||||
by |vim.pack|, not necessarily already added to current
|
by |vim.pack|, not necessarily already added to current
|
||||||
session. Default: names of all plugins added to current
|
session. Default: names of all plugins managed by |vim.pack|.
|
||||||
session via |vim.pack.add()|.
|
|
||||||
• {opts} (`table?`) A table with the following fields:
|
• {opts} (`table?`) A table with the following fields:
|
||||||
• {force}? (`boolean`) Whether to skip confirmation and make
|
• {force}? (`boolean`) Whether to skip confirmation and make
|
||||||
updates immediately. Default `false`.
|
updates immediately. Default `false`.
|
||||||
|
@@ -401,15 +401,8 @@ local function plug_list_from_names(names)
|
|||||||
local plug_dir = get_plug_dir()
|
local plug_dir = get_plug_dir()
|
||||||
local plugs = {} --- @type vim.pack.Plug[]
|
local plugs = {} --- @type vim.pack.Plug[]
|
||||||
for _, p_data in ipairs(p_data_list) do
|
for _, p_data in ipairs(p_data_list) do
|
||||||
-- NOTE: By default include only active plugins (and not all on disk). Using
|
plugs[#plugs + 1] = new_plug(p_data.spec, plug_dir)
|
||||||
-- 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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return plugs
|
return plugs
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -975,7 +968,7 @@ end
|
|||||||
---
|
---
|
||||||
--- @param names? string[] List of plugin names to update. Must be managed
|
--- @param names? string[] List of plugin names to update. Must be managed
|
||||||
--- by |vim.pack|, not necessarily already added to current session.
|
--- 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
|
--- @param opts? vim.pack.keyset.update
|
||||||
function M.update(names, opts)
|
function M.update(names, opts)
|
||||||
vim.validate('names', names, vim.islist, true, 'list')
|
vim.validate('names', names, vim.islist, true, 'list')
|
||||||
|
@@ -847,7 +847,7 @@ describe('vim.pack', function()
|
|||||||
-- Install initial versions of tested plugins
|
-- Install initial versions of tested plugins
|
||||||
exec_lua(function()
|
exec_lua(function()
|
||||||
vim.pack.add({
|
vim.pack.add({
|
||||||
repos_src.fetch,
|
{ src = repos_src.fetch, version = 'main' },
|
||||||
{ src = repos_src.semver, version = 'v0.3.0' },
|
{ src = repos_src.semver, version = 'v0.3.0' },
|
||||||
repos_src.defbranch,
|
repos_src.defbranch,
|
||||||
})
|
})
|
||||||
@@ -865,6 +865,11 @@ describe('vim.pack', function()
|
|||||||
|
|
||||||
repo_write_file('fetch', 'lua/fetch.lua', 'return "fetch new 2"')
|
repo_write_file('fetch', 'lua/fetch.lua', 'return "fetch new 2"')
|
||||||
git_add_commit('Commit to be added 2', 'fetch')
|
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)
|
end)
|
||||||
|
|
||||||
after_each(function()
|
after_each(function()
|
||||||
@@ -942,8 +947,8 @@ describe('vim.pack', function()
|
|||||||
local screen
|
local screen
|
||||||
screen = Screen.new(85, 35)
|
screen = Screen.new(85, 35)
|
||||||
|
|
||||||
hashes.fetch_new = git_get_hash('HEAD', 'fetch')
|
hashes.fetch_new = git_get_hash('main', 'fetch')
|
||||||
hashes.fetch_new_prev = git_get_hash('HEAD~', 'fetch')
|
hashes.fetch_new_prev = git_get_hash('main~', 'fetch')
|
||||||
hashes.semver_head = git_get_hash('v0.3.0', 'semver')
|
hashes.semver_head = git_get_hash('v0.3.0', 'semver')
|
||||||
|
|
||||||
local tab_name = 'n' .. (t.is_os('win') and ':' or '') .. '//2/confirm-update'
|
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()')
|
exec_lua('vim.pack.update()')
|
||||||
n.exec('write')
|
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)
|
eq(ref_fetch_lock, get_lock_tbl().plugins.fetch)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('works with not active plugins', function()
|
it('works with not active plugins', function()
|
||||||
|
-- No plugins are added, but they are installed in `before_each()`
|
||||||
exec_lua(function()
|
exec_lua(function()
|
||||||
-- No plugins are added, but they are installed in `before_each()`
|
-- By default should also include not active plugins
|
||||||
vim.pack.update({ 'fetch' })
|
vim.pack.update()
|
||||||
end)
|
end)
|
||||||
eq({ 'return "fetch main"' }, fn.readfile(fetch_lua_file))
|
eq({ 'return "fetch main"' }, fn.readfile(fetch_lua_file))
|
||||||
n.exec('write')
|
n.exec('write')
|
||||||
@@ -1218,8 +1224,8 @@ describe('vim.pack', function()
|
|||||||
eq('', api.nvim_get_option_value('filetype', {}))
|
eq('', api.nvim_get_option_value('filetype', {}))
|
||||||
|
|
||||||
-- Write to log file
|
-- Write to log file
|
||||||
hashes.fetch_new = git_get_hash('HEAD', 'fetch')
|
hashes.fetch_new = git_get_hash('main', 'fetch')
|
||||||
hashes.fetch_new_prev = git_get_hash('HEAD~', 'fetch')
|
hashes.fetch_new_prev = git_get_hash('main~', 'fetch')
|
||||||
|
|
||||||
local log_path = vim.fs.joinpath(fn.stdpath('log'), 'nvim-pack.log')
|
local log_path = vim.fs.joinpath(fn.stdpath('log'), 'nvim-pack.log')
|
||||||
local log_lines = fn.readfile(log_path)
|
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))
|
eq(ref_log_lines, vim.list_slice(log_lines, 2))
|
||||||
|
|
||||||
-- Should update lockfile
|
-- 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)
|
end)
|
||||||
|
|
||||||
it('shows progress report', function()
|
it('shows progress report', function()
|
||||||
track_nvim_echo()
|
track_nvim_echo()
|
||||||
exec_lua(function()
|
exec_lua(function()
|
||||||
vim.pack.add({ repos_src.fetch, repos_src.defbranch })
|
vim.pack.add({ repos_src.fetch, repos_src.defbranch })
|
||||||
|
-- Should also include updates from not active plugins
|
||||||
vim.pack.update()
|
vim.pack.update()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- During initial download
|
-- During initial download
|
||||||
validate_progress_report('Downloading updates', { 'fetch', 'defbranch' })
|
validate_progress_report('Downloading updates', { 'fetch', 'defbranch', 'semver' })
|
||||||
exec_lua('_G.echo_log = {}')
|
exec_lua('_G.echo_log = {}')
|
||||||
|
|
||||||
-- During application (only for plugins that have updates)
|
-- 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.add({ repos_src.fetch, repos_src.defbranch })
|
||||||
vim.pack.update(nil, { force = true })
|
vim.pack.update(nil, { force = true })
|
||||||
end)
|
end)
|
||||||
validate_progress_report('Updating', { 'fetch', 'defbranch' })
|
validate_progress_report('Updating', { 'fetch', 'defbranch', 'semver' })
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('triggers relevant events', function()
|
it('triggers relevant events', function()
|
||||||
|
Reference in New Issue
Block a user