refactor(git): route every git invocation through util.git
This commit is contained in:
+29
-29
@@ -460,17 +460,19 @@ local function action_stage()
|
||||
if #paths == 0 then
|
||||
return
|
||||
end
|
||||
local cmd = { "git", "add", "--" }
|
||||
vim.list_extend(cmd, paths)
|
||||
vim.system(
|
||||
cmd,
|
||||
{ cwd = s.repo.worktree },
|
||||
vim.schedule_wrap(function(obj)
|
||||
if obj.code ~= 0 then
|
||||
util.error("git add failed: %s", vim.trim(obj.stderr or ""))
|
||||
local args = { "add", "--" }
|
||||
vim.list_extend(args, paths)
|
||||
util.git(args, {
|
||||
cwd = s.repo.worktree,
|
||||
on_exit = function(result)
|
||||
if result.code ~= 0 then
|
||||
util.error(
|
||||
"git add failed: %s",
|
||||
vim.trim(result.stderr or "")
|
||||
)
|
||||
end
|
||||
end)
|
||||
)
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
local function action_unstage()
|
||||
@@ -481,7 +483,7 @@ local function action_unstage()
|
||||
if item.kind ~= "staged" then
|
||||
return
|
||||
end
|
||||
local cmd = { "git", "restore", "--staged", "--" }
|
||||
local args = { "restore", "--staged", "--" }
|
||||
local entries
|
||||
if item.is_header then
|
||||
entries = s.repo.status:by_kind("staged")
|
||||
@@ -494,22 +496,21 @@ local function action_unstage()
|
||||
end
|
||||
for _, e in ipairs(entries) do
|
||||
if e.orig then
|
||||
table.insert(cmd, e.orig)
|
||||
table.insert(args, e.orig)
|
||||
end
|
||||
table.insert(cmd, e.path)
|
||||
table.insert(args, e.path)
|
||||
end
|
||||
vim.system(
|
||||
cmd,
|
||||
{ cwd = s.repo.worktree },
|
||||
vim.schedule_wrap(function(obj)
|
||||
if obj.code ~= 0 then
|
||||
util.git(args, {
|
||||
cwd = s.repo.worktree,
|
||||
on_exit = function(result)
|
||||
if result.code ~= 0 then
|
||||
util.error(
|
||||
"git restore --staged failed: %s",
|
||||
vim.trim(obj.stderr or "")
|
||||
vim.trim(result.stderr or "")
|
||||
)
|
||||
end
|
||||
end)
|
||||
)
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
local function action_discard()
|
||||
@@ -542,18 +543,17 @@ local function action_discard()
|
||||
elseif item.kind == "unstaged" then
|
||||
prompt = string.format("Discard changes to %s?", item.path)
|
||||
action = function()
|
||||
vim.system(
|
||||
{ "git", "checkout", "--", item.path },
|
||||
{ cwd = s.repo.worktree },
|
||||
vim.schedule_wrap(function(obj)
|
||||
if obj.code ~= 0 then
|
||||
util.git({ "checkout", "--", item.path }, {
|
||||
cwd = s.repo.worktree,
|
||||
on_exit = function(result)
|
||||
if result.code ~= 0 then
|
||||
util.error(
|
||||
"git checkout failed: %s",
|
||||
vim.trim(obj.stderr or "")
|
||||
vim.trim(result.stderr or "")
|
||||
)
|
||||
end
|
||||
end)
|
||||
)
|
||||
end,
|
||||
})
|
||||
end
|
||||
else
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user