chore(git): consistent error reporting on git failures
This commit is contained in:
+11
-2
@@ -20,15 +20,17 @@ local cached_cmds
|
|||||||
|
|
||||||
---@param result vim.SystemCompleted
|
---@param result vim.SystemCompleted
|
||||||
local function populate_cached_cmds(result)
|
local function populate_cached_cmds(result)
|
||||||
|
if result.code ~= 0 then
|
||||||
|
log.error("git --list-cmds failed: %s", vim.trim(result.stderr or ""))
|
||||||
|
return
|
||||||
|
end
|
||||||
cached_cmds = {}
|
cached_cmds = {}
|
||||||
if result.code == 0 then
|
|
||||||
for line in (result.stdout or ""):gmatch("[^\r\n]+") do
|
for line in (result.stdout or ""):gmatch("[^\r\n]+") do
|
||||||
if line ~= "" then
|
if line ~= "" then
|
||||||
table.insert(cached_cmds, line)
|
table.insert(cached_cmds, line)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
table.sort(cached_cmds)
|
table.sort(cached_cmds)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---Prime `cached_cmds` asynchronously so the first `:G <Tab>` doesn't block.
|
---Prime `cached_cmds` asynchronously so the first `:G <Tab>` doesn't block.
|
||||||
@@ -111,6 +113,13 @@ local function run_in_split(worktree, args, conf)
|
|||||||
vim.api.nvim_buf_set_lines(buf, 0, -1, false, split_lines(content))
|
vim.api.nvim_buf_set_lines(buf, 0, -1, false, split_lines(content))
|
||||||
vim.bo[buf].modifiable = false
|
vim.bo[buf].modifiable = false
|
||||||
vim.bo[buf].modified = false
|
vim.bo[buf].modified = false
|
||||||
|
if obj.code ~= 0 then
|
||||||
|
log.error(
|
||||||
|
"git %s failed: %s",
|
||||||
|
args[1] or "",
|
||||||
|
vim.trim(obj.stderr or "")
|
||||||
|
)
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ function M.commit(opts)
|
|||||||
):wait()
|
):wait()
|
||||||
if result.code == 0 then
|
if result.code == 0 then
|
||||||
initial = (result.stdout or ""):gsub("\n+$", "")
|
initial = (result.stdout or ""):gsub("\n+$", "")
|
||||||
|
else
|
||||||
|
log.warning("git log -1 failed: %s", vim.trim(result.stderr or ""))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+13
-2
@@ -62,8 +62,19 @@ local function read_show(worktree, revspec)
|
|||||||
{ cwd = worktree, text = true }
|
{ cwd = worktree, text = true }
|
||||||
)
|
)
|
||||||
:wait()
|
:wait()
|
||||||
local content = result.code == 0 and (result.stdout or "") or ""
|
if result.code ~= 0 then
|
||||||
local lines = vim.split(content, "\n", { plain = true, trimempty = false })
|
log.error(
|
||||||
|
"git show %s failed: %s",
|
||||||
|
revspec,
|
||||||
|
vim.trim(result.stderr or "")
|
||||||
|
)
|
||||||
|
return {}
|
||||||
|
end
|
||||||
|
local lines = vim.split(
|
||||||
|
result.stdout or "",
|
||||||
|
"\n",
|
||||||
|
{ plain = true, trimempty = false }
|
||||||
|
)
|
||||||
if #lines > 0 and lines[#lines] == "" then
|
if #lines > 0 and lines[#lines] == "" then
|
||||||
table.remove(lines)
|
table.remove(lines)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
local log = require("log")
|
||||||
local util = require("util")
|
local util = require("util")
|
||||||
|
|
||||||
local UNMERGED = {
|
local UNMERGED = {
|
||||||
@@ -73,6 +74,7 @@ local function resolve(path)
|
|||||||
f:close()
|
f:close()
|
||||||
local gitdir = content:match("gitdir:%s*(%S+)")
|
local gitdir = content:match("gitdir:%s*(%S+)")
|
||||||
if not gitdir then
|
if not gitdir then
|
||||||
|
log.warning(".git file at %s has no `gitdir:` line", found)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
if not gitdir:match("^/") then
|
if not gitdir:match("^/") then
|
||||||
@@ -148,6 +150,8 @@ local function do_refresh(repo)
|
|||||||
statuses[vim.fs.joinpath(repo.worktree, path_part)] =
|
statuses[vim.fs.joinpath(repo.worktree, path_part)] =
|
||||||
format(code)
|
format(code)
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
log.warning("git status failed: %s", vim.trim(obj.stderr or ""))
|
||||||
end
|
end
|
||||||
local dirty = false
|
local dirty = false
|
||||||
for buf in pairs(repo.buffers) do
|
for buf in pairs(repo.buffers) do
|
||||||
|
|||||||
+45
-4
@@ -145,6 +145,9 @@ local function fetch_status(worktree, callback)
|
|||||||
Unpushed = {},
|
Unpushed = {},
|
||||||
Unpulled = {},
|
Unpulled = {},
|
||||||
}
|
}
|
||||||
|
if obj.code ~= 0 then
|
||||||
|
log.error("git status failed: %s", vim.trim(obj.stderr or ""))
|
||||||
|
end
|
||||||
if obj.code == 0 then
|
if obj.code == 0 then
|
||||||
for line in (obj.stdout or ""):gmatch("[^\r\n]+") do
|
for line in (obj.stdout or ""):gmatch("[^\r\n]+") do
|
||||||
if line:sub(1, 2) == "##" then
|
if line:sub(1, 2) == "##" then
|
||||||
@@ -237,6 +240,12 @@ local function fetch_status(worktree, callback)
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
log.error(
|
||||||
|
"git log %s failed: %s",
|
||||||
|
f.range,
|
||||||
|
vim.trim(log_obj.stderr or "")
|
||||||
|
)
|
||||||
end
|
end
|
||||||
pending = pending - 1
|
pending = pending - 1
|
||||||
if pending == 0 then
|
if pending == 0 then
|
||||||
@@ -643,7 +652,17 @@ local function action_stage()
|
|||||||
if entry.section == "Staged" then
|
if entry.section == "Staged" then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
vim.system({ "git", "add", "--", entry.path }, { cwd = s.worktree })
|
vim.system(
|
||||||
|
{ "git", "add", "--", entry.path },
|
||||||
|
{ cwd = s.worktree },
|
||||||
|
function(obj)
|
||||||
|
if obj.code ~= 0 then
|
||||||
|
vim.schedule(function()
|
||||||
|
log.error("git add failed: %s", vim.trim(obj.stderr or ""))
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function action_unstage()
|
local function action_unstage()
|
||||||
@@ -660,7 +679,16 @@ local function action_unstage()
|
|||||||
table.insert(cmd, entry.orig)
|
table.insert(cmd, entry.orig)
|
||||||
end
|
end
|
||||||
table.insert(cmd, entry.path)
|
table.insert(cmd, entry.path)
|
||||||
vim.system(cmd, { cwd = s.worktree })
|
vim.system(cmd, { cwd = s.worktree }, function(obj)
|
||||||
|
if obj.code ~= 0 then
|
||||||
|
vim.schedule(function()
|
||||||
|
log.error(
|
||||||
|
"git restore --staged failed: %s",
|
||||||
|
vim.trim(obj.stderr or "")
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function action_discard()
|
local function action_discard()
|
||||||
@@ -678,7 +706,10 @@ local function action_discard()
|
|||||||
if entry.section == "Untracked" then
|
if entry.section == "Untracked" then
|
||||||
prompt = string.format("Delete untracked file %s?", entry.path)
|
prompt = string.format("Delete untracked file %s?", entry.path)
|
||||||
action = function()
|
action = function()
|
||||||
os.remove(vim.fs.joinpath(s.worktree, entry.path))
|
local ok, err = os.remove(vim.fs.joinpath(s.worktree, entry.path))
|
||||||
|
if not ok then
|
||||||
|
log.error("failed to remove %s: %s", entry.path, err or "")
|
||||||
|
end
|
||||||
refresh(vim.api.nvim_get_current_buf())
|
refresh(vim.api.nvim_get_current_buf())
|
||||||
end
|
end
|
||||||
elseif entry.section == "Unstaged" then
|
elseif entry.section == "Unstaged" then
|
||||||
@@ -686,7 +717,17 @@ local function action_discard()
|
|||||||
action = function()
|
action = function()
|
||||||
vim.system(
|
vim.system(
|
||||||
{ "git", "checkout", "--", entry.path },
|
{ "git", "checkout", "--", entry.path },
|
||||||
{ cwd = s.worktree }
|
{ cwd = s.worktree },
|
||||||
|
function(obj)
|
||||||
|
if obj.code ~= 0 then
|
||||||
|
vim.schedule(function()
|
||||||
|
log.error(
|
||||||
|
"git checkout failed: %s",
|
||||||
|
vim.trim(obj.stderr or "")
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user