Skip to content

Commit 1897fb3

Browse files
authored
fix: guard convert_layout against nil revs (sindrets#612) (#19)
Null file entries created by FileEntry.new_null_entry() have no revs field, causing cycle_layout to crash in FileHistoryView.
1 parent 3eed8d8 commit 1897fb3

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

lua/diffview/scene/file_entry.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ end
118118

119119
---@param target_layout Layout
120120
function FileEntry:convert_layout(target_layout)
121+
if not self.revs then return end
122+
121123
local get_data
122124

123125
for _, file in ipairs(self.layout:files()) do

lua/diffview/tests/functional/file_entry_spec.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
local FileEntry = require("diffview.scene.file_entry").FileEntry
2+
local Diff2Hor = require("diffview.scene.layouts.diff_2_hor").Diff2Hor
23
local RevType = require("diffview.vcs.rev").RevType
34
local GitRev = require("diffview.vcs.adapters.git.rev").GitRev
45

56
describe("diffview.file_entry", function()
7+
it("convert_layout skips null entries without error (#612)", function()
8+
local adapter = { ctx = { toplevel = vim.uv.cwd() } }
9+
local entry = FileEntry.new_null_entry(adapter)
10+
local original_layout = entry.layout
11+
12+
-- Must not error; null entries have no revs.
13+
assert.has_no.errors(function()
14+
entry:convert_layout(Diff2Hor)
15+
end)
16+
17+
assert.are.equal(original_layout, entry.layout)
18+
end)
19+
620
it("does not treat should_null errors as truthy null markers", function()
721
local captured
822
local layout_class = setmetatable({

0 commit comments

Comments
 (0)