summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorfleesk <48991514+fleesk@users.noreply.github.com>2026-04-22 10:46:48 +0200
committerGitHub <noreply@github.com>2026-04-22 04:46:48 -0400
commite53e728c925641397bc25969457db67189a2eb75 (patch)
treec172e7b0c748f59d9aba8058f735fb8ff664195e
parent44770bb924844700e05aef4f81850f0378183ad9 (diff)
fix(pack): GIT_DIR/GIT_WORK_TREE env vars may interfere #39279
Problem: With GIT_DIR/GIT_WORK_TREE set, the LSP on the vim.pack.update() confirmation buffer does not show the correct git log on hover. Solution: Temporarily remove the git vars from the environment.
-rw-r--r--runtime/lua/vim/pack/_lsp.lua6
-rw-r--r--test/functional/plugin/pack_spec.lua6
2 files changed, 11 insertions, 1 deletions
diff --git a/runtime/lua/vim/pack/_lsp.lua b/runtime/lua/vim/pack/_lsp.lua
index 7eedf9dfe5..a3342e9a30 100644
--- a/runtime/lua/vim/pack/_lsp.lua
+++ b/runtime/lua/vim/pack/_lsp.lua
@@ -218,7 +218,11 @@ methods['textDocument/hover'] = function(params, callback)
local res = { contents = { kind = vim.lsp.protocol.MarkupKind.Markdown, value = markdown } }
callback(nil, res)
end
- vim.system(cmd, { cwd = path }, vim.schedule_wrap(on_exit))
+
+ -- temporarily clear GIT env vars
+ local env = vim.fn.environ() --- @type table<string,string>
+ env.GIT_DIR, env.GIT_WORK_TREE = nil, nil
+ vim.system(cmd, { cwd = path, env = env, clear_env = true }, vim.schedule_wrap(on_exit))
end
local dispatchers = {}
diff --git a/test/functional/plugin/pack_spec.lua b/test/functional/plugin/pack_spec.lua
index 377bd6fbf8..5d416ea8e8 100644
--- a/test/functional/plugin/pack_spec.lua
+++ b/test/functional/plugin/pack_spec.lua
@@ -1463,6 +1463,9 @@ describe('vim.pack', function()
-- textDocument/hover
local confirm_winnr = api.nvim_get_current_win()
local function assert_hover(pos, commit_msg)
+ -- Should not be affected by special environment variables
+ fn.setenv('GIT_WORK_TREE', t.paths.test_source_path)
+ fn.setenv('GIT_DIR', vim.fs.joinpath(t.paths.test_source_path, '.git'))
api.nvim_win_set_cursor(0, pos)
exec_lua(function()
vim.lsp.buf.hover()
@@ -1482,6 +1485,9 @@ describe('vim.pack', function()
local ref_pattern = 'Marvim <marvim@neovim%.io>\nDate:.*' .. vim.pesc(commit_msg)
matches(ref_pattern, text)
+
+ exec_lua('vim.uv.os_unsetenv("GIT_WORK_TREE")')
+ exec_lua('vim.uv.os_unsetenv("GIT_DIR")')
end
assert_hover({ 14, 0 }, 'Commit from `main` to be removed')