refine: replace vim.fn.system with vim.system (#2863)
This commit is contained in:
@@ -129,21 +129,17 @@ end
|
||||
---@return boolean
|
||||
function M.is_ignored(abs_path)
|
||||
local project_root = Utils.get_project_root()
|
||||
local cmd =
|
||||
string.format("git -C %s check-ignore %s", vim.fn.shellescape(project_root), vim.fn.shellescape(abs_path))
|
||||
local exit_code = vim
|
||||
.system({ "git", "-C", vim.fn.shellescape(project_root), "check-ignore", vim.fn.shellescape(abs_path) }, { text = true })
|
||||
:wait().code
|
||||
|
||||
local result = vim.fn.system(cmd)
|
||||
local exit_code = vim.v.shell_error
|
||||
|
||||
-- If command failed or git is not available, fall back to old method
|
||||
-- If command failed or git is not available or not a git repository, fall back to old method
|
||||
if exit_code ~= 0 and exit_code ~= 1 then return old_is_ignored(abs_path) end
|
||||
|
||||
-- Check if result indicates this is not a git repository
|
||||
if result:sub(1, 26) == "fatal: not a git repository" then return old_is_ignored(abs_path) end
|
||||
|
||||
-- git check-ignore returns:
|
||||
-- - exit code 0 and outputs the path if the file is ignored
|
||||
-- - exit code 1 and no output if the file is not ignored
|
||||
-- - exit code 0 and outputs the path to stdout if the file is ignored
|
||||
-- - exit code 1 and no output to stdout if the file is not ignored
|
||||
-- - exit code 128 and outputs the error info to stderr not stdout
|
||||
return exit_code == 0
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user