diff --git a/runtime/doc/pack.txt b/runtime/doc/pack.txt index aa3fdfb5fb..8ba0e3a68b 100644 --- a/runtime/doc/pack.txt +++ b/runtime/doc/pack.txt @@ -375,7 +375,8 @@ add({specs}, {opts}) *vim.pack.add()* 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`). + 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. diff --git a/runtime/lua/vim/pack.lua b/runtime/lua/vim/pack.lua index dfcc732d80..bb5b5640eb 100644 --- a/runtime/lua/vim/pack.lua +++ b/runtime/lua/vim/pack.lua @@ -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. --- diff --git a/test/functional/plugin/pack_spec.lua b/test/functional/plugin/pack_spec.lua index e75f586d38..aad3dcddb5 100644 --- a/test/functional/plugin/pack_spec.lua +++ b/test/functional/plugin/pack_spec.lua @@ -575,10 +575,9 @@ describe('vim.pack', function() local pluginerr_hash = git_get_hash('main', 'pluginerr') local ref_lockfile = { - -- Should be no entry for `repo_not_exist` + -- Should be no entry for `repo_not_exist` and `basic` as they did not + -- fully install plugins = { - -- No `rev` because there was no relevant checkout - basic = { src = repos_src.basic, version = "'not-exist'" }, -- Error during sourcing 'plugin/' should not affect lockfile pluginerr = { rev = pluginerr_hash, src = repos_src.pluginerr, version = "'main'" }, }, @@ -605,14 +604,12 @@ describe('vim.pack', function() eq(false, vim.tbl_contains(rtp, after_dir)) end) - it('does not checkout on bad `version`', function() + it('does not install on bad `version`', function() local err = pcall_err(exec_lua, function() vim.pack.add({ { src = repos_src.basic, version = 'not-exist' } }) end) matches('`not%-exist` is not a branch/tag/commit', err) - local plug_path = pack_get_plug_path('basic') - local entries = vim.iter(vim.fs.dir(plug_path)):totable() - eq({ { '.git', 'directory' } }, entries) + eq(false, pack_exists('basic')) end) it('allows changing `src` of installed plugin', function()