Skip to content

Commit

Permalink
fix: async consideration for stage with hunk
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgrieser committed Sep 29, 2023
1 parent 1374d4e commit c3be8c3
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lua/tinygit/staging.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ local M = {}
local u = require("tinygit.utils")
--------------------------------------------------------------------------------

---@deprecated
---TODO make PR to gitsigns.nvim instead?
function M.stageHunkWithInfo()
-- stage
local ok, gitsigns = pcall(require, "gitsigns")
Expand All @@ -11,11 +13,14 @@ function M.stageHunkWithInfo()
end
gitsigns.stage_hunk()

-- display total stage info
local info = vim.fn.system { "git", "diff", "--staged", "--stat" }
if vim.v.shell_error ~= 0 then return "" end
local infoNoLastLine = info:gsub("\n.-$", "")
u.notify(infoNoLastLine, "info", "Staged Changes")
-- HACK defer since stage_hunk is async
vim.defer_fn(function()
-- display total stage info
local info = vim.fn.system { "git", "diff", "--staged", "--stat" }
if vim.v.shell_error ~= 0 then return "" end
local infoNoLastLine = info:gsub("\n.-$", "")
u.notify(infoNoLastLine, "info", "Staged Changes")
end, 100)
end

--------------------------------------------------------------------------------
Expand Down

0 comments on commit c3be8c3

Please sign in to comment.