Skip to content

Commit 63f95f2

Browse files
committed
Fix when trying to use "diff this" from status buffer. Stash was being
passed as a SHA instead of stash{n} format, leading to a nil concat error. Simplify by just merging the stash case with the commit case, since both the stash format and sha format are valid.
1 parent dbbbfe6 commit 63f95f2

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

lua/neogit/buffers/stash_list_view/init.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function M:open()
9797
[popups.mapping_for("DiffPopup")] = popups.open("diff", function(p)
9898
local items = self.buffer.ui:get_commits_in_selection()
9999
p {
100-
section = { name = "log" },
100+
section = { name = "stashes" },
101101
item = { name = items },
102102
}
103103
end),
@@ -166,7 +166,7 @@ function M:open()
166166
[popups.mapping_for("DiffPopup")] = popups.open("diff", function(p)
167167
local item = self.buffer.ui:get_commit_under_cursor()
168168
p {
169-
section = { name = "log" },
169+
section = { name = "stashes" },
170170
item = { name = item },
171171
}
172172
end),

lua/neogit/integrations/diffview.lua

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -112,29 +112,20 @@ function M.open(section_name, item_name, opts)
112112
local view
113113
-- selene: allow(if_same_then_else)
114114
if
115-
section_name == "recent"
116-
or section_name == "log"
117-
or (section_name and section_name:match("unmerged$"))
115+
(section_name == "recent" or section_name == "log" or (section_name and section_name:match("unmerged$")))
116+
and item_name
118117
then
119118
local range
120119
if type(item_name) == "table" then
121120
range = string.format("%s..%s", item_name[1], item_name[#item_name])
122-
elseif item_name ~= nil then
123-
range = string.format("%s^!", item_name:match("[a-f0-9]+"))
124121
else
125-
return
122+
range = string.format("%s^!", item_name:match("[a-f0-9]+"))
126123
end
127124

128125
view = dv_lib.diffview_open(dv_utils.tbl_pack(range))
129-
elseif section_name == "range" then
130-
local range = item_name
131-
view = dv_lib.diffview_open(dv_utils.tbl_pack(range))
132-
elseif section_name == "stashes" then
133-
assert(item_name and type(item_name) == "string", "No item name for stash!")
134-
135-
local stash_id = item_name:match("stash@{%d+}")
136-
view = dv_lib.diffview_open(dv_utils.tbl_pack(stash_id .. "^!"))
137-
elseif section_name == "commit" then
126+
elseif section_name == "range" and item_name then
127+
view = dv_lib.diffview_open(dv_utils.tbl_pack(item_name))
128+
elseif (section_name == "stashes" or section_name == "commit") and item_name then
138129
view = dv_lib.diffview_open(dv_utils.tbl_pack(item_name .. "^!"))
139130
elseif section_name == "conflict" and item_name then
140131
view = dv_lib.diffview_open(dv_utils.tbl_pack("--selected-file=" .. item_name))

0 commit comments

Comments
 (0)