feat: Enable commit inspection for recent commits and stashes.

Adjusts the diff parser to handle the combined diff format (used for
i.e. merge commits and stashes).
This commit is contained in:
Sindre T. Strøm 2021-10-24 23:33:16 +02:00
parent 24b7a773e4
commit c94549f3c3
2 changed files with 11 additions and 4 deletions

View file

@ -50,7 +50,7 @@ local function parse_diff(output, with_stats)
local header = {}
for i=start_idx,#output do
if output[i]:match('^@@.*@@') then
if output[i]:match('^@@@*.*@@@*') then
start_idx = i
break
end
@ -86,7 +86,14 @@ local function parse_diff(output, with_stats)
for i=1,len do
local line = diff.lines[i]
if not vim.startswith(line, "+++") then
local index_from, index_len, disk_from, disk_len = line:match('@@ %-(%d+),?(%d*) %+(%d+),?(%d*) @@')
local index_from, index_len, disk_from, disk_len
if vim.startswith(line, "@@@") then
-- Combined diff header
index_from, index_len, disk_from, disk_len = line:match('@@@* %-(%d+),?(%d*) .* %+(%d+),?(%d*) @@@*')
else
-- Normal diff header
index_from, index_len, disk_from, disk_len = line:match('@@ %-(%d+),?(%d*) %+(%d+),?(%d*) @@')
end
if index_from then
if hunk ~= nil then

View file

@ -804,11 +804,11 @@ local cmd_func_map = function ()
local relpath = vim.fn.fnamemodify(repo_root .. '/' .. path, ':.')
vim.cmd("e " .. relpath)
elseif section.name == "unpulled" or section.name == "unmerged" then
elseif vim.tbl_contains({ "unmerged", "unpulled", "recent", "stashes" }, section.name) then
if M.commit_view and M.commit_view.is_open then
M.commit_view:close()
end
M.commit_view = CommitView.new(item.name:match("(.-) "), true)
M.commit_view = CommitView.new(item.name:match("(.-):? "), true)
M.commit_view:open()
else
return