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)