From 9521fe8be39255b9abc6ec54e352bf04c410f5cf Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 13 Nov 2024 13:57:08 +0000 Subject: [PATCH] feat: nicer errors for failed stages --- lua/gitsigns/actions.lua | 19 ++++++++++++++++--- lua/gitsigns/git.lua | 3 ++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lua/gitsigns/actions.lua b/lua/gitsigns/actions.lua index d2e90c428..cb6d04994 100644 --- a/lua/gitsigns/actions.lua +++ b/lua/gitsigns/actions.lua @@ -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') @@ -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) @@ -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) @@ -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) diff --git a/lua/gitsigns/git.lua b/lua/gitsigns/git.lua index bec3d3559..b8a041077 100644 --- a/lua/gitsigns/git.lua +++ b/lua/gitsigns/git.lua @@ -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() @@ -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