fix(fugitive): handle git-quoted filenames in status buffer

Problem: git quotes filenames containing spaces, unicode, or special
characters (e.g. M  "path with spaces/file.lua"). parse_file_line
passed the quotes through, causing file-not-found on diff operations.

Solution: add unquote() helper that strips surrounding quotes and
unescapes \\, \", \n, \t, and octal \NNN sequences. Apply it to both
filename returns in parse_file_line.
This commit is contained in:
Barrett Ruth 2026-02-09 13:53:02 -05:00
parent f5a090baae
commit 603c966c71
2 changed files with 98 additions and 2 deletions

View file

@ -243,6 +243,57 @@ describe('fugitive', function()
vim.api.nvim_buf_delete(buf, { force = true })
end)
it('unquotes git-quoted filenames with spaces', function()
local buf = create_status_buffer({
'Unstaged (1)',
'M "path with spaces/file.lua"',
})
local filename = fugitive.get_file_at_line(buf, 2)
assert.equals('path with spaces/file.lua', filename)
vim.api.nvim_buf_delete(buf, { force = true })
end)
it('unquotes escaped quotes in filenames', function()
local buf = create_status_buffer({
'Unstaged (1)',
'M "file\\"name.lua"',
})
local filename = fugitive.get_file_at_line(buf, 2)
assert.equals('file"name.lua', filename)
vim.api.nvim_buf_delete(buf, { force = true })
end)
it('unquotes octal escapes in filenames', function()
local buf = create_status_buffer({
'Unstaged (1)',
'M "\\303\\251le.lua"',
})
local filename = fugitive.get_file_at_line(buf, 2)
assert.equals('\195\169le.lua', filename)
vim.api.nvim_buf_delete(buf, { force = true })
end)
it('passes through unquoted filenames unchanged', function()
local buf = create_status_buffer({
'Unstaged (1)',
'M normal.lua',
})
local filename = fugitive.get_file_at_line(buf, 2)
assert.equals('normal.lua', filename)
vim.api.nvim_buf_delete(buf, { force = true })
end)
it('unquotes renamed files with quotes', function()
local buf = create_status_buffer({
'Staged (1)',
'R100 "old name.lua" -> "new name.lua"',
})
local filename, _, _, old_filename = fugitive.get_file_at_line(buf, 2)
assert.equals('new name.lua', filename)
assert.equals('old name.lua', old_filename)
vim.api.nvim_buf_delete(buf, { force = true })
end)
it('handles deeply nested paths', function()
local buf = create_status_buffer({
'Unstaged (1)',