diff --git a/lua/git-dashboard-nvim/git.lua b/lua/git-dashboard-nvim/git.lua index f4ed781..2b408e4 100644 --- a/lua/git-dashboard-nvim/git.lua +++ b/lua/git-dashboard-nvim/git.lua @@ -8,18 +8,15 @@ Git = {} ---@return boolean Git.is_git_repo = function() - local handle = io.popen("git status &>" .. null .. "; echo $?") + local handle = io.popen("git rev-parse --is-inside-work-tree 2>" .. null) if not handle then return false end - local exit_code = handle:read("*a") + local result = vim.trim(handle:read("*a")) handle:close() - -- git status command returns - -- 0 exit code if it is a git repository, - -- 128 exit code otherwise - return tonumber(exit_code) == 0 + return result == "true" end ---@return string diff --git a/tests/unit/git_spec.lua b/tests/unit/git_spec.lua index 65935ae..6f5e445 100644 --- a/tests/unit/git_spec.lua +++ b/tests/unit/git_spec.lua @@ -105,7 +105,7 @@ describe("git", function() assert(commits ~= nil) end) - it("should return git status exit code 0", function() + it("should return true if in a git repo", function() local git = require("git-dashboard-nvim.git") local is_git_repo = git.is_git_repo()