mirror of
https://github.com/neovim/neovim.git
synced 2025-12-12 01:22:41 +00:00
fix(pack)!: ensure plugin is fully absent if not fully installed
Problem: Currently it is possible to have plugin in a "partial install" state when `git clone` was successfull but `git checkout` was not. This was done to not checkout default branch by default in these situations (for security reasons). The problem is that it adds complexity when both dealing with lockfile (plugin's `rev` might be `nil`) and in how `src` and `version` are treated (wrong `src` - no plugin on disk; wrong `version` - "partial" plugin on disk). Solution: Treat plugin as "installed" if both `git clone` and `git checkout` are successful, while ensuring that not installed plugins are not on disk and in lockfile. This also means that if in 'init.lua' there is a `vim.pack.add()` with bad `version`, for first install there will be an informative error about it BUT next session will also try to install it. The solution is the same - adjust `version` beforehand.
This commit is contained in:
@@ -677,7 +677,6 @@ local function install_list(plug_list, confirm)
|
||||
trigger_event(p, 'PackChangedPre', 'install')
|
||||
|
||||
git_clone(p.spec.src, p.path)
|
||||
p.info.installed = true
|
||||
|
||||
plugin_lock.plugins[p.spec.name].src = p.spec.src
|
||||
|
||||
@@ -685,6 +684,7 @@ local function install_list(plug_list, confirm)
|
||||
p.info.sha_target = (plugin_lock.plugins[p.spec.name] or {}).rev
|
||||
|
||||
checkout(p, timestamp)
|
||||
p.info.installed = true
|
||||
|
||||
trigger_event(p, 'PackChanged', 'install')
|
||||
end
|
||||
@@ -694,10 +694,11 @@ local function install_list(plug_list, confirm)
|
||||
run_list(plug_list, do_install, 'Installing plugins')
|
||||
end
|
||||
|
||||
-- Ensure that not installed plugins are absent in lockfile
|
||||
-- Ensure that not fully installed plugins are absent on disk and in lockfile
|
||||
for _, p in ipairs(plug_list) do
|
||||
if not p.info.installed then
|
||||
plugin_lock.plugins[p.spec.name] = nil
|
||||
vim.fs.rm(p.path, { recursive = true, force = true })
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -800,7 +801,8 @@ end
|
||||
--- immediately to clean install from the new source. Otherwise do nothing.
|
||||
--- - If doesn't exist, install it by downloading from `src` into `name`
|
||||
--- subdirectory (via partial blobless `git clone`) and update revision
|
||||
--- to match `version` (via `git checkout`).
|
||||
--- to match `version` (via `git checkout`). Plugin will not be on disk if
|
||||
--- any step resulted in an error.
|
||||
--- - For each plugin execute |:packadd| (or customizable `load` function) making
|
||||
--- it reachable by Nvim.
|
||||
---
|
||||
|
||||
Reference in New Issue
Block a user