From 3f6f15cab9f077f68b6bef85f5dc839478ce9fc9 Mon Sep 17 00:00:00 2001 From: przepompownia Date: Mon, 4 Aug 2025 18:05:26 +0200 Subject: [PATCH 1/5] fix(#3171): use vim.system() to determine git toplevel --- lua/nvim-tree/git/utils.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lua/nvim-tree/git/utils.lua b/lua/nvim-tree/git/utils.lua index b805ebfe4cd..d97a9922a15 100644 --- a/lua/nvim-tree/git/utils.lua +++ b/lua/nvim-tree/git/utils.lua @@ -16,12 +16,13 @@ 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 obj = vim.system(cmd):wait() + local out = vim.trim(obj.stdout) 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 obj.code ~= 0 or not out or #out == 0 or out:match("fatal") then return nil, nil end From 7fe20240bffaf55fd4d61a4c23c0cd0aa88b3c54 Mon Sep 17 00:00:00 2001 From: przepompownia Date: Tue, 5 Aug 2025 01:35:15 +0200 Subject: [PATCH 2/5] Don't use vim.trim --- lua/nvim-tree/git/utils.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/nvim-tree/git/utils.lua b/lua/nvim-tree/git/utils.lua index d97a9922a15..b1947cdff59 100644 --- a/lua/nvim-tree/git/utils.lua +++ b/lua/nvim-tree/git/utils.lua @@ -17,7 +17,7 @@ function M.get_toplevel(cwd) log.line("git", "%s", table.concat(cmd, " ")) local obj = vim.system(cmd):wait() - local out = vim.trim(obj.stdout) + local out = obj.stdout log.raw("git", out) log.profile_end(profile) From f76e49238f7389fe084381cf0d09d231ecfd909f Mon Sep 17 00:00:00 2001 From: przepompownia Date: Tue, 5 Aug 2025 01:41:35 +0200 Subject: [PATCH 3/5] Ensure sdtout is a string --- lua/nvim-tree/git/utils.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/nvim-tree/git/utils.lua b/lua/nvim-tree/git/utils.lua index b1947cdff59..7f8ef0a331f 100644 --- a/lua/nvim-tree/git/utils.lua +++ b/lua/nvim-tree/git/utils.lua @@ -17,7 +17,7 @@ function M.get_toplevel(cwd) log.line("git", "%s", table.concat(cmd, " ")) local obj = vim.system(cmd):wait() - local out = obj.stdout + local out = obj.stdout or "" log.raw("git", out) log.profile_end(profile) From 5f7b11fe01cb0b60da7298ac89951500bb555dce Mon Sep 17 00:00:00 2001 From: przepompownia Date: Tue, 5 Aug 2025 01:54:02 +0200 Subject: [PATCH 4/5] Keep Nvim 0.9 compatibility --- lua/nvim-tree/git/utils.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lua/nvim-tree/git/utils.lua b/lua/nvim-tree/git/utils.lua index 7f8ef0a331f..971e727e585 100644 --- a/lua/nvim-tree/git/utils.lua +++ b/lua/nvim-tree/git/utils.lua @@ -16,13 +16,18 @@ 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 obj = vim.system(cmd):wait() - local out = obj.stdout or "" + local out, exitCode + if vim.fn.has("nvim-0.10") == 1 then + local obj = vim.system(cmd):wait() + out, exitCode = obj.stdout or "", obj.code + else + out, exitCode = vim.fn.system(cmd), vim.v.shell_error + end log.raw("git", out) log.profile_end(profile) - if obj.code ~= 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 From 73a8c027b12796d386b176e1fe1a2e22bcf0fd44 Mon Sep 17 00:00:00 2001 From: przepompownia Date: Tue, 5 Aug 2025 02:43:26 +0200 Subject: [PATCH 5/5] Use vim.system to query git config for status.showUntrackedFiles too --- lua/nvim-tree/git/utils.lua | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lua/nvim-tree/git/utils.lua b/lua/nvim-tree/git/utils.lua index 971e727e585..1e3444c70f4 100644 --- a/lua/nvim-tree/git/utils.lua +++ b/lua/nvim-tree/git/utils.lua @@ -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,13 +29,7 @@ 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, exitCode - if vim.fn.has("nvim-0.10") == 1 then - local obj = vim.system(cmd):wait() - out, exitCode = obj.stdout or "", obj.code - else - out, exitCode = vim.fn.system(cmd), vim.v.shell_error - end + local out, exitCode = system(cmd) log.raw("git", out) log.profile_end(profile) @@ -79,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)