Skip to content

Commit c917468

Browse files
authored
Merge branch 'master' into 2826-one-window-per-explorer-per-tab
2 parents f7bd731 + 9a05b9e commit c917468

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

lua/nvim-tree/git/utils.lua

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@ local M = {
55
use_cygpath = false,
66
}
77

8+
--- Execute system command
9+
---@param cmd string[]
10+
---@return string stdout
11+
---@return integer exit code
12+
local function system(cmd)
13+
if vim.fn.has("nvim-0.10") == 1 then
14+
local obj = vim.system(cmd):wait()
15+
return obj.stdout or "", obj.code
16+
else
17+
return vim.fn.system(cmd), vim.v.shell_error
18+
end
19+
end
20+
821
--- Retrieve the git toplevel directory
922
---@param cwd string path
1023
---@return string|nil toplevel absolute path
@@ -16,12 +29,12 @@ function M.get_toplevel(cwd)
1629
local cmd = { "git", "-C", cwd, "rev-parse", "--show-toplevel", "--absolute-git-dir" }
1730
log.line("git", "%s", table.concat(cmd, " "))
1831

19-
local out = vim.fn.system(cmd)
32+
local out, exitCode = system(cmd)
2033

2134
log.raw("git", out)
2235
log.profile_end(profile)
2336

24-
if vim.v.shell_error ~= 0 or not out or #out == 0 or out:match("fatal") then
37+
if exitCode ~= 0 or not out or #out == 0 or out:match("fatal") then
2538
return nil, nil
2639
end
2740

@@ -73,7 +86,7 @@ function M.should_show_untracked(cwd)
7386
local cmd = { "git", "-C", cwd, "config", "status.showUntrackedFiles" }
7487
log.line("git", table.concat(cmd, " "))
7588

76-
local has_untracked = vim.fn.system(cmd)
89+
local has_untracked = system(cmd)
7790

7891
log.raw("git", has_untracked)
7992
log.profile_end(profile)

0 commit comments

Comments
 (0)