Skip to content

Commit 5fefc7b

Browse files
phanenlewis6991
authored andcommitted
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 5fefc7b

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

lua/gitsigns/cache.lua

Lines changed: 8 additions & 5 deletions
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)

test/actions_spec.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,18 @@ describe('actions', function()
118118
signs = { changed = 1 },
119119
})
120120

121+
command('Gitsigns stage_hunk')
122+
check({
123+
status = { head = 'main', added = 0, changed = 0, removed = 0 },
124+
signs = {},
125+
})
126+
127+
command('Gitsigns stage_hunk')
128+
check({
129+
status = { head = 'main', added = 0, changed = 1, removed = 0 },
130+
signs = { changed = 1 },
131+
})
132+
121133
-- Add multiple edits
122134
feed('ggccThat<esc>')
123135

0 commit comments

Comments
 (0)