Skip to content

Commit bc61ff4

Browse files
committed
fix: stage_hunk on staged hunk should behave like undo_stage_hunk
seems a regression of: https://github.com/lewis6991/gitsigns.nvim/blob/b95d08a0607328d7d973cfcdaf4133a1a5fb3f2e/lua/gitsigns/actions.lua#L157-L157
1 parent 011dc67 commit bc61ff4

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lua/gitsigns/cache.lua

+8-5
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,15 @@ function CacheEntry:get_hunks(greedy, staged)
224224
return vim.deepcopy(self.hunks)
225225
end
226226

227+
--- @param hunks? Gitsigns.Hunk.Hunk[]?
227228
--- @return Gitsigns.Hunk.Hunk? hunk
228229
--- @return integer? index
229-
function CacheEntry:get_cursor_hunk()
230-
local hunks = {}
231-
vim.list_extend(hunks, self.hunks or {})
232-
vim.list_extend(hunks, self.hunks_staged or {})
230+
function CacheEntry:get_cursor_hunk(hunks)
231+
if not hunks then
232+
hunks = {}
233+
vim.list_extend(hunks, self.hunks or {})
234+
vim.list_extend(hunks, self.hunks_staged or {})
235+
end
233236

234237
local lnum = api.nvim_win_get_cursor(0)[1]
235238
local Hunks = require('gitsigns.hunks')
@@ -247,7 +250,7 @@ function CacheEntry:get_hunk(range, greedy, staged)
247250
local hunks = self:get_hunks(greedy, staged)
248251

249252
if not range then
250-
return self:get_cursor_hunk()
253+
return self:get_cursor_hunk(hunks)
251254
end
252255

253256
table.sort(range)

0 commit comments

Comments
 (0)