fix(difftool): fully resolve symlinks when comparing paths #36147

Fixes issue on mac where it was constantly reloading buffers as paths
were not being normalized and resolved correctly (in relation to buffer
name).

Quickfix entry:
/var/folders/pt/2s7dzyw12v36tsslrghfgpkr0000gn/T/git-difftool.m95lj8/right/app.vue

Buffer name:
/private/var/folders/pt/2s7dzyw12v36tsslrghfgpkr0000gn/T/git-difftool.m95lj8/right/app.vue

/var was synlinked to /private/var and this was not being properly
handled.

Also added lazy redraw to avoid too many redraws when this happens in
future and added test for symlink handling.

Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
Tomas Slusny
2025-10-12 20:25:14 +02:00
committed by GitHub
parent 638d44ded8
commit c6113da5a9
3 changed files with 52 additions and 10 deletions

View File

@@ -61,6 +61,31 @@ describe('nvim.difftool', function()
)
end)
it('handles symlinks', function()
-- Create a symlink in right dir pointing to file2.txt in left dir
local symlink_path = vim.fs.joinpath(testdir_right, 'file2.txt')
local target_path = vim.fs.joinpath('..', testdir_left, 'file2.txt')
assert(vim.uv.fs_symlink(target_path, symlink_path) == true)
finally(function()
os.remove(symlink_path)
end)
assert(fn.getftype(symlink_path) == 'link')
-- Run difftool
command(('DiffTool %s %s'):format(testdir_left, testdir_right))
local qflist = fn.getqflist()
local entries = {}
for _, item in ipairs(qflist) do
table.insert(entries, { text = item.text, rel = item.user_data and item.user_data.rel })
end
-- file2.txt should not be reported as added or deleted anymore
eq({
{ text = 'M', rel = 'file1.txt' },
{ text = 'A', rel = 'file3.txt' },
}, entries)
end)
it('has autocmds when diff window is opened', function()
command(('DiffTool %s %s'):format(testdir_left, testdir_right))
local autocmds = fn.nvim_get_autocmds({ group = 'nvim.difftool.events' })