mirror of
https://github.com/neovim/neovim.git
synced 2026-06-16 00:31:16 +00:00
fix(difftool): handle filenames containing spaces #39740
Problem:
Using the `DiffTool` plugin (e.g. through `nvim -d ...` or `:DiffTool
<file1> <file2>` fails if a space is in one of the paths. This occurs
because the `diff` wraps the paths with quotes (`'`) if space
characters are present, which the line diff regex fails to parse.
Solution:
Update regex to handle quoted paths by matching the string within the
quotes, if it exists.
(cherry picked from commit 1e09b020e5)
This commit is contained in:
committed by
github-actions[bot]
parent
42f6c1c443
commit
f62ce1a42f
@@ -123,7 +123,7 @@ local function diff_dirs_diffr(left_dir, right_dir, opt)
|
||||
local qf_entries = {}
|
||||
|
||||
for _, line in ipairs(lines) do
|
||||
local modified_left, modified_right = line:match('^Files (.+) and (.+) differ$')
|
||||
local modified_left, modified_right = line:match("^Files '?(.-)'? and '?(.-)'? differ$")
|
||||
if modified_left and modified_right then
|
||||
local left_exists = vim.fn.filereadable(modified_left) == 1
|
||||
local right_exists = vim.fn.filereadable(modified_right) == 1
|
||||
|
||||
@@ -15,8 +15,10 @@ setup(function()
|
||||
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_left .. pathsep .. 'file4 with space.txt', 'hello')
|
||||
t.write_file(testdir_right .. pathsep .. 'file1.txt', 'hello world') -- modified
|
||||
t.write_file(testdir_right .. pathsep .. 'file3.txt', 'bar') -- added
|
||||
t.write_file(testdir_right .. pathsep .. 'file4 with space.txt', 'hello world') -- modified
|
||||
end)
|
||||
|
||||
teardown(function()
|
||||
@@ -42,10 +44,12 @@ describe('nvim.difftool', function()
|
||||
-- file1.txt as modified (M)
|
||||
-- file2.txt as deleted (D)
|
||||
-- file3.txt as added (A)
|
||||
-- file4 with space.txt as modified (M)
|
||||
eq({
|
||||
{ text = 'M', rel = 'file1.txt' },
|
||||
{ text = 'D', rel = 'file2.txt' },
|
||||
{ text = 'A', rel = 'file3.txt' },
|
||||
{ text = 'M', rel = 'file4 with space.txt' },
|
||||
}, entries)
|
||||
end)
|
||||
|
||||
@@ -83,6 +87,7 @@ describe('nvim.difftool', function()
|
||||
eq({
|
||||
{ text = 'M', rel = 'file1.txt' },
|
||||
{ text = 'A', rel = 'file3.txt' },
|
||||
{ text = 'M', rel = 'file4 with space.txt' },
|
||||
}, entries)
|
||||
end)
|
||||
|
||||
@@ -144,6 +149,7 @@ describe('nvim.difftool', function()
|
||||
{ text = 'M', rel = 'file1.txt' },
|
||||
{ text = 'D', rel = 'file2.txt' },
|
||||
{ text = 'A', rel = 'file3.txt' },
|
||||
{ text = 'M', rel = 'file4 with space.txt' },
|
||||
}, entries)
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user