fix(fs): make vim.fs.root work for relative paths and unnamed buffers (#28964)

If a buffer does not have a backing file then fall back to the current
working directory.
This commit is contained in:
Gregory Anders
2024-05-24 10:48:32 -05:00
committed by GitHub
parent e71713ba2b
commit 206f8f24a2
3 changed files with 39 additions and 9 deletions

View File

@@ -310,6 +310,25 @@ describe('vim.fs', function()
it('works with a filename argument', function()
eq(test_source_path, exec_lua([[return vim.fs.root(..., '.git')]], nvim_prog))
end)
it('works with a relative path', function()
eq(
test_source_path,
exec_lua([[return vim.fs.root(..., '.git')]], vim.fs.basename(nvim_prog))
)
end)
it('uses cwd for unnamed buffers', function()
command('new')
eq(test_source_path, exec_lua([[return vim.fs.root(0, '.git')]]))
end)
it("uses cwd for buffers with non-empty 'buftype'", function()
command('new')
command('set buftype=nofile')
command('file lua://')
eq(test_source_path, exec_lua([[return vim.fs.root(0, '.git')]]))
end)
end)
describe('joinpath()', function()