commit 8f0b8a2c279f42d5af83b7517e4a19cacd21bfbe
parent 025c0c34ce597484db01850cc1576b488bc84986
Author: Evgeni Chasnovski <evgeni.chasnovski@gmail.com>
Date: Mon, 12 Jan 2026 15:53:36 +0200
fix(pack): skip `git stash` during install
Problem: Installing plugin is done via `git clone --no-checkout ...`
(to not end up with default branch code in case of invalid `version`).
This leaves cloned repo in a state that `git stash` will actually add
an entry to the stash list. Although not critical, better to not have
that if possible.
Solution: explicitly skip `git stash` step in checkout during install.
Diffstat:
2 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/runtime/lua/vim/pack.lua b/runtime/lua/vim/pack.lua
@@ -654,15 +654,18 @@ end
--- @async
--- @param p vim.pack.Plug
--- @param timestamp string
-local function checkout(p, timestamp)
+--- @param skip_stash? boolean
+local function checkout(p, timestamp, skip_stash)
infer_revisions(p)
- local stash_cmd = { 'stash', '--quiet' }
- if git_version > vim.version.parse('2.13') then
- stash_cmd[#stash_cmd + 1] = '--message'
- stash_cmd[#stash_cmd + 1] = ('vim.pack: %s Stash before checkout'):format(timestamp)
+ if not skip_stash then
+ local stash_cmd = { 'stash', '--quiet' }
+ if git_version > vim.version.parse('2.13') then
+ stash_cmd[#stash_cmd + 1] = '--message'
+ stash_cmd[#stash_cmd + 1] = ('vim.pack: %s Stash before checkout'):format(timestamp)
+ end
+ git_cmd(stash_cmd, p.path)
end
- git_cmd(stash_cmd, p.path)
git_cmd({ 'checkout', '--quiet', p.info.sha_target }, p.path)
@@ -691,7 +694,7 @@ local function install_list(plug_list, confirm)
-- Prefer revision from the lockfile instead of using `version`
p.info.sha_target = (plugin_lock.plugins[p.spec.name] or {}).rev
- checkout(p, timestamp)
+ checkout(p, timestamp, true)
p.info.installed = true
trigger_event(p, 'PackChanged', 'install')
diff --git a/test/functional/plugin/pack_spec.lua b/test/functional/plugin/pack_spec.lua
@@ -369,6 +369,11 @@ describe('vim.pack', function()
vim.pack.add({ repos_src.basic })
end)
eq(exec_lua('return #_G.event_log'), 0)
+
+ -- Should not create redundant stash entry
+ local basic_path = pack_get_plug_path('basic')
+ local stash_list = system_sync({ 'git', 'stash', 'list' }, { cwd = basic_path }).stdout or ''
+ eq('', stash_list)
end)
it('passes `data` field through to `opts.load`', function()