* fix(#3171): use vim.system() to determine git toplevel * Don't use vim.trim * Ensure sdtout is a string * Keep Nvim 0.9 compatibility * Use vim.system to query git config for status.showUntrackedFiles too
This commit is contained in:
parent
0a7fcdf3f8
commit
9a05b9e9f9
@ -5,6 +5,19 @@ local M = {
|
||||
use_cygpath = false,
|
||||
}
|
||||
|
||||
--- Execute system command
|
||||
---@param cmd string[]
|
||||
---@return string stdout
|
||||
---@return integer exit code
|
||||
local function system(cmd)
|
||||
if vim.fn.has("nvim-0.10") == 1 then
|
||||
local obj = vim.system(cmd):wait()
|
||||
return obj.stdout or "", obj.code
|
||||
else
|
||||
return vim.fn.system(cmd), vim.v.shell_error
|
||||
end
|
||||
end
|
||||
|
||||
--- Retrieve the git toplevel directory
|
||||
---@param cwd string path
|
||||
---@return string|nil toplevel absolute path
|
||||
@ -16,12 +29,12 @@ function M.get_toplevel(cwd)
|
||||
local cmd = { "git", "-C", cwd, "rev-parse", "--show-toplevel", "--absolute-git-dir" }
|
||||
log.line("git", "%s", table.concat(cmd, " "))
|
||||
|
||||
local out = vim.fn.system(cmd)
|
||||
local out, exitCode = system(cmd)
|
||||
|
||||
log.raw("git", out)
|
||||
log.profile_end(profile)
|
||||
|
||||
if vim.v.shell_error ~= 0 or not out or #out == 0 or out:match("fatal") then
|
||||
if exitCode ~= 0 or not out or #out == 0 or out:match("fatal") then
|
||||
return nil, nil
|
||||
end
|
||||
|
||||
@ -73,7 +86,7 @@ function M.should_show_untracked(cwd)
|
||||
local cmd = { "git", "-C", cwd, "config", "status.showUntrackedFiles" }
|
||||
log.line("git", table.concat(cmd, " "))
|
||||
|
||||
local has_untracked = vim.fn.system(cmd)
|
||||
local has_untracked = system(cmd)
|
||||
|
||||
log.raw("git", has_untracked)
|
||||
log.profile_end(profile)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user