diff --git a/lua/git/cmd.lua b/lua/git/cmd.lua index 2783ba9..ae710be 100644 --- a/lua/git/cmd.lua +++ b/lua/git/cmd.lua @@ -20,15 +20,17 @@ local cached_cmds ---@param result vim.SystemCompleted local function populate_cached_cmds(result) - cached_cmds = {} - if result.code == 0 then - for line in (result.stdout or ""):gmatch("[^\r\n]+") do - if line ~= "" then - table.insert(cached_cmds, line) - end - end - table.sort(cached_cmds) + if result.code ~= 0 then + log.error("git --list-cmds failed: %s", vim.trim(result.stderr or "")) + return end + cached_cmds = {} + for line in (result.stdout or ""):gmatch("[^\r\n]+") do + if line ~= "" then + table.insert(cached_cmds, line) + end + end + table.sort(cached_cmds) end ---Prime `cached_cmds` asynchronously so the first `:G ` 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.bo[buf].modifiable = 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 diff --git a/lua/git/commit.lua b/lua/git/commit.lua index 4c7882f..f5956f7 100644 --- a/lua/git/commit.lua +++ b/lua/git/commit.lua @@ -25,6 +25,8 @@ function M.commit(opts) ):wait() if result.code == 0 then initial = (result.stdout or ""):gsub("\n+$", "") + else + log.warning("git log -1 failed: %s", vim.trim(result.stderr or "")) end end diff --git a/lua/git/diff.lua b/lua/git/diff.lua index f6a97be..a8170cf 100644 --- a/lua/git/diff.lua +++ b/lua/git/diff.lua @@ -62,8 +62,19 @@ local function read_show(worktree, revspec) { cwd = worktree, text = true } ) :wait() - local content = result.code == 0 and (result.stdout or "") or "" - local lines = vim.split(content, "\n", { plain = true, trimempty = false }) + if result.code ~= 0 then + 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 table.remove(lines) end diff --git a/lua/git/repo.lua b/lua/git/repo.lua index 4d39f55..e844930 100644 --- a/lua/git/repo.lua +++ b/lua/git/repo.lua @@ -1,3 +1,4 @@ +local log = require("log") local util = require("util") local UNMERGED = { @@ -73,6 +74,7 @@ local function resolve(path) f:close() local gitdir = content:match("gitdir:%s*(%S+)") if not gitdir then + log.warning(".git file at %s has no `gitdir:` line", found) return nil end if not gitdir:match("^/") then @@ -148,6 +150,8 @@ local function do_refresh(repo) statuses[vim.fs.joinpath(repo.worktree, path_part)] = format(code) end + else + log.warning("git status failed: %s", vim.trim(obj.stderr or "")) end local dirty = false for buf in pairs(repo.buffers) do diff --git a/lua/git/status_win.lua b/lua/git/status_win.lua index e465347..465e00a 100644 --- a/lua/git/status_win.lua +++ b/lua/git/status_win.lua @@ -145,6 +145,9 @@ local function fetch_status(worktree, callback) Unpushed = {}, Unpulled = {}, } + if obj.code ~= 0 then + log.error("git status failed: %s", vim.trim(obj.stderr or "")) + end if obj.code == 0 then for line in (obj.stdout or ""):gmatch("[^\r\n]+") do if line:sub(1, 2) == "##" then @@ -237,6 +240,12 @@ local function fetch_status(worktree, callback) }) end end + else + log.error( + "git log %s failed: %s", + f.range, + vim.trim(log_obj.stderr or "") + ) end pending = pending - 1 if pending == 0 then @@ -643,7 +652,17 @@ local function action_stage() if entry.section == "Staged" then return 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 local function action_unstage() @@ -660,7 +679,16 @@ local function action_unstage() table.insert(cmd, entry.orig) end 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 local function action_discard() @@ -678,7 +706,10 @@ local function action_discard() if entry.section == "Untracked" then prompt = string.format("Delete untracked file %s?", entry.path) 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()) end elseif entry.section == "Unstaged" then @@ -686,7 +717,17 @@ local function action_discard() action = function() vim.system( { "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 else