fix(init): guard read_file_lines against directory paths (#190)

This commit is contained in:
Barrett Ruth 2026-03-13 07:25:55 -04:00 committed by GitHub
parent 925ba5cb8a
commit a1af48833b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 0 deletions

View file

@ -165,6 +165,39 @@ describe('context', function()
assert.is_nil(hunks[1].context_after)
end)
it('skips when path is a directory', function()
vim.fn.mkdir(vim.fs.joinpath(tmpdir, 'subdir'), 'p')
local hunks = {
make_hunk('subdir', {
file_new_start = 1,
file_new_count = 1,
lines = { '+x' },
}),
}
compute_hunk_context(hunks, 25)
assert.is_nil(hunks[1].context_before)
assert.is_nil(hunks[1].context_after)
end)
it('skips when path is a symlink to a directory', function()
vim.fn.mkdir(vim.fs.joinpath(tmpdir, 'real_dir'), 'p')
vim.uv.fs_symlink(vim.fs.joinpath(tmpdir, 'real_dir'), vim.fs.joinpath(tmpdir, 'link_dir'))
local hunks = {
make_hunk('link_dir', {
file_new_start = 1,
file_new_count = 1,
lines = { '+x' },
}),
}
compute_hunk_context(hunks, 25)
assert.is_nil(hunks[1].context_before)
assert.is_nil(hunks[1].context_after)
end)
it('skips when file does not exist on disk', function()
local hunks = {
make_hunk('nonexistent.lua', {