fix(commands): filter combined diffs from section output
Problem: git diff produces diff --cc (combined format) for unmerged files. This format uses @@@ triple-at headers and multi-column prefixes that the parser cannot handle, resulting in no highlighting when pressing du on a section header in a repo with merge conflicts. Solution: add filter_combined_diffs() to strip diff --cc entries from raw git diff output in both gdiff_section and read_buffer, leaving only standard unified diffs that the parser understands.
This commit is contained in:
parent
92209721c8
commit
93ee38db8c
1 changed files with 22 additions and 0 deletions
|
|
@ -36,6 +36,24 @@ function M.find_hunk_line(diff_lines, hunk_position)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param lines string[]
|
||||||
|
---@return string[]
|
||||||
|
local function filter_combined_diffs(lines)
|
||||||
|
local result = {}
|
||||||
|
local skip = false
|
||||||
|
for _, line in ipairs(lines) do
|
||||||
|
if line:match('^diff %-%-cc ') then
|
||||||
|
skip = true
|
||||||
|
elseif line:match('^diff %-%-git ') then
|
||||||
|
skip = false
|
||||||
|
end
|
||||||
|
if not skip then
|
||||||
|
table.insert(result, line)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
---@param old_lines string[]
|
---@param old_lines string[]
|
||||||
---@param new_lines string[]
|
---@param new_lines string[]
|
||||||
---@param old_name string
|
---@param old_name string
|
||||||
|
|
@ -282,6 +300,8 @@ function M.gdiff_section(repo_root, opts)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
result = filter_combined_diffs(result)
|
||||||
|
|
||||||
if #result == 0 then
|
if #result == 0 then
|
||||||
vim.notify('[diffs.nvim]: no changes in section', vim.log.levels.INFO)
|
vim.notify('[diffs.nvim]: no changes in section', vim.log.levels.INFO)
|
||||||
return
|
return
|
||||||
|
|
@ -344,6 +364,8 @@ function M.read_buffer(bufnr)
|
||||||
if vim.v.shell_error ~= 0 then
|
if vim.v.shell_error ~= 0 then
|
||||||
diff_lines = {}
|
diff_lines = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
diff_lines = filter_combined_diffs(diff_lines)
|
||||||
else
|
else
|
||||||
local abs_path = repo_root .. '/' .. path
|
local abs_path = repo_root .. '/' .. path
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue