Compares current buffer against any git revision (default HEAD), opens result in vsplit with full diffs.nvim syntax highlighting.
68 lines
2.1 KiB
Lua
68 lines
2.1 KiB
Lua
require('spec.helpers')
|
|
local git = require('diffs.git')
|
|
|
|
describe('git', function()
|
|
describe('get_git_dir', function()
|
|
it('returns git dir for current repo', function()
|
|
local cwd = vim.fn.getcwd()
|
|
local git_dir = git.get_git_dir(cwd .. '/lua/diffs/init.lua')
|
|
assert.is_not_nil(git_dir)
|
|
assert.is_true(vim.fn.isdirectory(git_dir) == 1)
|
|
end)
|
|
|
|
it('returns nil for non-git directory', function()
|
|
local git_dir = git.get_git_dir('/tmp')
|
|
assert.is_nil(git_dir)
|
|
end)
|
|
end)
|
|
|
|
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)
|