Skip to content

Commit

Permalink
feat: detect repo errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lewis6991 committed Aug 28, 2024
1 parent 80214a8 commit 899e993
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lua/gitsigns/git/cmd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down Expand Up @@ -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
12 changes: 6 additions & 6 deletions lua/gitsigns/git/repo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/[email protected]/
Expand All @@ -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])
Expand Down

0 comments on commit 899e993

Please sign in to comment.