fix(file): show files added since the diffed revision as empty instead of erroring (#130)

Co-authored-by: Roman Konoval <roman@jiko.io>
This commit is contained in:
Roman Konoval
2026-06-23 09:52:02 +02:00
committed by GitHub
co-authored by Roman Konoval
parent cffc74128a
commit ca6d751de6
5 changed files with 79 additions and 13 deletions
+4 -2
View File
@@ -172,8 +172,10 @@ diff.register_backend("codediff", {
-- side is decoded in the same way as the current file.
-- Assumes the encoding didn't change between revisions.
local enc = file.get_buf_encoding(0)
local base_lines, base_had_eol, ok_read = file.get_file_content(revset, path, enc)
if not ok_read then
-- A file added since `revset` has no content there; show it as empty
-- so it diffs as fully added rather than aborting the diff.
local base_lines, base_had_eol, ok_read, _, absent = file.get_file_content(revset, path, enc)
if not ok_read and not absent then
utils.notify(string.format("Could not read `%s` from `%s` for CodeDiff", path, revset), vim.log.levels.ERROR)
return
end
+4 -2
View File
@@ -28,8 +28,10 @@ local function open_revision(rev, path, enc)
return
end
local lines, had_eol, ok_read, used_enc = file.get_file_content(change_id, rel_path, enc)
if not ok_read then
-- A file added since `rev` has no content there; show it as empty so it
-- diffs as fully added rather than aborting the diff.
local lines, had_eol, ok_read, used_enc, absent = file.get_file_content(change_id, rel_path, enc)
if not ok_read and not absent then
utils.notify(string.format("Could not read `%s` from `%s`", rel_path, change_id), vim.log.levels.ERROR)
return
end