feat: detect repo errors

This commit is contained in:
Lewis Russell 2024-08-28 10:09:30 +01:00
parent 80214a857c
commit 899e993850
2 changed files with 8 additions and 8 deletions

View file

@ -12,7 +12,7 @@ local asystem = async.wrap(3, system)
--- @async
--- @param args string[]
--- @param spec? Gitsigns.Git.JobSpec
--- @return string[] stdout, string? stderr
--- @return string[] stdout, string? stderr, integer code
local function git_command(args, spec)
spec = spec or {}
@ -66,7 +66,7 @@ local function git_command(args, spec)
obj.stderr = nil
end
return stdout_lines, obj.stderr
return stdout_lines, obj.stderr, obj.code
end
return git_command

View file

@ -100,9 +100,9 @@ end
--- @async
function M:update_abbrev_head()
local info = M.get_info(self.toplevel)
local info, err = M.get_info(self.toplevel)
if not info then
log.eprintf('Could not get info for repo at %s', self.gitdir)
log.eprintf('Could not get info for repo at %s: %s', self.gitdir, err or '')
return
end
self.abbrev_head = info.abbrev_head
@ -212,7 +212,7 @@ end
--- @param cwd string
--- @param gitdir? string
--- @param toplevel? string
--- @return Gitsigns.RepoInfo?
--- @return Gitsigns.RepoInfo? info, string? err
function M.get_info(cwd, gitdir, toplevel)
-- Does git rev-parse have --absolute-git-dir, added in 2.13:
-- https://public-inbox.org/git/20170203024829.8071-16-szeder.dev@gmail.com/
@ -239,13 +239,13 @@ function M.get_info(cwd, gitdir, toplevel)
'HEAD',
})
local stdout = git_command(args, {
local stdout, stderr, code = git_command(args, {
ignore_error = true,
cwd = toplevel or cwd,
})
if not stdout[1] then
return
if code > 0 then
return nil, string.format('got stderr: %s', stderr or '')
end
local toplevel_r = normalize_path(stdout[1])