summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorfleesk <48991514+fleesk@users.noreply.github.com>2026-04-22 10:46:48 +0200
committergithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>2026-04-22 09:24:45 +0000
commit6583833ee2ac86ee7a57011fc1b1143d29cf755a (patch)
tree564f7aef28db03d50d79276ce1268e66fcf5bd83
parentba3de79ccbdeb39364c026d0402502d7bdd9243e (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. (cherry picked from commit e53e728c925641397bc25969457db67189a2eb75)
-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')