feat: add :Gdiff, :Gvdiff, :Ghdiff commands for unified diff view
Compares current buffer against any git revision (default HEAD), opens result with full diffs.nvim syntax highlighting. Follows fugitive convention: :Gdiff/:Gvdiff open vertical split, :Ghdiff opens horizontal split.
This commit is contained in:
parent
2ce76e7683
commit
045a9044b5
10 changed files with 404 additions and 7 deletions
54
spec/git_spec.lua
Normal file
54
spec/git_spec.lua
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
require('spec.helpers')
|
||||
local git = require('diffs.git')
|
||||
|
||||
describe('git', function()
|
||||
describe('get_repo_root', function()
|
||||
it('returns repo root for current repo', function()
|
||||
local cwd = vim.fn.getcwd()
|
||||
local root = git.get_repo_root(cwd .. '/lua/diffs/init.lua')
|
||||
assert.is_not_nil(root)
|
||||
assert.are.equal(cwd, root)
|
||||
end)
|
||||
|
||||
it('returns nil for non-git directory', function()
|
||||
local root = git.get_repo_root('/tmp')
|
||||
assert.is_nil(root)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('get_file_content', function()
|
||||
it('returns file content at HEAD', function()
|
||||
local cwd = vim.fn.getcwd()
|
||||
local content, err = git.get_file_content('HEAD', cwd .. '/lua/diffs/init.lua')
|
||||
assert.is_nil(err)
|
||||
assert.is_not_nil(content)
|
||||
assert.is_true(#content > 0)
|
||||
end)
|
||||
|
||||
it('returns error for non-existent file', function()
|
||||
local cwd = vim.fn.getcwd()
|
||||
local content, err = git.get_file_content('HEAD', cwd .. '/does_not_exist.lua')
|
||||
assert.is_nil(content)
|
||||
assert.is_not_nil(err)
|
||||
end)
|
||||
|
||||
it('returns error for non-git directory', function()
|
||||
local content, err = git.get_file_content('HEAD', '/tmp/some_file.txt')
|
||||
assert.is_nil(content)
|
||||
assert.is_not_nil(err)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('get_relative_path', function()
|
||||
it('returns relative path within repo', function()
|
||||
local cwd = vim.fn.getcwd()
|
||||
local rel = git.get_relative_path(cwd .. '/lua/diffs/init.lua')
|
||||
assert.are.equal('lua/diffs/init.lua', rel)
|
||||
end)
|
||||
|
||||
it('returns nil for non-git directory', function()
|
||||
local rel = git.get_relative_path('/tmp/some_file.txt')
|
||||
assert.is_nil(rel)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
Loading…
Add table
Add a link
Reference in a new issue