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

If a buffer does not have a backing file then fall back to the current
working directory.

(cherry picked from commit 206f8f24a2)
This commit is contained in:
github-actions[bot]
2024-05-24 10:57:21 -05:00
committed by GitHub
parent 28f03205be
commit bf16fe3f01
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()