Skip to content

Commit

Permalink
feat: nicer errors for failed stages
Browse files Browse the repository at this point in the history
  • Loading branch information
lewis6991 committed Nov 13, 2024
1 parent e8ba331 commit 9521fe8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
19 changes: 16 additions & 3 deletions lua/gitsigns/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local async = require('gitsigns.async')
local git = require('gitsigns.git')
local Hunks = require('gitsigns.hunks')
local manager = require('gitsigns.manager')
local message = require('gitsigns.message')
local popup = require('gitsigns.popup')
local util = require('gitsigns.util')
local run_diff = require('gitsigns.diff')
Expand Down Expand Up @@ -298,7 +299,11 @@ M.stage_hunk = mk_repeatable(async.create(2, function(range, opts)
return
end

bcache.git_obj:stage_hunks({ hunk }, invert)
local err = bcache.git_obj:stage_hunks({ hunk }, invert)
if err then
message.error(err)
return
end
table.insert(bcache.staged_diffs, hunk)

bcache:invalidate(true)
Expand Down Expand Up @@ -412,7 +417,11 @@ M.undo_stage_hunk = async.create(function()
return
end

bcache.git_obj:stage_hunks({ hunk }, true)
local err = bcache.git_obj:stage_hunks({ hunk }, true)
if err then
message.error(err)
return
end
bcache:invalidate(true)
update(bufnr)
end)
Expand Down Expand Up @@ -445,7 +454,11 @@ M.stage_buffer = async.create(function()
return
end

bcache.git_obj:stage_hunks(hunks)
local err = bcache.git_obj:stage_hunks(hunks)
if err then
message.error(err)
return
end

for _, hunk in ipairs(hunks) do
table.insert(bcache.staged_diffs, hunk)
Expand Down
3 changes: 2 additions & 1 deletion lua/gitsigns/git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ end)
--- @async
--- @param hunks Gitsigns.Hunk.Hunk[]
--- @param invert? boolean
--- @return string? err
function Obj:stage_hunks(hunks, invert)
self.lock = true
self:ensure_file_in_index()
Expand Down Expand Up @@ -357,7 +358,7 @@ function Obj:stage_hunks(hunks, invert)

if not stat then
self.lock = nil
error(err)
return err
end

-- Staging operations cause IO of the git directory so wait some time
Expand Down

0 comments on commit 9521fe8

Please sign in to comment.