diff --git a/lua/diffs/parser.lua b/lua/diffs/parser.lua index 4490c90..2ef3030 100644 --- a/lua/diffs/parser.lua +++ b/lua/diffs/parser.lua @@ -234,6 +234,8 @@ function M.parse_buffer(bufnr) end local diff_git_file = logical:match('^diff %-%-git a/.+ b/(.+)$') + or logical:match('^diff %-%-combined (.+)$') + or logical:match('^diff %-%-cc (.+)$') local neogit_file = logical:match('^modified%s+(.+)$') or (not logical:match('^new file mode') and logical:match('^new file%s+(.+)$')) or (not logical:match('^deleted file mode') and logical:match('^deleted%s+(.+)$')) @@ -286,10 +288,17 @@ function M.parse_buffer(bufnr) new_remaining = file_new_count end else + local hs, hc = logical:match('%-(%d+),?(%d*)') + if hs then + file_old_start = tonumber(hs) + file_old_count = tonumber(hc) or 1 + old_remaining = file_old_count + end local hs2, hc2 = logical:match('%+(%d+),?(%d*) @@') if hs2 then file_new_start = tonumber(hs2) file_new_count = tonumber(hc2) or 1 + new_remaining = file_new_count end end local at_end, context = logical:match('^(@@+.-@@+%s*)(.*)') @@ -312,13 +321,12 @@ function M.parse_buffer(bufnr) end elseif logical == '' - and is_unified_diff and old_remaining and old_remaining > 0 and new_remaining and new_remaining > 0 then - table.insert(hunk_lines, ' ') + table.insert(hunk_lines, string.rep(' ', hunk_prefix_width)) old_remaining = old_remaining - 1 new_remaining = new_remaining - 1 elseif diff --git a/spec/parser_spec.lua b/spec/parser_spec.lua index 729ad16..adbbd37 100644 --- a/spec/parser_spec.lua +++ b/spec/parser_spec.lua @@ -163,10 +163,10 @@ describe('parser', function() end end) - it('stops hunk at blank line', function() + it('stops hunk at blank line when remaining counts exhausted', function() local bufnr = create_buffer({ 'M test.lua', - '@@ -1,2 +1,3 @@', + '@@ -1,1 +1,2 @@', ' local x = 1', '+local y = 2', '', @@ -529,7 +529,8 @@ describe('parser', function() assert.are.equal(1, #hunks) assert.are.equal(1, hunks[1].file_new_start) assert.are.equal(9, hunks[1].file_new_count) - assert.is_nil(hunks[1].file_old_start) + assert.are.equal(1, hunks[1].file_old_start) + assert.are.equal(3, hunks[1].file_old_count) delete_buffer(bufnr) end)