mirror of
https://github.com/neovim/neovim.git
synced 2026-05-06 08:26:45 -04:00
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 e53e728c92)
This commit is contained in:
committed by
github-actions[bot]
parent
ba3de79ccb
commit
6583833ee2
@@ -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 = {}
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user