mirror of
https://github.com/neovim/neovim.git
synced 2025-10-16 06:46:07 +00:00
feat(plugins): nvim.difftool can compare directories #35448
Problem: Built-in diff mode (nvim -d) does not support directory diffing as required by git difftool -d. This makes it difficult to compare entire directories, detect renames, and navigate changes efficiently. Solution: Add a DiffTool plugin and command that enables side-by-side diffing of files and directories in Neovim. The plugin supports rename detection, highlights changes in the quickfix list, and provides a user command for easy invocation. This allows proper integration with git difftool -d for directory comparison. Example git config: ```ini [diff] tool = nvim_difftool [difftool "nvim_difftool"] cmd = nvim -c "packadd nvim.difftool" -c "DiffTool $LOCAL $REMOTE" ``` Signed-off-by: Tomas Slusny <slusnucky@gmail.com> Co-authored-by: Phạm Bình An <111893501+brianhuster@users.noreply.github.com> Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
This commit is contained in:
64
test/functional/plugin/difftool_spec.lua
Normal file
64
test/functional/plugin/difftool_spec.lua
Normal file
@@ -0,0 +1,64 @@
|
||||
local t = require('test.testutil')
|
||||
local n = require('test.functional.testnvim')()
|
||||
|
||||
local clear = n.clear
|
||||
local command = n.command
|
||||
local eq = t.eq
|
||||
local fn = n.fn
|
||||
|
||||
local pathsep = n.get_pathsep()
|
||||
local testdir_left = 'Xtest-difftool-left'
|
||||
local testdir_right = 'Xtest-difftool-right'
|
||||
|
||||
setup(function()
|
||||
n.mkdir_p(testdir_left)
|
||||
n.mkdir_p(testdir_right)
|
||||
t.write_file(testdir_left .. pathsep .. 'file1.txt', 'hello')
|
||||
t.write_file(testdir_left .. pathsep .. 'file2.txt', 'foo')
|
||||
t.write_file(testdir_right .. pathsep .. 'file1.txt', 'hello world') -- modified
|
||||
t.write_file(testdir_right .. pathsep .. 'file3.txt', 'bar') -- added
|
||||
end)
|
||||
|
||||
teardown(function()
|
||||
n.rmdir(testdir_left)
|
||||
n.rmdir(testdir_right)
|
||||
end)
|
||||
|
||||
describe('nvim.difftool', function()
|
||||
before_each(function()
|
||||
clear()
|
||||
command('packadd nvim.difftool')
|
||||
end)
|
||||
|
||||
it('shows added, modified, and deleted files in quickfix', function()
|
||||
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
|
||||
|
||||
-- Should show:
|
||||
-- file1.txt as modified (M)
|
||||
-- file2.txt as deleted (D)
|
||||
-- file3.txt as added (A)
|
||||
eq({
|
||||
{ text = 'M', rel = 'file1.txt' },
|
||||
{ text = 'D', rel = 'file2.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' })
|
||||
assert(#autocmds > 0)
|
||||
end)
|
||||
|
||||
it('cleans up autocmds when diff window is closed', function()
|
||||
command(('DiffTool %s %s'):format(testdir_left, testdir_right))
|
||||
command('q')
|
||||
local ok = pcall(fn.nvim_get_autocmds, { group = 'nvim.difftool.events' })
|
||||
eq(false, ok)
|
||||
end)
|
||||
end)
|
Reference in New Issue
Block a user