Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,5 @@ See the documentation for more information.
decoration provider highlighting architecture, gitsigns blame popup
highlighting, intra-line bg visibility fix
- [@tris203](https://github.com/tris203) - support for transparent backgrounds
- [@letientai299](https://github.com/letientai299) - `diff.mnemonicPrefix`
support
2 changes: 1 addition & 1 deletion lua/diffs/parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ function M.parse_buffer(bufnr)
end
end

local diff_git_file = logical:match('^diff %-%-git a/.+ b/(.+)$')
local diff_git_file = logical:match('^diff %-%-git %a/.+ %a/(.+)$')
or logical:match('^diff %-%-combined (.+)$')
or logical:match('^diff %-%-cc (.+)$')
local neogit_file = logical:match('^modified%s+(.+)$')
Expand Down
53 changes: 53 additions & 0 deletions spec/parser_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,59 @@ describe('parser', function()
delete_buffer(bufnr)
end)

it('extracts filename with mnemonic prefix c/ i/', function()
local bufnr = create_buffer({
'diff --git c/init.lua i/init.lua',
'index 3e8afa0..018159c 100644',
'--- c/init.lua',
'+++ i/init.lua',
'@@ -1,1 +1,2 @@',
' local M = {}',
'+local x = 1',
})
local hunks = parser.parse_buffer(bufnr)

assert.are.equal(1, #hunks)
assert.are.equal('init.lua', hunks[1].filename)
assert.are.equal('lua', hunks[1].ft)
assert.are.equal('lua', hunks[1].lang)
delete_buffer(bufnr)
end)

it('extracts filename with mnemonic prefix w/ i/', function()
local bufnr = create_buffer({
'diff --git w/src/main.lua i/src/main.lua',
'index abc1234..def5678 100644',
'--- w/src/main.lua',
'+++ i/src/main.lua',
'@@ -1,1 +1,2 @@',
' local M = {}',
'+local y = 2',
})
local hunks = parser.parse_buffer(bufnr)

assert.are.equal(1, #hunks)
assert.are.equal('src/main.lua', hunks[1].filename)
delete_buffer(bufnr)
end)

it('rejects non-letter prefix in diff header', function()
local bufnr = create_buffer({
'diff --git 1/init.lua 2/init.lua',
'index 3e8afa0..018159c 100644',
'--- 1/init.lua',
'+++ 2/init.lua',
'@@ -1,1 +1,2 @@',
' local M = {}',
'+local x = 1',
})
local hunks = parser.parse_buffer(bufnr)

assert.are.equal(1, #hunks)
assert.is_nil(hunks[1].filename)
delete_buffer(bufnr)
end)

it('handles fugitive status format with diff headers', function()
local bufnr = create_buffer({
'Head: main',
Expand Down
Loading