feat(fugitive): add section header and untracked file support
Section headers (Staged/Unstaged) now show all diffs in that section, matching fugitive's behavior. Untracked files show as all-added diffs. Deleted files show as all-removed diffs. Also handles edge cases: - Empty new/old content for deleted/new files - Section header detection returns is_header flag
This commit is contained in:
parent
ce8fe3b89b
commit
6072dd0156
3 changed files with 150 additions and 23 deletions
|
|
@ -173,5 +173,55 @@ describe('fugitive', function()
|
|||
assert.equals('unstaged', section2)
|
||||
vim.api.nvim_buf_delete(buf, { force = true })
|
||||
end)
|
||||
|
||||
it('detects section header for Staged', function()
|
||||
local buf = create_status_buffer({
|
||||
'Head: main',
|
||||
'',
|
||||
'Staged (2)',
|
||||
'M file1.lua',
|
||||
})
|
||||
local filename, section, is_header = fugitive.get_file_at_line(buf, 3)
|
||||
assert.is_nil(filename)
|
||||
assert.equals('staged', section)
|
||||
assert.is_true(is_header)
|
||||
vim.api.nvim_buf_delete(buf, { force = true })
|
||||
end)
|
||||
|
||||
it('detects section header for Unstaged', function()
|
||||
local buf = create_status_buffer({
|
||||
'Unstaged (3)',
|
||||
'M file1.lua',
|
||||
})
|
||||
local filename, section, is_header = fugitive.get_file_at_line(buf, 1)
|
||||
assert.is_nil(filename)
|
||||
assert.equals('unstaged', section)
|
||||
assert.is_true(is_header)
|
||||
vim.api.nvim_buf_delete(buf, { force = true })
|
||||
end)
|
||||
|
||||
it('detects section header for Untracked', function()
|
||||
local buf = create_status_buffer({
|
||||
'Untracked (1)',
|
||||
'? newfile.lua',
|
||||
})
|
||||
local filename, section, is_header = fugitive.get_file_at_line(buf, 1)
|
||||
assert.is_nil(filename)
|
||||
assert.equals('untracked', section)
|
||||
assert.is_true(is_header)
|
||||
vim.api.nvim_buf_delete(buf, { force = true })
|
||||
end)
|
||||
|
||||
it('returns is_header=false for file lines', function()
|
||||
local buf = create_status_buffer({
|
||||
'Staged (1)',
|
||||
'M file.lua',
|
||||
})
|
||||
local filename, section, is_header = fugitive.get_file_at_line(buf, 2)
|
||||
assert.equals('file.lua', filename)
|
||||
assert.equals('staged', section)
|
||||
assert.is_false(is_header)
|
||||
vim.api.nvim_buf_delete(buf, { force = true })
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue